From 38d8fce88589afb3a107a528bcc7770ed8eee289 Mon Sep 17 00:00:00 2001 From: Pedro Pombeiro Date: Thu, 8 Feb 2018 10:11:11 +0100 Subject: [PATCH] Modify Slack message when bounty has been approved - Instead of mentioning that is has been unassigned from the `bounty-awaiting-approval` column --- .github/github-bot.yml | 3 +- .../assign-to-bounty-awaiting-for-approval.js | 30 +++++++++++++------ .../bounty-awaiting-approval-slack-ping.js | 7 ++++- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/.github/github-bot.yml b/.github/github-bot.yml index c3d34b6..3426e28 100644 --- a/.github/github-bot.yml +++ b/.github/github-bot.yml @@ -6,7 +6,8 @@ project-board: bounty-project-board: name: 'Status SOB Swarm' - label-name: 'bounty-awaiting-approval' + awaiting-approval-label-name: 'bounty-awaiting-approval' + bounty-label-name: 'bounty' awaiting-approval-column-name: 'bounty-awaiting-approval' welcome-bot: diff --git a/bot_scripts/assign-to-bounty-awaiting-for-approval.js b/bot_scripts/assign-to-bounty-awaiting-for-approval.js index 20aed8f..170a2df 100644 --- a/bot_scripts/assign-to-bounty-awaiting-for-approval.js +++ b/bot_scripts/assign-to-bounty-awaiting-for-approval.js @@ -47,12 +47,13 @@ async function assignIssueToBountyAwaitingForApproval (context, robot, assign) { const repoName = payload.repository.name // const config = await getConfig(context, 'github-bot.yml', defaultConfig(robot, '.github/github-bot.yml')) const config = defaultConfig(robot, '.github/github-bot.yml') + const projectBoardConfig = config['bounty-project-board'] - if (!config['bounty-project-board']) { + if (!projectBoardConfig) { return } - const watchedLabelName = config['bounty-project-board']['label-name'] + const watchedLabelName = projectBoardConfig['awaiting-approval-label-name'] if (payload.label.name !== watchedLabelName) { robot.log.debug(`assignIssueToBountyAwaitingForApproval - ${payload.label.name} doesn't match watched ${watchedLabelName} label. Ignoring`) return @@ -68,8 +69,8 @@ async function assignIssueToBountyAwaitingForApproval (context, robot, assign) { // TODO: The org project and project column info should be cached // in order to improve performance and reduce roundtrips let column = null - const projectBoardName = config['bounty-project-board'].name - const approvalColumnName = config['bounty-project-board']['awaiting-approval-column-name'] + const projectBoardName = projectBoardConfig.name + const approvalColumnName = projectBoardConfig['awaiting-approval-column-name'] try { const orgName = ownerName @@ -107,6 +108,9 @@ async function assignIssueToBountyAwaitingForApproval (context, robot, assign) { return } + const bountyLabelName = projectBoardConfig['bounty-label-name'] + const isOfficialBounty = !!payload.issue.labels.find(l => l.name === bountyLabelName) + if (process.env.DRY_RUN) { if (assign) { robot.log.info(`Would have created card for issue`, column.id, payload.issue.id) @@ -141,12 +145,20 @@ async function assignIssueToBountyAwaitingForApproval (context, robot, assign) { } } - if (!process.env.DRY_RUN_BOUNTY_APPROVAL) { - // Send message to Slack - if (assign) { - slackHelper.sendMessage(robot, slackClient, config.slack.notification.room, `Assigned issue to ${approvalColumnName} in ${projectBoardName} project\n${payload.issue.html_url}`) + let message + // Send message to Slack + if (assign) { + message = `Assigned issue to ${approvalColumnName} in ${projectBoardName} project\n${payload.issue.html_url}` + } else { + if (isOfficialBounty) { + message = `${payload.issue.html_url} has been approved as an official bounty!` } else { - slackHelper.sendMessage(robot, slackClient, config.slack.notification.room, `Unassigned issue from ${approvalColumnName} in ${projectBoardName} project\n${payload.issue.html_url}`) + message = `Unassigned issue from ${approvalColumnName} in ${projectBoardName} project\n${payload.issue.html_url}` } } + + if (message && !process.env.DRY_RUN_BOUNTY_APPROVAL) { + // Send message to Slack + slackHelper.sendMessage(robot, slackClient, config.slack.notification.room, message) + } } diff --git a/bot_scripts/bounty-awaiting-approval-slack-ping.js b/bot_scripts/bounty-awaiting-approval-slack-ping.js index f4f2479..a58758e 100644 --- a/bot_scripts/bounty-awaiting-approval-slack-ping.js +++ b/bot_scripts/bounty-awaiting-approval-slack-ping.js @@ -38,8 +38,13 @@ async function notifyCollaborators (context, robot, slackClient, getSlackMention const ownerName = payload.repository.owner.login const repoName = payload.repository.name const config = defaultConfig(robot, '.github/github-bot.yml') + const projectBoardConfig = config['bounty-project-board'] - const watchedLabelName = config['bounty-project-board']['label-name'] + if (!projectBoardConfig) { + return + } + + const watchedLabelName = projectBoardConfig['awaiting-approval-label-name'] if (payload.label.name !== watchedLabelName) { robot.log.debug(`bountyAwaitingApprovalSlackPing - ${payload.label.name} doesn't match watched ${watchedLabelName} label. Ignoring`) return null