Skip to content

Commit bf42e92

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 6655ade + c2d213b commit bf42e92

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

services/IssueService.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ const eventService = require('./EventService');
2626

2727
const md = new MarkdownIt();
2828

29+
// A variable to store issue creation lock to prevent duplicate creation process.
30+
// The key is `${provider}-${repositoryId}-${number}`. The value is True.
31+
const issueCreationLock = {};
32+
2933
/**
3034
* Generate the contest url, given the challenge id
3135
* @param {String} challengeId The id of the challenge in topcoder
@@ -555,6 +559,13 @@ async function handleIssueCreate(event, issue, forceAssign = false) {
555559
return;
556560
}
557561

562+
const creationLockKey = `${issue.provider}-${issue.repositoryId}-${issue.number}`;
563+
if (issueCreationLock[creationLockKey]) {
564+
throw new Error(
565+
`Issue ${creationLockKey} is creating.`);
566+
}
567+
issueCreationLock[creationLockKey] = true;
568+
558569
// create issue with challenge creation pending
559570
const issueObject = _.assign({}, _.omit(issue, 'assignee'), {
560571
id: helper.generateIdentifier(),
@@ -594,6 +605,7 @@ async function handleIssueCreate(event, issue, forceAssign = false) {
594605
logger.error(`Challenge creation failure: ${e}`);
595606
await dbHelper.removeIssue(models.Issue, issue.repositoryId, issue.number, issue.provider);
596607
await eventService.handleEventGracefully(event, issue, e);
608+
delete issueCreationLock[creationLockKey];
597609
return;
598610
}
599611

@@ -610,6 +622,7 @@ async function handleIssueCreate(event, issue, forceAssign = false) {
610622
await handleIssueAssignment(event, issue, true);
611623
}
612624
}
625+
delete issueCreationLock[creationLockKey];
613626
logger.debug(`new challenge created with id ${issue.challengeId} for issue ${issue.number}`);
614627
}
615628

utils/topcoder-api-helper.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const m2m = m2mAuth(_.pick(config, ['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_
2525

2626
let topcoderApiProjects = require('topcoder-api-projects');
2727
let topcoderApiChallenges = require('@topcoder-platform/topcoder-api-challenges-v4-wrapper');
28-
let topcoderApiChallengesV3 = require('topcoder-api-challenges');
2928

3029
const topcoderDevApiProjects = require('topcoder-dev-api-projects');
3130
const topcoderDevApiChallenges = require('@topcoder-platform/topcoder-api-challenges-v4-wrapper-dev');
@@ -46,7 +45,6 @@ let cachedAccessToken;
4645
// Init the API instances
4746
const projectsClient = topcoderApiProjects.ApiClient.instance;
4847
const challengesClient = topcoderApiChallenges.ApiClient.instance;
49-
const challengesClientV3 = topcoderApiChallengesV3.ApiClient.instance;
5048

5149
// Timeout increase to 5 minutes
5250
challengesClient.timeout = 300000;
@@ -299,13 +297,10 @@ async function getChallengeById(id) {
299297
* @param {Number} winnerId the winner id
300298
*/
301299
async function closeChallenge(id, winnerId) {
302-
const apiKey = await getAccessToken();
300+
const apiKey = await getM2Mtoken();
303301
logger.debug(`Closing challenge ${id}`);
304302
try {
305303
let basePath = challengesClient.basePath;
306-
if (!config.TC_DEV_ENV) {
307-
basePath = challengesClientV3.basePath;
308-
}
309304
const response = await axios.post(`${basePath}/challenges/${id}/close?winnerId=${winnerId}`, null, {
310305
headers: {
311306
authorization: `Bearer ${apiKey}`,

0 commit comments

Comments
 (0)