Modify Slack message when bounty has been approved

- Instead of mentioning that is has been unassigned from the `bounty-awaiting-approval` column
This commit is contained in:
Pedro Pombeiro 2018-02-08 10:11:11 +01:00
parent 9ff69661a1
commit 38d8fce885
No known key found for this signature in database
GPG Key ID: A65DEB11E4BBC647
3 changed files with 29 additions and 11 deletions

View File

@ -6,7 +6,8 @@ project-board:
bounty-project-board: bounty-project-board:
name: 'Status SOB Swarm' 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' awaiting-approval-column-name: 'bounty-awaiting-approval'
welcome-bot: welcome-bot:

View File

@ -47,12 +47,13 @@ async function assignIssueToBountyAwaitingForApproval (context, robot, assign) {
const repoName = payload.repository.name const repoName = payload.repository.name
// const config = await getConfig(context, 'github-bot.yml', defaultConfig(robot, '.github/github-bot.yml')) // const config = await getConfig(context, 'github-bot.yml', defaultConfig(robot, '.github/github-bot.yml'))
const config = 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 return
} }
const watchedLabelName = config['bounty-project-board']['label-name'] const watchedLabelName = projectBoardConfig['awaiting-approval-label-name']
if (payload.label.name !== watchedLabelName) { if (payload.label.name !== watchedLabelName) {
robot.log.debug(`assignIssueToBountyAwaitingForApproval - ${payload.label.name} doesn't match watched ${watchedLabelName} label. Ignoring`) robot.log.debug(`assignIssueToBountyAwaitingForApproval - ${payload.label.name} doesn't match watched ${watchedLabelName} label. Ignoring`)
return return
@ -68,8 +69,8 @@ async function assignIssueToBountyAwaitingForApproval (context, robot, assign) {
// TODO: The org project and project column info should be cached // TODO: The org project and project column info should be cached
// in order to improve performance and reduce roundtrips // in order to improve performance and reduce roundtrips
let column = null let column = null
const projectBoardName = config['bounty-project-board'].name const projectBoardName = projectBoardConfig.name
const approvalColumnName = config['bounty-project-board']['awaiting-approval-column-name'] const approvalColumnName = projectBoardConfig['awaiting-approval-column-name']
try { try {
const orgName = ownerName const orgName = ownerName
@ -107,6 +108,9 @@ async function assignIssueToBountyAwaitingForApproval (context, robot, assign) {
return return
} }
const bountyLabelName = projectBoardConfig['bounty-label-name']
const isOfficialBounty = !!payload.issue.labels.find(l => l.name === bountyLabelName)
if (process.env.DRY_RUN) { if (process.env.DRY_RUN) {
if (assign) { if (assign) {
robot.log.info(`Would have created card for issue`, column.id, payload.issue.id) 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) { let message
// Send message to Slack // Send message to Slack
if (assign) { if (assign) {
slackHelper.sendMessage(robot, slackClient, config.slack.notification.room, `Assigned issue to ${approvalColumnName} in ${projectBoardName} project\n${payload.issue.html_url}`) 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 { } 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)
}
} }

View File

@ -38,8 +38,13 @@ async function notifyCollaborators (context, robot, slackClient, getSlackMention
const ownerName = payload.repository.owner.login const ownerName = payload.repository.owner.login
const repoName = payload.repository.name const repoName = payload.repository.name
const config = defaultConfig(robot, '.github/github-bot.yml') 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) { if (payload.label.name !== watchedLabelName) {
robot.log.debug(`bountyAwaitingApprovalSlackPing - ${payload.label.name} doesn't match watched ${watchedLabelName} label. Ignoring`) robot.log.debug(`bountyAwaitingApprovalSlackPing - ${payload.label.name} doesn't match watched ${watchedLabelName} label. Ignoring`)
return null return null