@@ -196,6 +196,14 @@ async function handleIssueAssignment(event, issue, force = false) {
196
196
try {
197
197
dbIssue = await ensureChallengeExists ( event , issue ) ;
198
198
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
+
199
207
// Handle multiple assignees. TC-X allows only one assignee.
200
208
if ( event . data . issue . assignees && event . data . issue . assignees . length > 1 ) {
201
209
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) {
304
312
try {
305
313
dbIssue = await ensureChallengeExists ( event , issue , false ) ;
306
314
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
+
307
323
if ( dbIssue . title === issue . title &&
308
324
dbIssue . body === issue . body &&
309
325
dbIssue . prizes . length === issue . prizes . length &&
@@ -347,6 +363,15 @@ async function handleIssueClose(event, issue) {
347
363
let dbIssue ;
348
364
try {
349
365
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
+
350
375
event . dbIssue = dbIssue ;
351
376
352
377
// if the issue has payment success or payment pending status, we'll ignore this process.
@@ -613,6 +638,12 @@ async function handleIssueLabelUpdated(event, issue) {
613
638
await eventService . handleEventGracefully ( event , issue , e ) ;
614
639
return ;
615
640
}
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
+ }
616
647
await dbHelper . update ( models . Issue , dbIssue . id , {
617
648
labels : issue . labels ,
618
649
updatedAt : new Date ( )
@@ -629,6 +660,15 @@ async function handleIssueUnAssignment(event, issue) {
629
660
let dbIssue ;
630
661
try {
631
662
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
+
632
672
if ( dbIssue . assignee ) {
633
673
const assigneeUserId = gitHelper . getUserIdByLogin ( event , dbIssue . assignee ) ;
634
674
logger . debug ( `Looking up TC handle of git user: ${ assigneeUserId } ` ) ;
0 commit comments