-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgithub-app.js
41 lines (34 loc) · 1.23 KB
/
github-app.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
const GOOD_FIRST_REGEX = /^good\sfirst\sissue$/i;
/**
* @param {Record<string, string>} env
* @param {import("@octokit/app").App} app
*/
export default async function githubApp(env, app) {
app.log.info('App loaded');
app.webhooks.onAny(async ({ name, payload }) => {
const eventNameWithAction = payload.action ? `${name}.${payload.action}` : name;
app.log.info(`Event received: ${eventNameWithAction}`);
});
app.webhooks.on('issues.labeled', async (context) => {
// ignore private repositories
if (context.payload.repository.private) return;
// ignore if label is not "good first issue"
const { name } = context.payload.label;
if (!GOOD_FIRST_REGEX.test(name)) return;
// send message to discord
const discordWebhookUrl = env.DISCORD_WEBHOOKS_URL;
const params = {
username: 'GFI-Catsup [beta]',
avatar_url: 'https://github.com/open-sauced/assets/blob/master/logo.png?raw=true',
content: `New good first issue: ${context.payload.issue.html_url}`,
};
// send post request using fetch to webhook
await fetch(discordWebhookUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(params),
});
});
}