@@ -108,10 +108,7 @@ async function ensureChallengeExists(event, issue, create = true) {
108108 */
109109async function getProjectDetail ( event ) {
110110 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 ) ;
115112
116113 return project ;
117114}
@@ -202,7 +199,11 @@ async function handleIssueAssignment(event, issue, force = false) {
202199 }
203200 return ;
204201 }
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+ }
206207 // Handle multiple assignees. TC-X allows only one assignee.
207208 if ( event . data . issue . assignees && event . data . issue . assignees . length > 1 ) {
208209 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) {
332333 }
333334 return ;
334335 }
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+ }
336341 if ( dbIssue . title === issue . title &&
337342 dbIssue . body === issue . body &&
338343 dbIssue . prizes . length === issue . prizes . length &&
@@ -410,7 +415,7 @@ async function handleIssueClose(event, issue) { // eslint-disable-line
410415 let comment = 'This ticket was not processed for payment. If you would like to process it for payment,' ;
411416 comment += ' please reopen it, add the ```' + config . FIX_ACCEPTED_ISSUE_LABEL + '``` label, and then close it again' ; // eslint-disable-line
412417 await gitHelper . createComment ( event , issue . number , comment ) ;
413- closeChallenge = true ;
418+ return ;
414419 }
415420
416421 // if issue is close with cancelled label
@@ -493,8 +498,8 @@ async function handleIssueClose(event, issue) { // eslint-disable-line
493498 event . createCopilotPayments = createCopilotPayments ;
494499
495500 if ( createCopilotPayments ) {
496- logger . debugWithContext ( ` Setting copilot payment` ) ;
497-
501+ logger . debugWithContext ( ' Setting copilot payment' ) ;
502+
498503 const updateBody = {
499504 prizeSets : [ {
500505 type : 'placement' ,
@@ -504,13 +509,11 @@ async function handleIssueClose(event, issue) { // eslint-disable-line
504509 type : 'copilot' ,
505510 prizes : [ { type : 'USD' , value : 40 } ]
506511 }
507- ]
512+ ]
508513 } ;
509514 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 ) ;
514517 }
515518
516519 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
525528 logger . debugWithContext ( 'Assignee is already set, so skipping' , event , issue ) ;
526529 }
527530
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-
537531 logger . debugWithContext ( `Closing challenge with winner ${ assigneeMember . topcoderUsername } (${ winnerId } )` , event , issue ) ;
538532 await topcoderApiHelper . closeChallenge ( dbIssue . challengeUUID , winnerId , assigneeMember . topcoderUsername ) ;
539533 event . paymentSuccessful = true ;
@@ -644,11 +638,11 @@ async function handleIssueCreate(event, issue, forceAssign = false) {
644638 status : constants . ISSUE_STATUS . CHALLENGE_CREATION_SUCCESSFUL ,
645639 updatedAt : new Date ( )
646640 } ) ;
647-
641+
648642 logger . debugWithContext ( `Adding copilot to issue: ${ event . copilot . topcoderUsername } ` , event , issue ) ;
649643 // get copilot tc user id
650644 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 ) ;
652646 } catch ( e ) {
653647 logger . error ( `Challenge creation failure: ${ e } ` ) ;
654648 delete issueCreationLock [ creationLockKey ] ;
@@ -698,6 +692,11 @@ async function handleIssueLabelUpdated(event, issue) {
698692 logger . debugWithContext ( 'DB record not found. Issue label update ignored.' , event , issue ) ;
699693 return ;
700694 }
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+ }
701700 await dbHelper . update ( models . Issue , dbIssue . id , {
702701 labels : issue . labels ,
703702 updatedAt : new Date ( )
@@ -720,6 +719,11 @@ async function handleIssueUnAssignment(event, issue) {
720719 // Ignore it.
721720 return ;
722721 }
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+ }
723727 if ( dbIssue . assignee ) {
724728 const assigneeUserId = await gitHelper . getUserIdByLogin ( event , dbIssue . assignee ) ;
725729 if ( ! assigneeUserId ) {
@@ -861,10 +865,7 @@ async function process(event) {
861865 const fullRepoUrl = gitHelper . getFullRepoUrl ( event ) ;
862866 event . data . repository . repoUrl = fullRepoUrl ;
863867
864- const project = await dbHelper . scanOne ( models . Project , {
865- repoUrl : fullRepoUrl ,
866- archived : 'false'
867- } ) ;
868+ const project = await dbHelper . queryOneActiveProject ( models . Project , fullRepoUrl ) ;
868869
869870 issue . projectId = project . id ;
870871
0 commit comments