@@ -174,9 +174,10 @@ function parseComment(comment) {
174
174
* handles the issue assignment
175
175
* @param {Object } event the event
176
176
* @param {Object } issue the issue
177
+ * @param {Boolean } force force to assign (if there is no OpenForPickup label)
177
178
* @private
178
179
*/
179
- async function handleIssueAssignment ( event , issue ) {
180
+ async function handleIssueAssignment ( event , issue , force = false ) {
180
181
const assigneeUserId = event . data . assignee . id ;
181
182
logger . debug ( `Looking up TC handle of git user: ${ assigneeUserId } ` ) ;
182
183
const userMapping = await userService . getTCUserName ( event . provider , assigneeUserId ) ;
@@ -201,7 +202,7 @@ async function handleIssueAssignment(event, issue) {
201
202
// ensure issue has open for pickup label
202
203
const hasOpenForPickupLabel = _ ( issue . labels ) . includes ( config . OPEN_FOR_PICKUP_ISSUE_LABEL ) ; // eslint-disable-line lodash/chaining
203
204
const hasNotReadyLabel = _ ( issue . labels ) . includes ( config . NOT_READY_ISSUE_LABEL ) ; // eslint-disable-line lodash/chaining
204
- if ( ! hasOpenForPickupLabel ) {
205
+ if ( ! hasOpenForPickupLabel && ! force ) {
205
206
if ( ! issue . assignee ) {
206
207
const issueLabels = _ ( issue . labels ) . push ( config . NOT_READY_ISSUE_LABEL ) . value ( ) ; // eslint-disable-line lodash/chaining
207
208
const comment = `This ticket isn't quite ready to be worked on yet.Please wait until it has the ${ config . OPEN_FOR_PICKUP_ISSUE_LABEL } label` ;
@@ -464,7 +465,7 @@ async function handleIssueClose(event, issue) {
464
465
labels,
465
466
updatedAt : new Date ( )
466
467
} ) ;
467
- await gitHelper . markIssueAsPaid ( event , issue . number , dbIssue . challengeId ) ;
468
+ await gitHelper . markIssueAsPaid ( event , issue . number , dbIssue . challengeId , labels ) ;
468
469
} catch ( e ) {
469
470
await eventService . handleEventGracefully ( event , issue , e ) ;
470
471
return ;
@@ -500,7 +501,7 @@ async function handleIssueCreate(event, issue) {
500
501
}
501
502
502
503
// create issue with challenge creation pending
503
- const issueObject = _ . assign ( { } , issue , {
504
+ const issueObject = _ . assign ( { } , _ . omit ( issue , 'assignee' ) , {
504
505
id : helper . generateIdentifier ( ) ,
505
506
status : 'challenge_creation_pending'
506
507
} ) ;
@@ -548,14 +549,13 @@ async function handleIssueCreate(event, issue) {
548
549
const contestUrl = getUrlForChallengeId ( issue . challengeId ) ;
549
550
const comment = `Contest ${ contestUrl } has been created for this ticket.` ;
550
551
await gitHelper . createComment ( event , issue . number , comment ) ;
551
- if ( event . provider === 'gitlab' ) {
552
- // if assignee is added during issue create then assign as well
553
- if ( event . data . issue . assignees && event . data . issue . assignees . length > 0 && event . data . issue . assignees [ 0 ] . id ) {
554
- event . data . assignee = {
555
- id : event . data . issue . assignees [ 0 ] . id
556
- } ;
557
- await handleIssueAssignment ( event , issue ) ;
558
- }
552
+
553
+ // if assignee is added during issue create then assign as well
554
+ if ( event . data . issue . assignees && event . data . issue . assignees . length > 0 && event . data . issue . assignees [ 0 ] . id ) {
555
+ event . data . assignee = {
556
+ id : event . data . issue . assignees [ 0 ] . id
557
+ } ;
558
+ await handleIssueAssignment ( event , issue , true ) ;
559
559
}
560
560
561
561
logger . debug ( `new challenge created with id ${ issue . challengeId } for issue ${ issue . number } ` ) ;
@@ -660,6 +660,50 @@ async function handleIssueUnAssignment(event, issue) {
660
660
}
661
661
}
662
662
663
+ /**
664
+ * handles the issue recreate event
665
+ * @param {Object } event the event
666
+ * @param {Object } issue the issue
667
+ * @private
668
+ */
669
+ async function handleIssueRecreate ( event , issue ) {
670
+ const dbIssue = await dbHelper . scanOne ( models . Issue , {
671
+ number : issue . number ,
672
+ provider : issue . provider ,
673
+ repositoryId : issue . repositoryId
674
+ } ) ;
675
+ try {
676
+ const project = await getProjectDetail ( event ) ;
677
+
678
+ logger . debug ( `Getting the billing account ID for project ID: ${ project . tcDirectId } ` ) ;
679
+ const accountId = await topcoderApiHelper . getProjectBillingAccountId ( project . tcDirectId ) ;
680
+
681
+ logger . debug ( `Assigning the billing account id ${ accountId } to challenge` ) ;
682
+
683
+ // adding assignees as well if it is missed/failed during update
684
+ // prize needs to be again set after adding billing account otherwise it won't let activate
685
+ const updateBody = {
686
+ billingAccountId : accountId ,
687
+ prizes : dbIssue . prizes
688
+ } ;
689
+ await topcoderApiHelper . updateChallenge ( dbIssue . challengeId , updateBody ) ;
690
+
691
+ // Activate the challenge
692
+ await topcoderApiHelper . activateChallenge ( dbIssue . challengeId ) ;
693
+
694
+ // Cancel the challenge
695
+ await topcoderApiHelper . cancelPrivateContent ( dbIssue . challengeId ) ;
696
+
697
+ await dbIssue . delete ( ) ;
698
+ } catch ( err ) {
699
+ // Just log the error, keep the process go on.
700
+ logger . error ( `Error cleaning the old DB and its challenge.\n ${ err } ` ) ;
701
+ }
702
+
703
+ await handleIssueCreate ( event , issue ) ;
704
+ // handleIssueLabelUpdated(event, issue);
705
+ }
706
+
663
707
/**
664
708
* Process issue event.
665
709
* @param {Object } event the event
@@ -710,12 +754,14 @@ async function process(event) {
710
754
await handleIssueLabelUpdated ( event , issue ) ;
711
755
} else if ( event . event === 'issue.unassigned' ) {
712
756
await handleIssueUnAssignment ( event , issue ) ;
757
+ } else if ( event . event === 'issue.recreated' ) {
758
+ await handleIssueRecreate ( event , issue ) ;
713
759
}
714
760
}
715
761
716
762
process . schema = Joi . object ( ) . keys ( {
717
763
event : Joi . string ( ) . valid ( 'issue.created' , 'issue.updated' , 'issue.closed' , 'comment.created' , 'comment.updated' , 'issue.assigned' ,
718
- 'issue.labelUpdated' , 'issue.unassigned' ) . required ( ) ,
764
+ 'issue.labelUpdated' , 'issue.unassigned' , 'issue.recreated' ) . required ( ) ,
719
765
provider : Joi . string ( ) . valid ( 'github' , 'gitlab' ) . required ( ) ,
720
766
data : Joi . object ( ) . keys ( {
721
767
issue : Joi . object ( ) . keys ( {
0 commit comments