@@ -108,10 +108,7 @@ async function ensureChallengeExists(event, issue, create = true) {
108
108
*/
109
109
async function getProjectDetail ( event ) {
110
110
const fullRepoUrl = gitHelper . getFullRepoUrl ( event ) ;
111
- const project = await dbHelper . scanOne ( models . Project , {
112
- repoUrl : fullRepoUrl ,
113
- archived : 'false'
114
- } ) ;
111
+ const project = await dbHelper . queryOneActiveProject ( models . Project , fullRepoUrl ) ;
115
112
116
113
return project ;
117
114
}
@@ -202,7 +199,11 @@ async function handleIssueAssignment(event, issue, force = false) {
202
199
}
203
200
return ;
204
201
}
205
-
202
+ // if the issue has payment success we'll ignore this process.
203
+ if ( dbIssue . status === constants . ISSUE_STATUS . CHALLENGE_PAYMENT_SUCCESSFUL ) {
204
+ logger . debugWithContext ( 'Ignoring this issue processing. The issue has challenge_payment_successful.' , event , issue ) ;
205
+ return ;
206
+ }
206
207
// Handle multiple assignees. TC-X allows only one assignee.
207
208
if ( event . data . issue . assignees && event . data . issue . assignees . length > 1 ) {
208
209
const comment = 'Topcoder-X only supports a single assignee on a ticket to avoid issues with payment' ;
@@ -332,7 +333,11 @@ async function handleIssueUpdate(event, issue) {
332
333
}
333
334
return ;
334
335
}
335
-
336
+ // if the issue has payment success we'll ignore this process.
337
+ if ( dbIssue . status === constants . ISSUE_STATUS . CHALLENGE_PAYMENT_SUCCESSFUL ) {
338
+ logger . debugWithContext ( 'Ignoring this issue processing. The issue has challenge_payment_successful.' , event , issue ) ;
339
+ return ;
340
+ }
336
341
if ( dbIssue . title === issue . title &&
337
342
dbIssue . body === issue . body &&
338
343
dbIssue . prizes . length === issue . prizes . length &&
@@ -410,7 +415,7 @@ async function handleIssueClose(event, issue) { // eslint-disable-line
410
415
let comment = 'This ticket was not processed for payment. If you would like to process it for payment,' ;
411
416
comment += ' please reopen it, add the ```' + config . FIX_ACCEPTED_ISSUE_LABEL + '``` label, and then close it again' ; // eslint-disable-line
412
417
await gitHelper . createComment ( event , issue . number , comment ) ;
413
- closeChallenge = true ;
418
+ return ;
414
419
}
415
420
416
421
// if issue is close with cancelled label
@@ -493,8 +498,8 @@ async function handleIssueClose(event, issue) { // eslint-disable-line
493
498
event . createCopilotPayments = createCopilotPayments ;
494
499
495
500
if ( createCopilotPayments ) {
496
- logger . debugWithContext ( ` Setting copilot payment` ) ;
497
-
501
+ logger . debugWithContext ( ' Setting copilot payment' ) ;
502
+
498
503
const updateBody = {
499
504
prizeSets : [ {
500
505
type : 'placement' ,
@@ -504,13 +509,11 @@ async function handleIssueClose(event, issue) { // eslint-disable-line
504
509
type : 'copilot' ,
505
510
prizes : [ { type : 'USD' , value : 40 } ]
506
511
}
507
- ]
512
+ ]
508
513
} ;
509
514
await topcoderApiHelper . updateChallenge ( dbIssue . challengeUUID , updateBody ) ;
510
-
511
- }
512
- else {
513
- logger . debugWithContext ( 'Create copilot payments is unchecked on the Topcoder-X project setup, so skipping' , event , issue ) ;
515
+ } else {
516
+ logger . debugWithContext ( 'Create copilot payments is unchecked on the Topcoder-X project setup, so skipping' , event , issue ) ;
514
517
}
515
518
516
519
logger . debugWithContext ( `Getting the topcoder member ID for member name: ${ assigneeMember . topcoderUsername } ` , event , issue ) ;
@@ -525,15 +528,6 @@ async function handleIssueClose(event, issue) { // eslint-disable-line
525
528
logger . debugWithContext ( 'Assignee is already set, so skipping' , event , issue ) ;
526
529
}
527
530
528
- // activate challenge
529
-
530
- if ( challenge . status === 'Draft' ) {
531
- await topcoderApiHelper . activateChallenge ( dbIssue . challengeUUID ) ;
532
- //HACK - sleep 30 seconds so the legacy processor has time to "catch up"
533
- // logger.debugWithContext('Sleeping for 1 seconds after activation so everything propagates...', event, issue);
534
- // await new Promise(resolve => setTimeout(resolve, 1000));
535
- }
536
-
537
531
logger . debugWithContext ( `Closing challenge with winner ${ assigneeMember . topcoderUsername } (${ winnerId } )` , event , issue ) ;
538
532
await topcoderApiHelper . closeChallenge ( dbIssue . challengeUUID , winnerId , assigneeMember . topcoderUsername ) ;
539
533
event . paymentSuccessful = true ;
@@ -644,11 +638,11 @@ async function handleIssueCreate(event, issue, forceAssign = false) {
644
638
status : constants . ISSUE_STATUS . CHALLENGE_CREATION_SUCCESSFUL ,
645
639
updatedAt : new Date ( )
646
640
} ) ;
647
-
641
+
648
642
logger . debugWithContext ( `Adding copilot to issue: ${ event . copilot . topcoderUsername } ` , event , issue ) ;
649
643
// get copilot tc user id
650
644
await topcoderApiHelper . addResourceToChallenge ( issue . challengeUUID , event . copilot . topcoderUsername , config . ROLE_ID_COPILOT ) ;
651
-
645
+ await topcoderApiHelper . addResourceToChallenge ( issue . challengeUUID , event . copilot . topcoderUsername , config . ROLE_ID_ITERATIVE_REVIEWER ) ;
652
646
} catch ( e ) {
653
647
logger . error ( `Challenge creation failure: ${ e } ` ) ;
654
648
delete issueCreationLock [ creationLockKey ] ;
@@ -698,6 +692,11 @@ async function handleIssueLabelUpdated(event, issue) {
698
692
logger . debugWithContext ( 'DB record not found. Issue label update ignored.' , event , issue ) ;
699
693
return ;
700
694
}
695
+ // if the issue has payment success we'll ignore this process.
696
+ if ( dbIssue . status === constants . ISSUE_STATUS . CHALLENGE_PAYMENT_SUCCESSFUL ) {
697
+ logger . debugWithContext ( 'Ignoring this issue processing. The issue has challenge_payment_successful.' , event , issue ) ;
698
+ return ;
699
+ }
701
700
await dbHelper . update ( models . Issue , dbIssue . id , {
702
701
labels : issue . labels ,
703
702
updatedAt : new Date ( )
@@ -720,6 +719,11 @@ async function handleIssueUnAssignment(event, issue) {
720
719
// Ignore it.
721
720
return ;
722
721
}
722
+ // if the issue has payment success we'll ignore this process.
723
+ if ( dbIssue . status === constants . ISSUE_STATUS . CHALLENGE_PAYMENT_SUCCESSFUL ) {
724
+ logger . debugWithContext ( 'Ignoring this issue processing. The issue has challenge_payment_successful.' , event , issue ) ;
725
+ return ;
726
+ }
723
727
if ( dbIssue . assignee ) {
724
728
const assigneeUserId = await gitHelper . getUserIdByLogin ( event , dbIssue . assignee ) ;
725
729
if ( ! assigneeUserId ) {
@@ -861,10 +865,7 @@ async function process(event) {
861
865
const fullRepoUrl = gitHelper . getFullRepoUrl ( event ) ;
862
866
event . data . repository . repoUrl = fullRepoUrl ;
863
867
864
- const project = await dbHelper . scanOne ( models . Project , {
865
- repoUrl : fullRepoUrl ,
866
- archived : 'false'
867
- } ) ;
868
+ const project = await dbHelper . queryOneActiveProject ( models . Project , fullRepoUrl ) ;
868
869
869
870
issue . projectId = project . id ;
870
871
0 commit comments