From caf104e2d8a038bf9c6aba750cd5a8510d041bf4 Mon Sep 17 00:00:00 2001 From: Gregor Martynus <39992+gr2m@users.noreply.github.com> Date: Wed, 16 Aug 2023 13:49:36 -0700 Subject: [PATCH] fix: ignore private repositories --- github-app.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/github-app.js b/github-app.js index 221846a..45ea163 100644 --- a/github-app.js +++ b/github-app.js @@ -5,7 +5,7 @@ const GOOD_FIRST_REGEX = /^good\sfirst\sissue$/i; * @param {import("@octokit/app").App} app */ export default async function githubApp(env, app) { - app.log.info('App loaded'); + app.log.info("App loaded"); app.webhooks.onAny(async ({ name, payload }) => { const eventNameWithAction = payload.action ? `${name}.${payload.action}` : name; @@ -13,24 +13,27 @@ export default async function githubApp(env, app) { app.log.info(`Event received: ${eventNameWithAction}`); }); - app.webhooks.on('issues.labeled', async (context) => { - const { name } = context.payload.label; + 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', + 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', + method: "POST", headers: { - 'Content-Type': 'application/json', + "Content-Type": "application/json", }, body: JSON.stringify(params), });