This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
forked from Mustack/deploy-notifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslackMessages.js
101 lines (95 loc) · 2.47 KB
/
slackMessages.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
function getUserStrings(user) {
return {
short: user.slack
? `<@${user.slack.id}>`
: `<${user.gh.data.html_url}|${user.gh.data.login}>`,
long: user.slack
? `<@${user.slack.id}>`
: `Slack user not found. Github user: <${user.gh.data.html_url}|${user.gh.data.login}> (Make sure your full name in GH and Slack match)`,
};
}
export function createDeploymentNotificationMessage({
users,
pr,
repo_name,
sha1,
workflow_url,
}) {
const author = getUserStrings(users.author);
const merger = getUserStrings(users.merger);
const initialMessage = [];
initialMessage.push({
type: "section",
text: {
type: "mrkdwn",
text: `${merger.short}, by merging a PR to \`main\`, has started a deployment of ${repo_name} to \`production\`
If you didn't mean to start this deployment, please go to <${workflow_url}|the workflow on CircleCI> and cancel it.
Expectations of ${merger.short}:
- They will be available for at least an hour to respond to any issues that come up. Please keep an eye on #incidents
- They will test new changes in production when the deployment is done.
- They have gotten approval for visual changes with their team's designer, unless those changes are hidden behind a feature flag`,
},
});
initialMessage.push({
type: "section",
text: {
type: "mrkdwn",
text: `*PR Title*: <${pr.data.html_url}|${pr.data.title}>`,
},
});
initialMessage.push({
type: "section",
text: {
type: "mrkdwn",
text: `*Author*: ${author.long}`,
},
});
if (users.merger.gh.login !== users.author.gh.login) {
initialMessage.push({
type: "section",
text: {
type: "mrkdwn",
text: `*Merger*: ${merger.long}`,
},
});
}
initialMessage.push({
type: "section",
text: {
type: "mrkdwn",
text: `*Commit*: ${sha1}`,
},
});
initialMessage.push({
type: "actions",
elements: [
{
type: "button",
text: {
type: "plain_text",
text: "View Build Log",
},
url: workflow_url,
},
],
});
return {
initialMessage,
thread: [
{
type: "section",
text: {
type: "mrkdwn",
text: `*The pull request description follows a different markdown format than Slack, so it might look weird.*`,
},
},
{
type: "section",
text: {
type: "mrkdwn",
text: pr.data.body,
},
},
],
};
}