From c7405077754f4b6ca8ddba4a65962151f62bee83 Mon Sep 17 00:00:00 2001 From: Pedro Pombeiro Date: Fri, 23 Feb 2018 14:27:35 +0100 Subject: [PATCH] Add bounty size info on Slack message for promoted bounty issues --- README.md | 1 + .../assign-to-bounty-awaiting-for-approval.js | 36 ++++++++++++++----- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 769a08f..b956c1e 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,7 @@ Examples of settings that can be configured: - `bounty-project-board/awaiting-approval-column-name`: Name of the column in the bounty project board to group issues that are awaiting for bounty approval - `bounty-project-board/awaiting-approval-label-name`: Name of the label used in issues to declare that an issue is awaiting approval to become a bounty - `bounty-project-board/bounty-label-name`: Name of the label used in issues to declare that an issue is a bounty + - `bounty-project-board/bounty-size-label-name-regex`: Regular expression that matches the bounty size label and returns a group containing the size itself - `bounty-project-board/post-approved-bounties-to-slack-room`: Name of the Slack room where to cross-post approved bounties - Automated tests settings: diff --git a/bot_scripts/assign-to-bounty-awaiting-for-approval.js b/bot_scripts/assign-to-bounty-awaiting-for-approval.js index 86f8ae8..3a2efb3 100644 --- a/bot_scripts/assign-to-bounty-awaiting-for-approval.js +++ b/bot_scripts/assign-to-bounty-awaiting-for-approval.js @@ -66,6 +66,7 @@ async function assignIssueToBountyAwaitingForApproval (context, robot, assign) { const bountyLabelName = projectBoardConfig['bounty-label-name'] const isOfficialBounty = !!payload.issue.labels.find(l => l.name === bountyLabelName) + const bountySize = getBountySize(payload.issue.labels, projectBoardConfig) if (process.env.DRY_RUN) { if (assign) { @@ -101,7 +102,7 @@ async function assignIssueToBountyAwaitingForApproval (context, robot, assign) { } } - const slackMessage = getSlackMessage(projectBoardConfig.name, approvalColumnName, payload, assign, isOfficialBounty) + const slackMessage = getSlackMessage(projectBoardConfig.name, approvalColumnName, payload, assign, isOfficialBounty, bountySize) if (slackMessage && !process.env.DRY_RUN_BOUNTY_APPROVAL) { // Send message to Slack slackHelper.sendMessage(robot, config.slack.notification.room, slackMessage) @@ -116,14 +117,33 @@ async function assignIssueToBountyAwaitingForApproval (context, robot, assign) { } } -function getSlackMessage (projectBoardName, approvalColumnName, payload, assign, isOfficialBounty) { +function getSlackMessage (projectBoardName, approvalColumnName, payload, assign, isOfficialBounty, bountySize) { if (assign) { return `Assigned issue to ${approvalColumnName} in ${projectBoardName} project\n${payload.issue.html_url}` - } else { - if (isOfficialBounty) { - return `${payload.issue.html_url} has been approved as an official bounty!` - } else { - return `Unassigned issue from ${approvalColumnName} in ${projectBoardName} project\n${payload.issue.html_url}` - } } + + if (!isOfficialBounty) { + return `Unassigned issue from ${approvalColumnName} in ${projectBoardName} project\n${payload.issue.html_url}` + } + + if (bountySize) { + return `${payload.issue.html_url} has been approved as an official bounty (size: ${bountySize})!` + } + return `${payload.issue.html_url} has been approved as an official bounty!` +} + +function getBountySize (labels, projectBoardConfig) { + const regexString = projectBoardConfig['bounty-size-label-name-regex'] + if (!regexString) { + return null + } + + const bountySizeLabelRegex = new RegExp(regexString) + + const match = labels.map(l => bountySizeLabelRegex.exec(l.name)).find(m => m != null) + if (match) { + return match[1] + } + + return null }