add handling of issues assigned

This commit is contained in:
Andrea Maria Piana 2020-12-02 09:07:06 +01:00
parent 0fc7ccad52
commit d32ed164e2
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
2 changed files with 12 additions and 35 deletions

View File

@ -5,6 +5,7 @@ const tools = new Toolkit();
const handlers = { const handlers = {
create: 'create.js', create: 'create.js',
issues: 'issues.js',
ready_for_review: 'create.js', ready_for_review: 'create.js',
pull_request: 'pull_request.js' pull_request: 'pull_request.js'
} }

View File

@ -2,51 +2,27 @@ const zh = require('../zh-client'),
resolveIssueNumbers = require('../resolve-issue-number'), resolveIssueNumbers = require('../resolve-issue-number'),
{ INPUT_INPROG_COLUMN } = process.env; { INPUT_INPROG_COLUMN } = process.env;
exports.branch = async function handleCreatedBranch (tools) { exports.assigned = async function handleAssignedIssue (tools) {
tools.log.info('Handling created branch...'); tools.log.info('Handling assigned issue...');
const failures = [], const failures = [],
{ payload } = tools.context; { payload } = tools.context;
let issueNumbers = resolveIssueNumbers(payload.ref); console.log(payload)
if (!issueNumbers || issueNumbers.length < 1) { // Move issue(s) to INPROG_COLUMN
return tools.exit.neutral('No issues detected to act upon.'); if (INPUT_INPROG_COLUMN) {
}
for (let i = 0; i < issueNumbers.length; i++) {
let issueNo = issueNumbers[i];
// Assign sender to issue(s)
try { try {
tools.log.info(`Adding assignees for #${issueNo}...`); tools.log.info(`Moving issue #${issueNo} to in progress...`);
await tools.github.issues.addAssignees({ await zh.issues.moveIssueBetweenPipelines(payload.repository.id, issueNo, {
owner: payload.repository.owner.login, pipeline_id: INPUT_INPROG_COLUMN,
repo: payload.repository.name, position: 'top'
issue_number: issueNo,
assignees: [ payload.sender.login ]
}); });
tools.log.info(`Added assignees for #${issueNo}.`); tools.log.info(`Moved #${issueNo} to in progress.`);
} catch (e) { } catch (e) {
failures.push(`Failed to added assignees for #${issueNo}: ${e}`); failures.push(`Failed to move #${issueNo} to in progress: ${e}`);
}
// Move issue(s) to INPROG_COLUMN
if (INPUT_INPROG_COLUMN) {
try {
tools.log.info(`Moving issue #${issueNo} to in progress...`);
await zh.issues.moveIssueBetweenPipelines(payload.repository.id, issueNo, {
pipeline_id: INPUT_INPROG_COLUMN,
position: 'top'
});
tools.log.info(`Moved #${issueNo} to in progress.`);
} catch (e) {
failures.push(`Failed to move #${issueNo} to in progress: ${e}`);
}
} }
} }