Skip to content

Commit 414ed7f

Browse files
feat: message template added (shubhaamgupta11#19)
* feat: new template added for pr and issues on slack and discord * feat: slack id makes optional * dist changed
1 parent 802a588 commit 414ed7f

File tree

7 files changed

+206
-96
lines changed

7 files changed

+206
-96
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ jobs:
4747
# Slack-specific inputs
4848
slack_bot_token: "${{ secrets.SLACK_BOT_TOKEN }}"
4949
slack_channel: "<channel-id>"
50-
slack_id_type: "<user/group>"
51-
slack_id: "<user-id/group-id>"
50+
slack_id_type: "<user/group>" # Optional: Only needed to ping someone directly.
51+
slack_id: "<user-id/group-id>" # Optional: Only needed if slack_id_type is provided.
5252
```
5353
54+
> **Note:** slack_id_type and slack_id are only needed if you want to ping someone directly.
55+
5456
### Monitoring PRs with Discord
5557
5658
```yml
@@ -84,7 +86,7 @@ jobs:
8486
discord_webhook_url: "${{ secrets.DISCORD_WEBHOOK_URL }}"
8587
```
8688
87-
> **Note:** You can configure any notifier (slack, discord) for any task (monitor-issues, monitor-prs, etc.).
89+
> **Note:** You can configure any notifier (slack, discord) for any task (monitor-issues, monitor-prs, etc.).
8890
8991
## 🔧 Inputs
9092

action/integrations/discord.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const discordWrapper = (webhookUrl) => {
1515
};
1616

1717
// Send Discord Notifications
18-
const sendDiscordNotification = async (webhookUrl, issues, repo) => {
18+
const sendDiscordNotification = async (webhookUrl, issues, repo, type) => {
1919
if (!issues.length) {
2020
console.log("No issues found within the specified time frame.");
2121
return;
@@ -24,12 +24,30 @@ const sendDiscordNotification = async (webhookUrl, issues, repo) => {
2424
const discord = discordWrapper(webhookUrl);
2525

2626
for (const issue of issues) {
27-
const message = `
28-
**New Issue in ${repo}**
29-
**Title:** ${issue.title}
30-
**Labels:** ${issue.labels.map((label) => `\`${label}\``).join(", ")}
31-
**Link:** ${issue.url}
32-
`;
27+
let message = '';
28+
if (type === 'issue') {
29+
message = `
30+
:chart_with_upwards_trend: **New Issue in ${repo}**
31+
*-* **Title:** ${issue.title}
32+
*-* **Labels:** ${issue.labels
33+
.map((label) => `\`${label}\``)
34+
.join(", ")}
35+
*-* **Link:** <${issue.url}>
36+
37+
Mark as acknowledged👍 after triaging
38+
`;
39+
} else if (type === 'pr') {
40+
message = `
41+
:sparkles: **New Pull Request in ${repo}**
42+
*-* **Title:** ${issue.title}
43+
*-* **Author:** ${issue.author}
44+
*-* **Labels:** ${issue.labels
45+
.map((label) => `\`${label}\``)
46+
.join(", ")}
47+
*-* **Link:** <${issue.url}>
48+
Review and acknowledge👍
49+
`;
50+
}
3351

3452
try {
3553
await discord.sendMessage(message);

action/integrations/slack.js

Lines changed: 69 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,42 +24,76 @@ const slackWrapper = (token, channel) => {
2424
};
2525
};
2626

27-
const sendSlackNotification = async (slackToken, slackChannel, slackIDType, slackID, issues, repo) => {
28-
if (!issues.length) {
29-
console.log("No issues found within the specified time frame.");
30-
return;
31-
}
32-
33-
const slack = slackWrapper(slackToken, slackChannel);
34-
35-
const assigneeText =
36-
slackIDType === "group"
37-
? `*Assignee:* <!subteam^${slackID}> *(Mark as ACK or Done after triaging)*`
38-
: slackIDType === "user"
39-
? `*Assignee:* <@${slackID}> *(Mark as ACK or Done after triaging)*`
40-
: "";
41-
42-
for (const issue of issues) {
43-
const message = `
44-
:chart_with_upwards_trend: *New Issue in ${repo}*
45-
*-* *Title:* ${issue.title}
46-
*-* *Labels:* ${issue.labels.map((label) => `\`${label}\``).join(", ")}
47-
*-* *Link:* <${issue.url}|View Issue>
48-
${assigneeText}
49-
`;
50-
51-
try {
52-
await slack.sendMessage({ text: message });
53-
console.log(`Posted issue "${issue.title}" to Slack.`);
54-
} catch (error) {
55-
console.error(`Failed to post issue "${issue.title}" to Slack:`, error.message);
27+
const sendSlackNotification = async (
28+
slackToken,
29+
slackChannel,
30+
slackIDType,
31+
slackID,
32+
issues,
33+
repo,
34+
type
35+
) => {
36+
if (!issues.length) {
37+
console.log("No issues found within the specified time frame.");
38+
return;
39+
}
40+
41+
const slack = slackWrapper(slackToken, slackChannel);
42+
43+
for (const issue of issues) {
44+
let message = "";
45+
let assigneeText = "";
46+
47+
if (type === "issue") {
48+
assigneeText =
49+
slackIDType === "group"
50+
? `*Assignee:* <!subteam^${slackID}> *(Mark as ACK or Done after triaging)*`
51+
: slackIDType === "user"
52+
? `*Assignee:* <@${slackID}> *(Mark as ACK or Done after triaging)*`
53+
: "";
54+
55+
message = `
56+
:chart_with_upwards_trend: *New Issue in ${repo}*
57+
*-* *Title:* ${issue.title}
58+
*-* *Labels:* ${issue.labels
59+
.map((label) => `\`${label}\``)
60+
.join(", ")}
61+
*-* *Link:* <${issue.url}|View Issue>
62+
${assigneeText}
63+
`;
64+
} else if (type === "pr") {
65+
if (slackIDType === "group") {
66+
assigneeText = `*Reviewer:* <!subteam^${slackID}> *(Review and acknowledge)*`;
67+
} else if (slackIDType === "user") {
68+
assigneeText = `*Reviewer:* <@${slackID}> *(Review and acknowledge)*`;
5669
}
57-
58-
console.log("Waiting for 30 seconds before sending the next message...");
59-
await delay(5 * 1000);
70+
message = `
71+
:sparkles: *New Pull Request in ${repo}*
72+
*-* *Title:* ${issue.title}
73+
*-* *Author:* ${issue.author}
74+
*-* *Labels:* ${issue.labels
75+
.map((label) => `\`${label}\``)
76+
.join(", ")}
77+
*-* *Link:* <${issue.url}|View PR>
78+
${assigneeText}
79+
`;
6080
}
61-
62-
console.log(`*** All issues posted on Slack for ${repo} ***`);
63-
};
81+
82+
try {
83+
await slack.sendMessage({ text: message });
84+
console.log(`Posted issue "${issue.title}" to Slack.`);
85+
} catch (error) {
86+
console.error(
87+
`Failed to post issue "${issue.title}" to Slack:`,
88+
error.message
89+
);
90+
}
91+
92+
console.log("Waiting for 30 seconds before sending the next message...");
93+
await delay(5 * 1000);
94+
}
95+
96+
console.log(`*** All issues posted on Slack for ${repo} ***`);
97+
};
6498

6599
module.exports = sendSlackNotification;

action/monitor-new-issue.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ async function monitorIssues({
9898
slackIDType,
9999
slackID,
100100
issues,
101-
repo
101+
repo,
102+
"issue"
102103
);
103104
} else if (notifier === "discord") {
104105
const {
@@ -108,7 +109,7 @@ async function monitorIssues({
108109
"🔔 Sending notifications to Discord for issues:",
109110
issues.map((issue) => issue.title)
110111
);
111-
await sendDiscordNotification(discordWebhookUrl, issues, repo);
112+
await sendDiscordNotification(discordWebhookUrl, issues, repo, "issue");
112113
} else {
113114
throw new Error("Unsupported notifier. Use 'slack' or 'discord'.");
114115
}

action/monitor-new-pr.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ async function monitorPRs({
101101
slackIDType,
102102
slackID,
103103
prs,
104-
repo
104+
repo,
105+
"pr"
105106
);
106107
} else if (notifier === "discord") {
107108
const {
@@ -111,7 +112,7 @@ async function monitorPRs({
111112
"🔔 Sending notifications to Discord for PRs:",
112113
prs.map((pr) => pr.title)
113114
);
114-
await sendDiscordNotification(discordWebhookUrl, prs, repo);
115+
await sendDiscordNotification(discordWebhookUrl, prs, repo, "pr");
115116
} else {
116117
throw new Error("Unsupported notifier. Use 'slack' or 'discord'.");
117118
}

0 commit comments

Comments
 (0)