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

Ignore copilot payment if assignee is copilot. Add paid comment. #56

Merged
merged 1 commit into from
Jul 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions services/AzureService.js
Original file line number Diff line number Diff line change
@@ -183,8 +183,10 @@ getUsernameById.schema = {
* @param {Number} issueId the issue number
* @param {Number} challengeId the challenge id
* @param {Array} existLabels the issue labels
* @param {String} winner the winner topcoder handle
* @param {Boolean} createCopilotPayments the option to create copilot payments or not
*/
async function markIssueAsPaid(copilot, repoFullName, issueId, challengeId, existLabels) {
async function markIssueAsPaid(copilot, repoFullName, issueId, challengeId, existLabels, winner, createCopilotPayments) { // eslint-disable-line max-params
Joi.attempt({copilot, repoFullName, issueId, challengeId}, markIssueAsPaid.schema);
const labels = _(existLabels).filter((i) => i !== config.FIX_ACCEPTED_ISSUE_LABEL)
.push(config.FIX_ACCEPTED_ISSUE_LABEL, config.PAID_ISSUE_LABEL).value();
@@ -199,7 +201,16 @@ async function markIssueAsPaid(copilot, repoFullName, issueId, challengeId, exis
.set('Authorization', `Bearer ${copilot.accessToken}`)
.set('Content-Type', 'application/json-patch+json')
.end();
const body = helper.prepareAutomatedComment(`Payment task has been updated: ${config.TC_OR_DETAIL_LINK}${challengeId}`, copilot);

let commentMessage = '```\n';
commentMessage += '*Payments Complete*\n';
commentMessage += `Winner: ${winner}\n`;
if (createCopilotPayments) {
commentMessage += `Copilot: ${copilot.topcoderUsername}\n`;
}
commentMessage += '```\n';
commentMessage += `Payment task has been updated: ${config.TC_OR_DETAIL_LINK}${challengeId}`;
const body = helper.prepareAutomatedComment(commentMessage, copilot);
await request
.post(`${config.AZURE_DEVOPS_API_BASE_URL}/${repoFullName}/_apis/wit/workItems/${issueId}/comments?api-version=5.1-preview.3`)
.send({
21 changes: 17 additions & 4 deletions services/GithubService.js
Original file line number Diff line number Diff line change
@@ -236,17 +236,28 @@ getUserIdByLogin.schema = {
* @param {Number} number the issue number
* @param {Number} challengeId the challenge id
* @param {Array} existLabels the issue labels
* @param {String} winner the winner topcoder handle
* @param {Boolean} createCopilotPayments the option to create copilot payments or not
*
*/
async function markIssueAsPaid(copilot, repoFullName, number, challengeId, existLabels) {
Joi.attempt({copilot, repoFullName, number, challengeId, existLabels}, markIssueAsPaid.schema);
async function markIssueAsPaid(copilot, repoFullName, number, challengeId, existLabels, winner, createCopilotPayments) { // eslint-disable-line max-params
Joi.attempt({copilot, repoFullName, number, challengeId, existLabels, winner, createCopilotPayments}, markIssueAsPaid.schema);
const github = await _authenticate(copilot.accessToken);
const {owner, repo} = _parseRepoUrl(repoFullName);
const labels = _(existLabels).filter((i) => i !== config.FIX_ACCEPTED_ISSUE_LABEL)
.push(config.FIX_ACCEPTED_ISSUE_LABEL, config.PAID_ISSUE_LABEL).value();
try {
await github.issues.edit({owner, repo, number, labels});
const body = helper.prepareAutomatedComment(`Payment task has been updated: ${config.TC_OR_DETAIL_LINK}${challengeId}`, copilot);
let commentMessage = '```\n';
commentMessage += '*Payments Complete*\n';
commentMessage += `Winner: ${winner}\n`;
if (createCopilotPayments) {
commentMessage += `Copilot: ${copilot.topcoderUsername}\n`;
}
commentMessage += '```\n';
commentMessage += `Payment task has been updated: ${config.TC_OR_DETAIL_LINK}${challengeId}`;

const body = helper.prepareAutomatedComment(commentMessage, copilot);
await github.issues.createComment({owner, repo, number, body});
} catch (err) {
throw errors.convertGitHubError(err, 'Error occurred during updating issue as paid.');
@@ -259,7 +270,9 @@ markIssueAsPaid.schema = {
repoFullName: Joi.string().required(),
number: Joi.number().required(),
challengeId: Joi.number().positive().required(),
existLabels: Joi.array().items(Joi.string()).required()
existLabels: Joi.array().items(Joi.string()).required(),
winner: Joi.string().required(),
createCopilotPayments: Joi.boolean().default(false).optional()
};

/**
15 changes: 13 additions & 2 deletions services/GitlabService.js
Original file line number Diff line number Diff line change
@@ -199,15 +199,26 @@ getUserIdByLogin.schema = {
* @param {Number} issueId the issue number
* @param {Number} challengeId the challenge id
* @param {Array} existLabels the issue labels
* @param {String} winner the winner topcoder handle
* @param {Boolean} createCopilotPayments the option to create copilot payments or not
*/
async function markIssueAsPaid(copilot, projectId, issueId, challengeId, existLabels) {
async function markIssueAsPaid(copilot, projectId, issueId, challengeId, existLabels, winner, createCopilotPayments) { // eslint-disable-line max-params
Joi.attempt({copilot, projectId, issueId, challengeId}, markIssueAsPaid.schema);
const gitlab = await _authenticate(copilot.accessToken);
const labels = _(existLabels).filter((i) => i !== config.FIX_ACCEPTED_ISSUE_LABEL)
.push(config.FIX_ACCEPTED_ISSUE_LABEL, config.PAID_ISSUE_LABEL).value();
try {
await gitlab.projects.issues.edit(projectId, issueId, {labels: labels.join(',')});
const body = helper.prepareAutomatedComment(`Payment task has been updated: ${config.TC_OR_DETAIL_LINK}${challengeId}`, copilot);
let commentMessage = '```\n';
commentMessage += '*Payments Complete*\n';
commentMessage += `Winner: ${winner}\n`;
if (createCopilotPayments) {
commentMessage += `Copilot: ${copilot.topcoderUsername}\n`;
}
commentMessage += '```\n';
commentMessage += `Payment task has been updated: ${config.TC_OR_DETAIL_LINK}${challengeId}`;

const body = helper.prepareAutomatedComment(commentMessage, copilot);
await gitlab.projects.issues.notes.create(projectId, issueId, {body});
} catch (err) {
throw errors.convertGitLabError(err, 'Error occurred during updating issue as paid.');
14 changes: 12 additions & 2 deletions services/IssueService.js
Original file line number Diff line number Diff line change
@@ -465,8 +465,11 @@ async function handleIssueClose(event, issue) { // eslint-disable-line
await topcoderApiHelper.updateChallenge(dbIssue.challengeId, updateBody);

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

if (!copilotAlreadySet && project.createCopilotPayments === 'true') {
if (!copilotAlreadySet && createCopilotPayments) {
logger.debugWithContext(`Getting the topcoder member ID for copilot name : ${event.copilot.topcoderUsername}`, event, issue);
// get copilot tc user id
const copilotTopcoderUserId = await topcoderApiHelper.getTopcoderMemberId(event.copilot.topcoderUsername);
@@ -530,7 +533,13 @@ async function handleIssueClose(event, issue) { // eslint-disable-line
status: 'challenge_payment_successful',
updatedAt: new Date()
});
await gitHelper.markIssueAsPaid(event, issue.number, dbIssue.challengeId, labels);
await gitHelper.markIssueAsPaid(
event,
issue.number,
dbIssue.challengeId,
labels,
event.assigneeMember.topcoderUsername,
event.createCopilotPayments);
} catch (e) {
await eventService.handleEventGracefully(event, issue, e);
return;
@@ -922,6 +931,7 @@ process.schema = Joi.object().keys({
}).required(),
retryCount: Joi.number().integer().default(0).optional(),
paymentSuccessful: Joi.boolean().default(false).optional(),
createCopilotPayments: Joi.boolean().default(false).optional(),
challengeValid: Joi.boolean().default(false).optional(),
dbIssue: Joi.object().optional(),
assigneeMember: Joi.object().optional()
31 changes: 27 additions & 4 deletions utils/git-helper.js
Original file line number Diff line number Diff line change
@@ -137,14 +137,37 @@ class GitHelper {
* @param {Number} issueNumber the issue Number
* @param {Number} challengeId the challenge id
* @param {Array} existLabels the exist labels of the issue
* @param {String} winner the winner topcoder handle
* @param {Boolean} createCopilotPayments the option to create copilot payments or not
*/
async markIssueAsPaid(event, issueNumber, challengeId, existLabels) {
async markIssueAsPaid(event, issueNumber, challengeId, existLabels, winner, createCopilotPayments = false) { // eslint-disable-line max-params
if (event.provider === 'github') {
await gitHubService.markIssueAsPaid(event.copilot, event.data.repository.full_name, issueNumber, challengeId, existLabels);
await gitHubService.markIssueAsPaid(
event.copilot,
event.data.repository.full_name,
issueNumber,
challengeId,
existLabels,
winner,
createCopilotPayments);
} else if (event.provider === 'gitlab') {
await gitlabService.markIssueAsPaid(event.copilot, event.data.repository.id, issueNumber, challengeId, existLabels);
await gitlabService.markIssueAsPaid(
event.copilot,
event.data.repository.id,
issueNumber,
challengeId,
existLabels,
winner,
createCopilotPayments);
} else if (event.provider === 'azure') {
await azureService.markIssueAsPaid(event.copilot, event.data.repository.full_name, issueNumber, challengeId, existLabels);
await azureService.markIssueAsPaid(
event.copilot,
event.data.repository.full_name,
issueNumber,
challengeId,
existLabels,
winner,
createCopilotPayments);
}
}