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 = {
create: 'create.js',
issues: 'issues.js',
ready_for_review: 'create.js',
pull_request: 'pull_request.js'
}

View File

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