Skip to content

Commit 9a55ced

Browse files
Merge pull request #45 from chargebee/feat/repo-name-slack-msg
Add repo name prefix to Slack PR completion messages
1 parent 2602e17 commit 9a55ced

3 files changed

Lines changed: 26 additions & 6 deletions

File tree

dist/index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ const { masterBranch } = __nccwpck_require__(51629);
198198

199199
function toPr(context) {
200200
let { base, body, user, html_url, title, number, head, id} = context.payload.pull_request
201+
let repoFullName = (base && base.repo && base.repo.full_name) ||
202+
(head && head.repo && head.repo.full_name) || "";
203+
201204
return {
202205
description: body,
203206
authorHandle: user.login,
@@ -207,7 +210,8 @@ function toPr(context) {
207210
from: head.ref,
208211
to: base.ref,
209212
id: id,
210-
typeOfChange: head.ref.split('/')[0]
213+
typeOfChange: head.ref.split('/')[0],
214+
repoFullName: repoFullName
211215
}
212216
}
213217

@@ -415,6 +419,7 @@ async function test() {
415419
// await onPrClose({ payload: { pull_request: closedPr } })
416420
}
417421

422+
418423
/***/ }),
419424

420425
/***/ 87351:
@@ -107969,6 +107974,10 @@ function entry(label, value) {
107969107974
return slack.markdown(`*${label}:* ${value}`)
107970107975
}
107971107976

107977+
function repoPrefix(pr) {
107978+
return pr && pr.repoFullName ? `[${pr.repoFullName}] ` : ""
107979+
}
107980+
107972107981
async function notifyNewPR(pr) {
107973107982
if (isAuthoredByBot(pr.authorHandle)) {
107974107983
return;
@@ -107987,8 +107996,9 @@ async function notifyNewPR(pr) {
107987107996
async function notifyMergedPR(pr, mergedBy) {
107988107997
let textMessage = `${mergedBy} has merged a PR ${pr.title}(${pr.url})`
107989107998
if (isAuthoredByBot(mergedBy)) {
107999+
let completedMessage = `${repoPrefix(pr)}${pr.title} - completed`
107990108000
await slack.sendMessage(channelName(pr), textMessage, [
107991-
slack.markdown(pr.title + " - completed")
108001+
slack.markdown(completedMessage)
107992108002
]);
107993108003
return
107994108004
}
@@ -108049,6 +108059,7 @@ async function autoSyncFailed(channelName) {
108049108059
}
108050108060
module.exports = {notifyNewPR, notifyMergedPR, notifyClosedPR, notifyPrHasConflicts, notifyPrMergeFailed, autoSyncFailed}
108051108061

108062+
108052108063
/***/ }),
108053108064

108054108065
/***/ 22877:

handlers/pr.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ const { masterBranch } = require("../constants");
66

77
function toPr(context) {
88
let { base, body, user, html_url, title, number, head, id} = context.payload.pull_request
9+
let repoFullName = (base && base.repo && base.repo.full_name) ||
10+
(head && head.repo && head.repo.full_name) || "";
11+
912
return {
1013
description: body,
1114
authorHandle: user.login,
@@ -15,7 +18,8 @@ function toPr(context) {
1518
from: head.ref,
1619
to: base.ref,
1720
id: id,
18-
typeOfChange: head.ref.split('/')[0]
21+
typeOfChange: head.ref.split('/')[0],
22+
repoFullName: repoFullName
1923
}
2024
}
2125

@@ -221,4 +225,4 @@ async function test() {
221225

222226
// var closedPr = JSON.parse(fs.readFileSync('./../ops/dev/fakes/pr/close.json', 'utf8'));
223227
// await onPrClose({ payload: { pull_request: closedPr } })
224-
}
228+
}

notifications/slack.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ function entry(label, value) {
3737
return slack.markdown(`*${label}:* ${value}`)
3838
}
3939

40+
function repoPrefix(pr) {
41+
return pr && pr.repoFullName ? `[${pr.repoFullName}] ` : ""
42+
}
43+
4044
async function notifyNewPR(pr) {
4145
if (isAuthoredByBot(pr.authorHandle)) {
4246
return;
@@ -55,8 +59,9 @@ async function notifyNewPR(pr) {
5559
async function notifyMergedPR(pr, mergedBy) {
5660
let textMessage = `${mergedBy} has merged a PR ${pr.title}(${pr.url})`
5761
if (isAuthoredByBot(mergedBy)) {
62+
let completedMessage = `${repoPrefix(pr)}${pr.title} - completed`
5863
await slack.sendMessage(channelName(pr), textMessage, [
59-
slack.markdown(pr.title + " - completed")
64+
slack.markdown(completedMessage)
6065
]);
6166
return
6267
}
@@ -115,4 +120,4 @@ async function autoSyncFailed(channelName) {
115120
slack.header(":need_action: AUTO SYNC FAILED :need_action:")
116121
])
117122
}
118-
module.exports = {notifyNewPR, notifyMergedPR, notifyClosedPR, notifyPrHasConflicts, notifyPrMergeFailed, autoSyncFailed}
123+
module.exports = {notifyNewPR, notifyMergedPR, notifyClosedPR, notifyPrHasConflicts, notifyPrMergeFailed, autoSyncFailed}

0 commit comments

Comments
 (0)