forked from jun3453/slack-pr-open-notification-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SlackPrNotification.js
79 lines (76 loc) · 3.13 KB
/
SlackPrNotification.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
"use strict";
exports.__esModule = true;
var axios_1 = require("axios");
var url = process.env.SLACK_WEBHOOK_URL;
var prNum = process.env.PULL_REQUEST_NUMBER;
var prTitle = process.env.PULL_REQUEST_TITLE;
var prUrl = process.env.PULL_REQUEST_URL;
var prBody = process.env.PULL_REQUEST_BODY || "No description provided.";
var authorName = process.env.PULL_REQUEST_AUTHOR_NAME;
var authorIconUrl = process.env.PULL_REQUEST_AUTHOR_ICON_URL;
var compareBranchOwner = process.env.PULL_REQUEST_COMPARE_BRANCH_OWNER;
var compareBranchName = process.env.PULL_REQUEST_COMPARE_BRANCH_NAME;
var baseBranchOwner = process.env.PULL_REQUEST_BASE_BRANCH_OWNER;
var baseBranchName = process.env.PULL_REQUEST_BASE_BRANCH_NAME;
var sendHereMention = process.env.IS_SEND_HERE_MENTION.toLowerCase() === "true" ? "<!here>\n" : "";
var requestedReviewers = JSON.parse(process.env.PULL_REQUEST_REQUESTED_REVIEWERS);
var requestedReviewersExist = Object.keys(requestedReviewers).length === 0 ? "false" : "true"
var prFromFork = process.env.IS_PR_FROM_FORK;
var mainSectionTitleText = prFromFork === "true" ? sendHereMention + "*<" + prUrl + "|" + prTitle + " (" + baseBranchOwner + "#" + prNum + ")>*" : sendHereMention + "*<" + prUrl + "|" + prTitle + " (" + "#" + prNum + ")>*";
var compareBranchText = prFromFork === "true" ? "*Compare branch*\n" + compareBranchOwner + ":" + compareBranchName : "*Compare branch*\n" + compareBranchName;
var baseBranchText = prFromFork === "true" ? "*Base branch*\n" + baseBranchOwner + ":" + baseBranchName : "*Base branch*\n" + baseBranchName;
var requestedReviewersText = "";
if (requestedReviewersExist === "true") {
for (var i = 0; i < requestedReviewers.length; i++) {
if (i == requestedReviewers.length - 1) {
requestedReviewersText = requestedReviewersText.concat(requestedReviewers[i].login);
} else {
requestedReviewersText = requestedReviewersText.concat(requestedReviewers[i].login + ", ");
}
}
}
var message = {
blocks: [
{
type: "section",
text: {
type: "mrkdwn",
text: mainSectionTitleText
},
accessory: {
type: "image",
image_url: authorIconUrl,
alt_text: "github icon"
},
fields: [
{
type: "mrkdwn",
text: "*Author*\n" + authorName
},
{
type: "mrkdwn",
text: baseBranchText
},
{
type: "mrkdwn",
text: "*Reviewers*\n" + requestedReviewersText
},
{
type: "mrkdwn",
text: compareBranchText
},
]
},
{
type: "section",
text: {
type: "plain_text",
text: prBody,
emoji: true
}
},
]
};
if (requestedReviewersExist === "true") {
axios_1["default"].post(url, message);
}