add handler for milestones

This commit is contained in:
Andrea Maria Piana 2020-12-29 09:46:01 +01:00
parent 3c8fc9fb58
commit b609b96c8f
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
3 changed files with 56 additions and 18 deletions

View File

@ -1,32 +1,63 @@
const zh = require('../zh-client'),
resolveIssueNumbers = require('../resolve-issue-number'),
{ INPUT_INPROG_COLUMN } = process.env;
resolveIssueNumbers = require('../resolve-issue-number'),
{ INPUT_REVIEW_COLUMN, INPUT_INPROG_COLUMN, INPUT_NEXT_COLUMN } = process.env;
exports.milestoned = async function handleMilestonedIssue (tools) {
tools.log.info('Handling assigned issue...');
const failures = [],
{ payload } = tools.context;
const issueNo = payload.issue.number;
let zenHubIssue = await zh.issues.getIssue(payload.repository.id, issueNo);
if (!zenHubIssue) {
tools.log.info("issue not found")
return
}
if (zenHubIssue.pipeline.pipeline_id == INPUT_INPROG_COLUMN || zenHubIssue.pipeline.pipeline_id == INPUT_REVIEW_COLUMN) {
tools.log.info("issue already in progress or in review")
return
}
// Move it to the NEXT column
try {
tools.log.info(`Moving issue #${issueNo} to in progress...`);
await zh.issues.moveIssueBetweenPipelines(payload.repository.id, issueNo, {
pipeline_id: NEXT_INPROG_COLUMN,
position: 'top'
});
tools.log.info(`Moved #${issueNo} to in progress.`);
} catch (e) {
failures.push(`Failed to move #${issueNo} to in progress: ${e}`);
}
}
exports.assigned = async function handleAssignedIssue (tools) {
tools.log.info('Handling assigned issue...');
const failures = [],
{ payload } = tools.context;
{ payload } = tools.context;
const issueNo = payload.issue.number;
// Move issue(s) to INPROG_COLUMN
if (INPUT_INPROG_COLUMN) {
try {
tools.log.info(`Moving issue #${issueNo} to in progress...`);
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'
});
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}`);
}
}
tools.log.info(`Moved #${issueNo} to in progress.`);
} catch (e) {
failures.push(`Failed to move #${issueNo} to in progress: ${e}`);
}
}
if (failures.length) {
throw new Error(`Failed to execute some actions: ${failures.map(x => x.message || x).join(', ')}`);
}
if (failures.length) {
throw new Error(`Failed to execute some actions: ${failures.map(x => x.message || x).join(', ')}`);
}
};

6
package-lock.json generated
View File

@ -1281,6 +1281,12 @@
"load-json-file": "^4.0.0"
}
},
"prettier": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.2.1.tgz",
"integrity": "sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q==",
"dev": true
},
"psl": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/psl/-/psl-1.2.0.tgz",

View File

@ -13,6 +13,7 @@
},
"devDependencies": {
"chai": "^4.2.0",
"mocha": "^8.2.0"
"mocha": "^8.2.0",
"prettier": "2.2.1"
}
}