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

Commit cf3a425

Browse files
authored
Merge pull request #32 from afrisalyp/issue-232
Handle if dbissue is null.
2 parents 00d92e1 + 94ab9be commit cf3a425

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

services/IssueService.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ async function handleIssueAssignment(event, issue, force = false) {
196196
try {
197197
dbIssue = await ensureChallengeExists(event, issue);
198198

199+
if (!dbIssue) {
200+
const err = errors.internalDependencyError(`Can't find the issue in DB. It's not found or not accessible`);
201+
// The dbissue is not found, the db is not accessible, or the issue is still in creation process.
202+
// Handle it for rescheduling.
203+
await eventService.handleEventGracefully(event, issue, err);
204+
return;
205+
}
206+
199207
// Handle multiple assignees. TC-X allows only one assignee.
200208
if (event.data.issue.assignees && event.data.issue.assignees.length > 1) {
201209
const comment = 'Topcoder-X only supports a single assignee on a ticket to avoid issues with payment';
@@ -304,6 +312,14 @@ async function handleIssueUpdate(event, issue) {
304312
try {
305313
dbIssue = await ensureChallengeExists(event, issue, false);
306314

315+
if (!dbIssue) {
316+
const err = errors.internalDependencyError(`Can't find the issue in DB. It's not found or not accessible`);
317+
// The dbissue is not found, the db is not accessible, or the issue is still in creation process.
318+
// Handle it for rescheduling.
319+
await eventService.handleEventGracefully(event, issue, err);
320+
return;
321+
}
322+
307323
if (dbIssue.title === issue.title &&
308324
dbIssue.body === issue.body &&
309325
dbIssue.prizes.length === issue.prizes.length &&
@@ -347,6 +363,15 @@ async function handleIssueClose(event, issue) {
347363
let dbIssue;
348364
try {
349365
dbIssue = await ensureChallengeExists(event, issue);
366+
367+
if (!dbIssue) {
368+
const err = errors.internalDependencyError(`Can't find the issue in DB. It's not found or not accessible`);
369+
// The dbissue is not found, the db is not accessible, or the issue is still in creation process.
370+
// Handle it for rescheduling.
371+
await eventService.handleEventGracefully(event, issue, err);
372+
return;
373+
}
374+
350375
event.dbIssue = dbIssue;
351376

352377
// if the issue has payment success or payment pending status, we'll ignore this process.
@@ -613,6 +638,12 @@ async function handleIssueLabelUpdated(event, issue) {
613638
await eventService.handleEventGracefully(event, issue, e);
614639
return;
615640
}
641+
// Sometimes Github send label updated event before issue created event.
642+
// This process will be ignored. The label will be processed (stored) at hanleIssueCreated.
643+
if (!dbIssue) {
644+
logger.debug(`DB record not found. Issue label update ignored.`);
645+
return;
646+
}
616647
await dbHelper.update(models.Issue, dbIssue.id, {
617648
labels: issue.labels,
618649
updatedAt: new Date()
@@ -629,6 +660,15 @@ async function handleIssueUnAssignment(event, issue) {
629660
let dbIssue;
630661
try {
631662
dbIssue = await ensureChallengeExists(event, issue);
663+
664+
if (!dbIssue) {
665+
const err = errors.internalDependencyError(`Can't find the issue in DB. It's not found or not accessible`);
666+
// The dbissue is not found, the db is not accessible, or the issue is still in creation process.
667+
// Handle it for rescheduling.
668+
await eventService.handleEventGracefully(event, issue, err);
669+
return;
670+
}
671+
632672
if (dbIssue.assignee) {
633673
const assigneeUserId = gitHelper.getUserIdByLogin(event, dbIssue.assignee);
634674
logger.debug(`Looking up TC handle of git user: ${assigneeUserId}`);

0 commit comments

Comments
 (0)