Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Handle if dbissue is null. #32

Merged
merged 3 commits into from
Nov 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions services/IssueService.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ async function handleIssueAssignment(event, issue, force = false) {
try {
dbIssue = await ensureChallengeExists(event, issue);

if (!dbIssue) {
const err = errors.internalDependencyError(`Can't find the issue in DB. It's not found or not accessible`);
// The dbissue is not found, the db is not accessible, or the issue is still in creation process.
// Handle it for rescheduling.
await eventService.handleEventGracefully(event, issue, err);
return;
}

// Handle multiple assignees. TC-X allows only one assignee.
if (event.data.issue.assignees && event.data.issue.assignees.length > 1) {
const comment = 'Topcoder-X only supports a single assignee on a ticket to avoid issues with payment';
Expand Down Expand Up @@ -304,6 +312,14 @@ async function handleIssueUpdate(event, issue) {
try {
dbIssue = await ensureChallengeExists(event, issue, false);

if (!dbIssue) {
const err = errors.internalDependencyError(`Can't find the issue in DB. It's not found or not accessible`);
// The dbissue is not found, the db is not accessible, or the issue is still in creation process.
// Handle it for rescheduling.
await eventService.handleEventGracefully(event, issue, err);
return;
}

if (dbIssue.title === issue.title &&
dbIssue.body === issue.body &&
dbIssue.prizes.length === issue.prizes.length &&
Expand Down Expand Up @@ -347,6 +363,15 @@ async function handleIssueClose(event, issue) {
let dbIssue;
try {
dbIssue = await ensureChallengeExists(event, issue);

if (!dbIssue) {
const err = errors.internalDependencyError(`Can't find the issue in DB. It's not found or not accessible`);
// The dbissue is not found, the db is not accessible, or the issue is still in creation process.
// Handle it for rescheduling.
await eventService.handleEventGracefully(event, issue, err);
return;
}

event.dbIssue = dbIssue;

// if the issue has payment success or payment pending status, we'll ignore this process.
Expand Down Expand Up @@ -613,6 +638,12 @@ async function handleIssueLabelUpdated(event, issue) {
await eventService.handleEventGracefully(event, issue, e);
return;
}
// Sometimes Github send label updated event before issue created event.
// This process will be ignored. The label will be processed (stored) at hanleIssueCreated.
if (!dbIssue) {
logger.debug(`DB record not found. Issue label update ignored.`);
return;
}
await dbHelper.update(models.Issue, dbIssue.id, {
labels: issue.labels,
updatedAt: new Date()
Expand All @@ -629,6 +660,15 @@ async function handleIssueUnAssignment(event, issue) {
let dbIssue;
try {
dbIssue = await ensureChallengeExists(event, issue);

if (!dbIssue) {
const err = errors.internalDependencyError(`Can't find the issue in DB. It's not found or not accessible`);
// The dbissue is not found, the db is not accessible, or the issue is still in creation process.
// Handle it for rescheduling.
await eventService.handleEventGracefully(event, issue, err);
return;
}

if (dbIssue.assignee) {
const assigneeUserId = gitHelper.getUserIdByLogin(event, dbIssue.assignee);
logger.debug(`Looking up TC handle of git user: ${assigneeUserId}`);
Expand Down