Skip to content

Commit 1fcc249

Browse files
fix: add probot auth for reminders (#37)
1 parent 59bdffd commit 1fcc249

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/remind.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,23 @@ type TeamMember = { login: string };
99

1010
if (!SLACK_BOT_TOKEN && NODE_ENV !== 'test') {
1111
console.error('Missing environment variable SLACK_BOT_TOKEN');
12-
process.exit(1);
1312
}
1413

1514
const slack = new WebClient(SLACK_BOT_TOKEN);
1615

17-
const octokit = new ProbotOctokit();
16+
let auth: any;
17+
if (process.env.APP_ID && process.env.PRIVATE_KEY) {
18+
auth = {
19+
appId: process.env.APP_ID,
20+
privateKey: process.env.PRIVATE_KEY,
21+
};
22+
} else if (process.env.GITHUB_TOKEN) {
23+
auth = { token: process.env.GITHUB_TOKEN };
24+
} else {
25+
console.warn('Missing GitHub auth credentials, using unauthenticated requests.');
26+
}
27+
28+
const octokit = new ProbotOctokit({ auth });
1829

1930
function getOwnerAndRepoFromUrl(url: string) {
2031
const urlObj = new URL(url);
@@ -211,18 +222,24 @@ async function main() {
211222
}
212223

213224
if (!reminders.length) {
225+
console.info('No PRs found needing reminders :)');
214226
return;
215227
}
216228

217229
const text = `:blob-wave: *Reminder:* the following PRs are awaiting review.\n\n${reminders.join(
218230
'\n\n',
219231
)}`;
220232

221-
slack.chat.postMessage({
222-
channel: '#wg-api',
223-
unfurl_links: false,
224-
text,
225-
});
233+
if (SLACK_BOT_TOKEN) {
234+
slack.chat.postMessage({
235+
channel: '#wg-api',
236+
unfurl_links: false,
237+
text,
238+
});
239+
} else {
240+
// Log for testing without slack auth
241+
console.log(text);
242+
}
226243
}
227244

228245
if (require.main === module) main();

0 commit comments

Comments
 (0)