diff --git a/services/IssueService.js b/services/IssueService.js index e293887..d625c47 100755 --- a/services/IssueService.js +++ b/services/IssueService.js @@ -237,6 +237,8 @@ async function handleIssueAssignment(event, issue, force = false) { const contestUrl = getUrlForChallengeId(dbIssue.challengeId); const comment = `Contest ${contestUrl} has been updated - ${userMapping.topcoderUsername} has been unassigned.`; await rollbackAssignee(event, assigneeUserId, issue, false, comment); + const additionalComment = `${userMapping.topcoderUsername} has been unassigned because this ticket doesn't have the ${config.OPEN_FOR_PICKUP_ISSUE_LABEL} label.`; // eslint-disable-line max-len + await gitHelper.createComment(event, issue.number, additionalComment); } else { 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`; await rollbackAssignee(event, assigneeUserId, issue, false, comment); diff --git a/utils/topcoder-api-helper.js b/utils/topcoder-api-helper.js index 8c86227..903d3cf 100644 --- a/utils/topcoder-api-helper.js +++ b/utils/topcoder-api-helper.js @@ -60,7 +60,7 @@ const challengesApiInstance = new topcoderApiChallenges.DefaultApi(); * @returns {String} the access token issued by Topcoder * @private */ -async function getAccessToken() { +async function getAccessToken() { // eslint-disable-line no-unused-vars // Check the cached access token if (cachedAccessToken) { const decoded = jwtDecode(cachedAccessToken); @@ -115,7 +115,7 @@ async function getM2Mtoken() { * @returns {Number} the created project id */ async function createProject(projectName) { - bearer.apiKey = await getAccessToken(); + bearer.apiKey = await getM2Mtoken(); // eslint-disable-next-line new-cap const projectBody = new topcoderApiProjects.ProjectRequestBody.constructFromObject({ projectName @@ -147,7 +147,7 @@ async function createProject(projectName) { * @returns {Number} the created challenge id */ async function createChallenge(challenge) { - bearer.apiKey = await getAccessToken(); + bearer.apiKey = await getM2Mtoken(); const start = new Date(); const startTime = moment(start).toISOString(); const end = moment(start).add(config.NEW_CHALLENGE_DURATION_IN_DAYS, 'days').toISOString(); @@ -188,7 +188,7 @@ async function createChallenge(challenge) { * @param {Object} challenge the challenge to update */ async function updateChallenge(id, challenge) { - bearer.apiKey = await getAccessToken(); + bearer.apiKey = await getM2Mtoken(); logger.debug(`Updating challenge ${id} with ${circularJSON.stringify(challenge)}`); // eslint-disable-next-line new-cap const challengeBody = new topcoderApiChallenges.UpdateChallengeBodyParam.constructFromObject({ @@ -226,7 +226,7 @@ async function updateChallenge(id, challenge) { * @param {Number} id the challenge id */ async function activateChallenge(id) { - bearer.apiKey = await getAccessToken(); + bearer.apiKey = await getM2Mtoken(); logger.debug(`Activating challenge ${id}`); try { const response = await new Promise((resolve, reject) => { @@ -266,7 +266,7 @@ async function getChallengeById(id) { if (!_.isNumber(id)) { throw new Error('The challenge id must valid number'); } - const apiKey = await getAccessToken(); + const apiKey = await getM2Mtoken(); logger.debug('Getting topcoder challenge details'); try { const response = await axios.get(`${challengesClient.basePath}/challenges/${id}`, { @@ -297,7 +297,7 @@ async function getChallengeById(id) { * @param {Number} winnerId the winner id */ async function closeChallenge(id, winnerId) { - const apiKey = await getAccessToken(); + const apiKey = await getM2Mtoken(); logger.debug(`Closing challenge ${id}`); try { const basePath = challengesClient.basePath; @@ -328,7 +328,7 @@ async function closeChallenge(id, winnerId) { * @returns {Number} the billing account id */ async function getProjectBillingAccountId(id) { - const apiKey = await getAccessToken(); + const apiKey = await getM2Mtoken(); logger.debug(`Getting project billing detail ${id}`); try { const response = await axios.get(`${projectsClient.basePath}/direct/projects/${id}`, { @@ -360,7 +360,7 @@ async function getProjectBillingAccountId(id) { * @returns {Number} the user id */ async function getTopcoderMemberId(handle) { - bearer.apiKey = await getAccessToken(); + bearer.apiKey = await getM2Mtoken(); try { const response = await axios.get(`${projectsClient.basePath}/members/${handle}`); const statusCode = response ? response.status : null; @@ -379,7 +379,7 @@ async function getTopcoderMemberId(handle) { * @param {Object} resource the resource resource to add */ async function addResourceToChallenge(id, resource) { - bearer.apiKey = await getAccessToken(); + bearer.apiKey = await getM2Mtoken(); logger.debug(`adding resource to challenge ${id}`); try { const response = await new Promise((resolve, reject) => { @@ -420,7 +420,7 @@ async function getResourcesFromChallenge(id) { if (!_.isNumber(id)) { throw new Error('The challenge id must valid number'); } - const apiKey = await getAccessToken(); + const apiKey = await getM2Mtoken(); logger.debug(`fetch resource from challenge ${id}`); try { const response = await axios.get(`${challengesClient.basePath}/challenges/${id}/resources`, { @@ -465,7 +465,7 @@ async function roleAlreadySet(id, role) { * @param {Object} resource the resource resource to remove */ async function unregisterUserFromChallenge(id) { - bearer.apiKey = await getAccessToken(); + bearer.apiKey = await getM2Mtoken(); logger.debug(`removing resource from challenge ${id}`); try { const response = await new Promise((resolve, reject) => { @@ -502,7 +502,7 @@ async function unregisterUserFromChallenge(id) { * @param {Number} id the challenge id */ async function cancelPrivateContent(id) { - bearer.apiKey = await getAccessToken(); + bearer.apiKey = await getM2Mtoken(); logger.debug(`Cancelling challenge ${id}`); try { const response = await new Promise((resolve, reject) => { @@ -550,7 +550,7 @@ async function assignUserAsRegistrant(topcoderUserId, challengeId) { * @param {Object} resource the resource resource to remove */ async function removeResourceToChallenge(id, resource) { - bearer.apiKey = await getAccessToken(); + bearer.apiKey = await getM2Mtoken(); logger.debug(`removing resource from challenge ${id}`); try { const response = await new Promise((resolve, reject) => { @@ -580,7 +580,7 @@ async function removeResourceToChallenge(id, resource) { * @returns {Array} the resources of challenge */ async function getChallengeResources(id) { - const apiKey = await getAccessToken(); + const apiKey = await getM2Mtoken(); logger.debug(`getting resource from challenge ${id}`); try { const response = await axios.get(`${challengesClient.basePath}/challenges/${id}/resources`, {