@@ -499,7 +499,7 @@ async function handleIssueClose(event, issue) { // eslint-disable-line
499
499
} catch ( e ) {
500
500
event . paymentSuccessful = event . paymentSuccessful === true ; // if once paid shouldn't be false
501
501
// update the issue status to payment failed
502
- if ( ! event . paymentSuccessful ) {
502
+ if ( ! event . paymentSuccessful && dbIssue && dbIssue . id ) {
503
503
await dbHelper . update ( models . Issue , dbIssue . id , {
504
504
status : 'challenge_payment_failed' ,
505
505
updatedAt : new Date ( )
@@ -566,24 +566,25 @@ async function handleIssueCreate(event, issue, forceAssign = false) {
566
566
}
567
567
issueCreationLock [ creationLockKey ] = true ;
568
568
569
- // create issue with challenge creation pending
570
- const issueObject = _ . assign ( { } , _ . omit ( issue , 'assignee' ) , {
571
- id : helper . generateIdentifier ( ) ,
572
- status : 'challenge_creation_pending'
573
- } ) ;
574
- dbIssue = await dbHelper . create ( models . Issue , issueObject ) ;
569
+ try {
570
+ // create issue with challenge creation pending
571
+ const issueObject = _ . assign ( { } , _ . omit ( issue , 'assignee' ) , {
572
+ id : helper . generateIdentifier ( ) ,
573
+ status : 'challenge_creation_pending'
574
+ } ) ;
575
+ dbIssue = await dbHelper . create ( models . Issue , issueObject ) ;
575
576
576
- const projectId = project . tcDirectId ;
577
+ const projectId = project . tcDirectId ;
577
578
578
- let fullRepoUrl ;
579
- if ( issue . provider === 'github' ) {
580
- fullRepoUrl = `https://github.com/${ event . data . repository . full_name } ` ;
581
- } else if ( issue . provider === 'gitlab' ) {
582
- fullRepoUrl = `${ config . GITLAB_API_BASE_URL } /${ event . data . repository . full_name } ` ;
583
- }
579
+ let fullRepoUrl ;
580
+ if ( issue . provider === 'github' ) {
581
+ fullRepoUrl = `https://github.com/${ event . data . repository . full_name } ` ;
582
+ } else if ( issue . provider === 'gitlab' ) {
583
+ fullRepoUrl = `${ config . GITLAB_API_BASE_URL } /${ event . data . repository . full_name } ` ;
584
+ }
584
585
585
- logger . debug ( `existing project was found with id ${ projectId } for repository ${ event . data . repository . full_name } ` ) ;
586
- try {
586
+ logger . debug ( `existing project was found with id ${ projectId } for repository ${ event . data . repository . full_name } ` ) ;
587
+
587
588
// Create a new challenge
588
589
issue . challengeId = await topcoderApiHelper . createChallenge ( {
589
590
name : issue . title ,
@@ -603,27 +604,31 @@ async function handleIssueCreate(event, issue, forceAssign = false) {
603
604
} ) ;
604
605
} catch ( e ) {
605
606
logger . error ( `Challenge creation failure: ${ e } ` ) ;
607
+ delete issueCreationLock [ creationLockKey ] ;
606
608
await dbHelper . removeIssue ( models . Issue , issue . repositoryId , issue . number , issue . provider ) ;
607
609
await eventService . handleEventGracefully ( event , issue , e ) ;
608
- delete issueCreationLock [ creationLockKey ] ;
609
610
return ;
610
611
}
612
+ try {
613
+ const contestUrl = getUrlForChallengeId ( issue . challengeId ) ;
614
+ const comment = `Contest ${ contestUrl } has been created for this ticket.` ;
615
+ await gitHelper . createComment ( event , issue . number , comment ) ;
611
616
612
- const contestUrl = getUrlForChallengeId ( issue . challengeId ) ;
613
- const comment = `Contest ${ contestUrl } has been created for this ticket.` ;
614
- await gitHelper . createComment ( event , issue . number , comment ) ;
615
-
616
- if ( event . provider === 'gitlab' || forceAssign ) {
617
- // if assignee is added during issue create then assign as well
618
- if ( event . data . issue . assignees && event . data . issue . assignees . length > 0 && event . data . issue . assignees [ 0 ] . id ) {
619
- event . data . assignee = {
620
- id : event . data . issue . assignees [ 0 ] . id
621
- } ;
622
- await handleIssueAssignment ( event , issue , true ) ;
617
+ if ( event . provider === 'gitlab' || forceAssign ) {
618
+ // if assignee is added during issue create then assign as well
619
+ if ( event . data . issue . assignees && event . data . issue . assignees . length > 0 && event . data . issue . assignees [ 0 ] . id ) {
620
+ event . data . assignee = {
621
+ id : event . data . issue . assignees [ 0 ] . id
622
+ } ;
623
+ await handleIssueAssignment ( event , issue , true ) ;
624
+ }
623
625
}
626
+ delete issueCreationLock [ creationLockKey ] ;
627
+ } catch ( err ) {
628
+ logger . error ( `Comment creation failure: ${ e } ` ) ;
629
+ delete issueCreationLock [ creationLockKey ] ;
630
+ logger . debug ( `new challenge created with id ${ issue . challengeId } for issue ${ issue . number } ` ) ;
624
631
}
625
- delete issueCreationLock [ creationLockKey ] ;
626
- logger . debug ( `new challenge created with id ${ issue . challengeId } for issue ${ issue . number } ` ) ;
627
632
}
628
633
629
634
/**
@@ -780,6 +785,8 @@ async function handleIssueRecreate(event, issue) {
780
785
logger . debug ( `Adding label ${ config . OPEN_FOR_PICKUP_ISSUE_LABEL } ` ) ;
781
786
await gitHelper . addLabels ( event , issue . number , issueLabels ) ;
782
787
788
+ const creationLockKey = `${ issue . provider } -${ issue . repositoryId } -${ issue . number } ` ;
789
+ delete issueCreationLock [ creationLockKey ] ;
783
790
await handleIssueCreate ( event , issue , false ) ;
784
791
785
792
if ( event . data . issue . assignees && event . data . issue . assignees . length > 0 && event . data . issue . assignees [ 0 ] . id ) {
0 commit comments