Skip to content

Commit 7f9665d

Browse files
feat: strict checks for required inputs (shubhaamgupta11#24)
* feat: safe checks added * feat: version bumup
1 parent 3597ef3 commit 7f9665d

File tree

8 files changed

+68
-10
lines changed

8 files changed

+68
-10
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
with:
3636
node-version: '20'
3737
- name: Monitor New Issues
38-
uses: shubhaamgupta11/[email protected].1
38+
uses: shubhaamgupta11/[email protected].2
3939
with:
4040
# required inputs
4141
task: "monitor-issues"
@@ -73,7 +73,7 @@ jobs:
7373
with:
7474
node-version: '20'
7575
- name: Monitor New PRs
76-
uses: shubhaamgupta11/[email protected].1
76+
uses: shubhaamgupta11/[email protected].2
7777
with:
7878
# required inputs
7979
task: "monitor-prs"

action/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ async function run() {
2424
const discordIDType = core.getInput("discord_id_type");
2525
const discordIDs = core.getInput("discord_ids");
2626

27+
// Check if git_secret is provided
28+
if (!gitToken) {
29+
core.setFailed("Error: 'git_secret' is a mandatory input. Please provide a valid GitHub token.");
30+
return;
31+
}
32+
2733
switch (task) {
2834
case "monitor-issues":
2935
await monitorIssues({

action/monitor-new-issue.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ async function monitorIssues({
9090
slackIDType,
9191
slackIDs,
9292
} = slackConfig;
93+
94+
if (!slackToken) {
95+
console.log("No Slack token provided. Skipping notification.");
96+
return;
97+
}
98+
9399
console.log(
94100
"🔔 Sending notifications to Slack for issues:",
95101
issues.map((issue) => issue.title)
@@ -109,13 +115,19 @@ async function monitorIssues({
109115
discordIDType,
110116
discordIDs,
111117
} = discordConfig;
118+
119+
if (!discordWebhookUrl) {
120+
console.log("No Discord webhook URL provided. Skipping notification.");
121+
return;
122+
}
123+
112124
console.log(
113125
"🔔 Sending notifications to Discord for issues:",
114126
issues.map((issue) => issue.title)
115127
);
116128
await sendDiscordNotification(discordWebhookUrl, issues, repo, "issue", discordIDType, discordIDs);
117129
} else {
118-
throw new Error("Unsupported notifier. Use 'slack' or 'discord'.");
130+
console.log("No notifier selected. Skipping notification.");
119131
}
120132
}
121133

action/monitor-new-pr.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ async function monitorPRs({
101101
"🔔 Sending notifications to Slack for PRs:",
102102
prs.map((pr) => pr.title)
103103
);
104+
105+
if (!slackToken) {
106+
console.log("No Slack token provided. Skipping notification.");
107+
return;
108+
}
109+
104110
await sendSlackNotification(
105111
slackToken,
106112
slackChannel,
@@ -117,13 +123,18 @@ async function monitorPRs({
117123
discordIDs,
118124
} = discordConfig;
119125

126+
if (!discordWebhookUrl) {
127+
console.log("No Discord webhook URL provided. Skipping notification.");
128+
return;
129+
}
130+
120131
console.log(
121132
"🔔 Sending notifications to Discord for PRs:",
122133
prs.map((pr) => pr.title)
123134
);
124135
await sendDiscordNotification(discordWebhookUrl, prs, repo, "pr", discordIDType, discordIDs);
125136
} else {
126-
throw new Error("Unsupported notifier. Use 'slack' or 'discord'.");
137+
console.log("No notifier selected. Skipping notification.");
127138
}
128139
}
129140

dist/index.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,12 @@ async function monitorIssues({
226226
slackIDType,
227227
slackIDs,
228228
} = slackConfig;
229+
230+
if (!slackToken) {
231+
console.log("No Slack token provided. Skipping notification.");
232+
return;
233+
}
234+
229235
console.log(
230236
"🔔 Sending notifications to Slack for issues:",
231237
issues.map((issue) => issue.title)
@@ -245,13 +251,19 @@ async function monitorIssues({
245251
discordIDType,
246252
discordIDs,
247253
} = discordConfig;
254+
255+
if (!discordWebhookUrl) {
256+
console.log("No Discord webhook URL provided. Skipping notification.");
257+
return;
258+
}
259+
248260
console.log(
249261
"🔔 Sending notifications to Discord for issues:",
250262
issues.map((issue) => issue.title)
251263
);
252264
await sendDiscordNotification(discordWebhookUrl, issues, repo, "issue", discordIDType, discordIDs);
253265
} else {
254-
throw new Error("Unsupported notifier. Use 'slack' or 'discord'.");
266+
console.log("No notifier selected. Skipping notification.");
255267
}
256268
}
257269

@@ -365,6 +377,12 @@ async function monitorPRs({
365377
"🔔 Sending notifications to Slack for PRs:",
366378
prs.map((pr) => pr.title)
367379
);
380+
381+
if (!slackToken) {
382+
console.log("No Slack token provided. Skipping notification.");
383+
return;
384+
}
385+
368386
await sendSlackNotification(
369387
slackToken,
370388
slackChannel,
@@ -381,13 +399,18 @@ async function monitorPRs({
381399
discordIDs,
382400
} = discordConfig;
383401

402+
if (!discordWebhookUrl) {
403+
console.log("No Discord webhook URL provided. Skipping notification.");
404+
return;
405+
}
406+
384407
console.log(
385408
"🔔 Sending notifications to Discord for PRs:",
386409
prs.map((pr) => pr.title)
387410
);
388411
await sendDiscordNotification(discordWebhookUrl, prs, repo, "pr", discordIDType, discordIDs);
389412
} else {
390-
throw new Error("Unsupported notifier. Use 'slack' or 'discord'.");
413+
console.log("No notifier selected. Skipping notification.");
391414
}
392415
}
393416

@@ -39295,6 +39318,12 @@ async function run() {
3929539318
const discordIDType = core.getInput("discord_id_type");
3929639319
const discordIDs = core.getInput("discord_ids");
3929739320

39321+
// Check if git_secret is provided
39322+
if (!gitToken) {
39323+
core.setFailed("Error: 'git_secret' is a mandatory input. Please provide a valid GitHub token.");
39324+
return;
39325+
}
39326+
3929839327
switch (task) {
3929939328
case "monitor-issues":
3930039329
await monitorIssues({

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "repo-monitor",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "A GitHub Action to monitor a repository for new issues and PRs and send notifications to different channels.",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)