diff --git a/index.js b/index.js index 0991eeb..7fafd06 100644 --- a/index.js +++ b/index.js @@ -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' } diff --git a/lib/handlers/create.js b/lib/handlers/create.js index 896dfe5..4400b4c 100644 --- a/lib/handlers/create.js +++ b/lib/handlers/create.js @@ -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}`); } }