Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 24ea967

Browse files
committed
Ignore copilot payment if assignee is copilot. Add paid comment.
1 parent 7ffee6d commit 24ea967

File tree

5 files changed

+82
-14
lines changed

5 files changed

+82
-14
lines changed

services/AzureService.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,10 @@ getUsernameById.schema = {
183183
* @param {Number} issueId the issue number
184184
* @param {Number} challengeId the challenge id
185185
* @param {Array} existLabels the issue labels
186+
* @param {String} winner the winner topcoder handle
187+
* @param {Boolean} createCopilotPayments the option to create copilot payments or not
186188
*/
187-
async function markIssueAsPaid(copilot, repoFullName, issueId, challengeId, existLabels) {
189+
async function markIssueAsPaid(copilot, repoFullName, issueId, challengeId, existLabels, winner, createCopilotPayments) { // eslint-disable-line max-params
188190
Joi.attempt({copilot, repoFullName, issueId, challengeId}, markIssueAsPaid.schema);
189191
const labels = _(existLabels).filter((i) => i !== config.FIX_ACCEPTED_ISSUE_LABEL)
190192
.push(config.FIX_ACCEPTED_ISSUE_LABEL, config.PAID_ISSUE_LABEL).value();
@@ -199,7 +201,16 @@ async function markIssueAsPaid(copilot, repoFullName, issueId, challengeId, exis
199201
.set('Authorization', `Bearer ${copilot.accessToken}`)
200202
.set('Content-Type', 'application/json-patch+json')
201203
.end();
202-
const body = helper.prepareAutomatedComment(`Payment task has been updated: ${config.TC_OR_DETAIL_LINK}${challengeId}`, copilot);
204+
205+
let commentMessage = '```\n';
206+
commentMessage += '*Payments Complete*\n';
207+
commentMessage += `Winner: ${winner}\n`;
208+
if (createCopilotPayments) {
209+
commentMessage += `Copilot: ${copilot.topcoderUsername}\n`;
210+
}
211+
commentMessage += '```\n';
212+
commentMessage += `Payment task has been updated: ${config.TC_OR_DETAIL_LINK}${challengeId}`;
213+
const body = helper.prepareAutomatedComment(commentMessage, copilot);
203214
await request
204215
.post(`${config.AZURE_DEVOPS_API_BASE_URL}/${repoFullName}/_apis/wit/workItems/${issueId}/comments?api-version=5.1-preview.3`)
205216
.send({

services/GithubService.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,17 +236,28 @@ getUserIdByLogin.schema = {
236236
* @param {Number} number the issue number
237237
* @param {Number} challengeId the challenge id
238238
* @param {Array} existLabels the issue labels
239+
* @param {String} winner the winner topcoder handle
240+
* @param {Boolean} createCopilotPayments the option to create copilot payments or not
239241
*
240242
*/
241-
async function markIssueAsPaid(copilot, repoFullName, number, challengeId, existLabels) {
242-
Joi.attempt({copilot, repoFullName, number, challengeId, existLabels}, markIssueAsPaid.schema);
243+
async function markIssueAsPaid(copilot, repoFullName, number, challengeId, existLabels, winner, createCopilotPayments) { // eslint-disable-line max-params
244+
Joi.attempt({copilot, repoFullName, number, challengeId, existLabels, winner, createCopilotPayments}, markIssueAsPaid.schema);
243245
const github = await _authenticate(copilot.accessToken);
244246
const {owner, repo} = _parseRepoUrl(repoFullName);
245247
const labels = _(existLabels).filter((i) => i !== config.FIX_ACCEPTED_ISSUE_LABEL)
246248
.push(config.FIX_ACCEPTED_ISSUE_LABEL, config.PAID_ISSUE_LABEL).value();
247249
try {
248250
await github.issues.edit({owner, repo, number, labels});
249-
const body = helper.prepareAutomatedComment(`Payment task has been updated: ${config.TC_OR_DETAIL_LINK}${challengeId}`, copilot);
251+
let commentMessage = '```\n';
252+
commentMessage += '*Payments Complete*\n';
253+
commentMessage += `Winner: ${winner}\n`;
254+
if (createCopilotPayments) {
255+
commentMessage += `Copilot: ${copilot.topcoderUsername}\n`;
256+
}
257+
commentMessage += '```\n';
258+
commentMessage += `Payment task has been updated: ${config.TC_OR_DETAIL_LINK}${challengeId}`;
259+
260+
const body = helper.prepareAutomatedComment(commentMessage, copilot);
250261
await github.issues.createComment({owner, repo, number, body});
251262
} catch (err) {
252263
throw errors.convertGitHubError(err, 'Error occurred during updating issue as paid.');
@@ -259,7 +270,9 @@ markIssueAsPaid.schema = {
259270
repoFullName: Joi.string().required(),
260271
number: Joi.number().required(),
261272
challengeId: Joi.number().positive().required(),
262-
existLabels: Joi.array().items(Joi.string()).required()
273+
existLabels: Joi.array().items(Joi.string()).required(),
274+
winner: Joi.string().required(),
275+
createCopilotPayments: Joi.boolean().default(false).optional()
263276
};
264277

265278
/**

services/GitlabService.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,26 @@ getUserIdByLogin.schema = {
199199
* @param {Number} issueId the issue number
200200
* @param {Number} challengeId the challenge id
201201
* @param {Array} existLabels the issue labels
202+
* @param {String} winner the winner topcoder handle
203+
* @param {Boolean} createCopilotPayments the option to create copilot payments or not
202204
*/
203-
async function markIssueAsPaid(copilot, projectId, issueId, challengeId, existLabels) {
205+
async function markIssueAsPaid(copilot, projectId, issueId, challengeId, existLabels, winner, createCopilotPayments) { // eslint-disable-line max-params
204206
Joi.attempt({copilot, projectId, issueId, challengeId}, markIssueAsPaid.schema);
205207
const gitlab = await _authenticate(copilot.accessToken);
206208
const labels = _(existLabels).filter((i) => i !== config.FIX_ACCEPTED_ISSUE_LABEL)
207209
.push(config.FIX_ACCEPTED_ISSUE_LABEL, config.PAID_ISSUE_LABEL).value();
208210
try {
209211
await gitlab.projects.issues.edit(projectId, issueId, {labels: labels.join(',')});
210-
const body = helper.prepareAutomatedComment(`Payment task has been updated: ${config.TC_OR_DETAIL_LINK}${challengeId}`, copilot);
212+
let commentMessage = '```\n';
213+
commentMessage += '*Payments Complete*\n';
214+
commentMessage += `Winner: ${winner}\n`;
215+
if (createCopilotPayments) {
216+
commentMessage += `Copilot: ${copilot.topcoderUsername}\n`;
217+
}
218+
commentMessage += '```\n';
219+
commentMessage += `Payment task has been updated: ${config.TC_OR_DETAIL_LINK}${challengeId}`;
220+
221+
const body = helper.prepareAutomatedComment(commentMessage, copilot);
211222
await gitlab.projects.issues.notes.create(projectId, issueId, {body});
212223
} catch (err) {
213224
throw errors.convertGitLabError(err, 'Error occurred during updating issue as paid.');

services/IssueService.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,11 @@ async function handleIssueClose(event, issue) { // eslint-disable-line
465465
await topcoderApiHelper.updateChallenge(dbIssue.challengeId, updateBody);
466466

467467
const copilotAlreadySet = await topcoderApiHelper.roleAlreadySet(dbIssue.challengeId, 'Copilot');
468+
const createCopilotPayments = project.createCopilotPayments === 'true' &&
469+
event.copilot.topcoderUsername.toLowerCase() !== assigneeMember.topcoderUsername.toLowerCase();
470+
event.createCopilotPayments = createCopilotPayments;
468471

469-
if (!copilotAlreadySet && project.createCopilotPayments === 'true') {
472+
if (!copilotAlreadySet && createCopilotPayments) {
470473
logger.debugWithContext(`Getting the topcoder member ID for copilot name : ${event.copilot.topcoderUsername}`, event, issue);
471474
// get copilot tc user id
472475
const copilotTopcoderUserId = await topcoderApiHelper.getTopcoderMemberId(event.copilot.topcoderUsername);
@@ -530,7 +533,13 @@ async function handleIssueClose(event, issue) { // eslint-disable-line
530533
status: 'challenge_payment_successful',
531534
updatedAt: new Date()
532535
});
533-
await gitHelper.markIssueAsPaid(event, issue.number, dbIssue.challengeId, labels);
536+
await gitHelper.markIssueAsPaid(
537+
event,
538+
issue.number,
539+
dbIssue.challengeId,
540+
labels,
541+
event.assigneeMember.topcoderUsername,
542+
event.createCopilotPayments);
534543
} catch (e) {
535544
await eventService.handleEventGracefully(event, issue, e);
536545
return;
@@ -922,6 +931,7 @@ process.schema = Joi.object().keys({
922931
}).required(),
923932
retryCount: Joi.number().integer().default(0).optional(),
924933
paymentSuccessful: Joi.boolean().default(false).optional(),
934+
createCopilotPayments: Joi.boolean().default(false).optional(),
925935
challengeValid: Joi.boolean().default(false).optional(),
926936
dbIssue: Joi.object().optional(),
927937
assigneeMember: Joi.object().optional()

utils/git-helper.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,37 @@ class GitHelper {
137137
* @param {Number} issueNumber the issue Number
138138
* @param {Number} challengeId the challenge id
139139
* @param {Array} existLabels the exist labels of the issue
140+
* @param {String} winner the winner topcoder handle
141+
* @param {Boolean} createCopilotPayments the option to create copilot payments or not
140142
*/
141-
async markIssueAsPaid(event, issueNumber, challengeId, existLabels) {
143+
async markIssueAsPaid(event, issueNumber, challengeId, existLabels, winner, createCopilotPayments = false) { // eslint-disable-line max-params
142144
if (event.provider === 'github') {
143-
await gitHubService.markIssueAsPaid(event.copilot, event.data.repository.full_name, issueNumber, challengeId, existLabels);
145+
await gitHubService.markIssueAsPaid(
146+
event.copilot,
147+
event.data.repository.full_name,
148+
issueNumber,
149+
challengeId,
150+
existLabels,
151+
winner,
152+
createCopilotPayments);
144153
} else if (event.provider === 'gitlab') {
145-
await gitlabService.markIssueAsPaid(event.copilot, event.data.repository.id, issueNumber, challengeId, existLabels);
154+
await gitlabService.markIssueAsPaid(
155+
event.copilot,
156+
event.data.repository.id,
157+
issueNumber,
158+
challengeId,
159+
existLabels,
160+
winner,
161+
createCopilotPayments);
146162
} else if (event.provider === 'azure') {
147-
await azureService.markIssueAsPaid(event.copilot, event.data.repository.full_name, issueNumber, challengeId, existLabels);
163+
await azureService.markIssueAsPaid(
164+
event.copilot,
165+
event.data.repository.full_name,
166+
issueNumber,
167+
challengeId,
168+
existLabels,
169+
winner,
170+
createCopilotPayments);
148171
}
149172
}
150173

0 commit comments

Comments
 (0)