Skip to content

Commit fe4a6be

Browse files
authored
User ID and Group ID mentions (#15)
* id mentions * update readme
1 parent 3d0a01b commit fe4a6be

File tree

3 files changed

+41
-11
lines changed

3 files changed

+41
-11
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ jobs:
3434
MAKE_PRETTY : false
3535
MAKE_COMPACT : false
3636
IS_PR_FROM_FORK: false
37-
uses: jun3453/[email protected]
37+
SEND_USER_ID_MENTIONS : ABCDE12345,AAABBBCCCC
38+
SEND_GROUP_ID_MENTIONS : GROUPIDDDD,GGGGROUPID
39+
uses: jun3453/[email protected]
3840
```
3941
4042
### Arguments
@@ -66,3 +68,15 @@ Whether notifications should support PRs from forks. By default, only the branch
6668
If set to 'true', it will add the branch owner in front of the branch name ('owner:branch' vs 'branch'). If this option is used, you may need to enable fork pull request workflows under your repository's Actions settings.
6769
6870
![make_compact and is_pr_fork](https://raw.githubusercontent.com/jun3453/slack-pr-open-notification-action/images/make_compact_fork.png)
71+
72+
#### SEND_USER_ID_MENTIONS
73+
**string (Optional)**
74+
Throw mentions to a specific user.
75+
Enter your Slack user ID separated by commas.
76+
Please google how to find out your user ID.
77+
78+
#### SEND_GROUP_ID_MENTIONS
79+
**string (Optional)**
80+
Throw mentions to a specific group.
81+
Enter your Slack group ID separated by commas.
82+
Please google how to find out your group ID.

SlackPrNotification.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,19 @@ var compareBranchOwner = process.env.PULL_REQUEST_COMPARE_BRANCH_OWNER;
1212
var compareBranchName = process.env.PULL_REQUEST_COMPARE_BRANCH_NAME;
1313
var baseBranchOwner = process.env.PULL_REQUEST_BASE_BRANCH_OWNER;
1414
var baseBranchName = process.env.PULL_REQUEST_BASE_BRANCH_NAME;
15-
var sendHereMention = process.env.IS_SEND_HERE_MENTION.toLowerCase() === "true" ? "<!here>\n" : "";
15+
var sendHereMention = process.env.IS_SEND_HERE_MENTION.toLowerCase() === "true" ? "<!here>" : "";
16+
var sendUserIDMentions = process.env.SEND_USER_ID_MENTIONS ? process.env.SEND_USER_ID_MENTIONS.split(",").map(function (id) {
17+
return "<@" + id + ">";
18+
}).join(" ") : "";
19+
var sendGroupIDMentions = process.env.SEND_GROUP_ID_MENTIONS ? process.env.SEND_GROUP_ID_MENTIONS.split(",").map(function (id) {
20+
return "<!subteam^" + id + ">";
21+
}).join(" ") : "";
22+
var mentions = sendHereMention + sendUserIDMentions + sendGroupIDMentions + "\n";
1623
var prFromFork = process.env.IS_PR_FROM_FORK;
1724
var compareBranchText = prFromFork === "true" ? compareBranchOwner + ":" + compareBranchName : compareBranchName;
1825
var baseBranchText = prFromFork === "true" ? baseBranchOwner + ":" + baseBranchName : baseBranchName;
19-
var makePretty = process.env.MAKE_PRETTY ? process.env.MAKE_PRETTY.toLowerCase() === "true" : false; //Priority is pretty > compact > normal
20-
var makeCompact = process.env.MAKE_COMPACT ? process.env.MAKE_COMPACT.toLowerCase() === "true" : false;
26+
var makePretty = process.env.MAKE_PRETTY.toLowerCase() === "true"; //Priority is pretty > compact > normal
27+
var makeCompact = process.env.MAKE_COMPACT.toLowerCase() === "true";
2128
if (makePretty) {
2229
var message = {
2330
attachments: [
@@ -29,7 +36,7 @@ if (makePretty) {
2936
block_id: "commit_title",
3037
text: {
3138
type: "mrkdwn",
32-
text: "*<" + prUrl + "|" + prTitle + ">* #" + prNum + " from *" + baseBranchText + "* to *" + compareBranchText + "*." + sendHereMention
39+
text: "*<" + prUrl + "|" + prTitle + ">* #" + prNum + " from *" + baseBranchText + "* to *" + compareBranchText + "*." + mentions
3340
}
3441
},
3542
{
@@ -78,7 +85,7 @@ else if (makeCompact) {
7885
block_id: "commit_title",
7986
text: {
8087
type: "mrkdwn",
81-
text: "*<" + prUrl + "|" + prTitle + ">* #" + prNum + " from *" + baseBranchText + "* to *" + compareBranchText + "*." + sendHereMention
88+
text: "*<" + prUrl + "|" + prTitle + ">* #" + prNum + " from *" + baseBranchText + "* to *" + compareBranchText + "*." + mentions
8289
}
8390
},
8491
{
@@ -107,7 +114,7 @@ else {
107114
type: "section",
108115
text: {
109116
type: "mrkdwn",
110-
text: sendHereMention + "*<" + prUrl + "|" + prTitle + ">*"
117+
text: mentions + "*<" + prUrl + "|" + prTitle + ">*"
111118
},
112119
accessory: {
113120
type: "image",

SlackPrNotification.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,16 @@ const compareBranchOwner: string = process.env.PULL_REQUEST_COMPARE_BRANCH_OWNER
1111
const compareBranchName: string = process.env.PULL_REQUEST_COMPARE_BRANCH_NAME;
1212
const baseBranchOwner: string = process.env.PULL_REQUEST_BASE_BRANCH_OWNER;
1313
const baseBranchName: string = process.env.PULL_REQUEST_BASE_BRANCH_NAME;
14-
const sendHereMention: string = process.env.IS_SEND_HERE_MENTION.toLowerCase() === "true" ? "<!here>\n" : "";
14+
15+
const sendHereMention: string = process.env.IS_SEND_HERE_MENTION.toLowerCase() === "true" ? "<!here>" : "";
16+
const sendUserIDMentions: string = process.env.SEND_USER_ID_MENTIONS ? process.env.SEND_USER_ID_MENTIONS.split(",").map(id => {
17+
return "<@" + id + ">"
18+
}).join(" ") : ""
19+
const sendGroupIDMentions: string = process.env.SEND_GROUP_ID_MENTIONS ? process.env.SEND_GROUP_ID_MENTIONS.split(",").map(id => {
20+
return "<!subteam^" + id + ">"
21+
}).join(" ") : ""
22+
23+
const mentions = sendHereMention + sendUserIDMentions + sendGroupIDMentions + "\n"
1524

1625
const prFromFork: string = process.env.IS_PR_FROM_FORK;
1726
const compareBranchText: string = prFromFork === "true" ? compareBranchOwner + ":" + compareBranchName : compareBranchName;
@@ -31,7 +40,7 @@ if (makePretty) {
3140
block_id: "commit_title",
3241
text: {
3342
type: "mrkdwn",
34-
text: "*<" + prUrl + "|" + prTitle + ">* #" + prNum + " from *" + baseBranchText + "* to *" + compareBranchText + "*." + sendHereMention
43+
text: "*<" + prUrl + "|" + prTitle + ">* #" + prNum + " from *" + baseBranchText + "* to *" + compareBranchText + "*." + mentions
3544
}
3645
},
3746
{
@@ -79,7 +88,7 @@ if (makePretty) {
7988
block_id: "commit_title",
8089
text: {
8190
type: "mrkdwn",
82-
text: "*<" + prUrl + "|" + prTitle + ">* #" + prNum + " from *" + baseBranchText + "* to *" + compareBranchText + "*." + sendHereMention
91+
text: "*<" + prUrl + "|" + prTitle + ">* #" + prNum + " from *" + baseBranchText + "* to *" + compareBranchText + "*." + mentions
8392
}
8493
},
8594
{
@@ -107,7 +116,7 @@ if (makePretty) {
107116
type: "section",
108117
text: {
109118
type: "mrkdwn",
110-
text: sendHereMention + "*<" + prUrl + "|" + prTitle + ">*",
119+
text: mentions + "*<" + prUrl + "|" + prTitle + ">*",
111120
},
112121
accessory: {
113122
type: "image",

0 commit comments

Comments
 (0)