Skip to content

Commit

Permalink
style: eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Jul 31, 2023
1 parent a16cf90 commit 2654ac9
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions netlify/edge-functions/github-webhooks.js
@@ -1,70 +1,70 @@
// @ts-check

import { App } from "https://esm.sh/@octokit/app@14.0.0";
import githubApp from "../../github-app.js";
import { App } from 'https://esm.sh/@octokit/app@14.0.0';
import githubApp from '../../github-app.js';

const requiredEnvironmentVariables = [
"GITHUB_APP_ID",
"GITHUB_APP_PRIVATE_KEY",
"GITHUB_APP_CLIENT_ID",
"GITHUB_APP_CLIENT_SECRET",
"GITHUB_APP_WEBHOOK_SECRET",
"DISCORD_WEBHOOKS_URL",
'GITHUB_APP_ID',
'GITHUB_APP_PRIVATE_KEY',
'GITHUB_APP_CLIENT_ID',
'GITHUB_APP_CLIENT_SECRET',
'GITHUB_APP_WEBHOOK_SECRET',
'DISCORD_WEBHOOKS_URL',
];

const missingEnvironmentVariables = requiredEnvironmentVariables.filter((name) => !Deno.env.get(name));

Check warning on line 15 in netlify/edge-functions/github-webhooks.js

View workflow job for this annotation

GitHub Actions / Test and lint / Code standards

This line has a length of 103. Maximum allowed is 100

Check warning on line 15 in netlify/edge-functions/github-webhooks.js

View workflow job for this annotation

GitHub Actions / Test and lint / Code standards

'Deno' is not defined

if (missingEnvironmentVariables.length) {
throw new Error(`Missing environment variables: ${missingEnvironmentVariables.join(", ")}`);
throw new Error(`Missing environment variables: ${missingEnvironmentVariables.join(', ')}`);
}

const app = new App({
appId: Number(Deno.env.get("GITHUB_APP_ID")),
privateKey: Deno.env.get("GITHUB_APP_PRIVATE_KEY"),
appId: Number(Deno.env.get('GITHUB_APP_ID')),

Check warning on line 22 in netlify/edge-functions/github-webhooks.js

View workflow job for this annotation

GitHub Actions / Test and lint / Code standards

'Deno' is not defined
privateKey: Deno.env.get('GITHUB_APP_PRIVATE_KEY'),

Check warning on line 23 in netlify/edge-functions/github-webhooks.js

View workflow job for this annotation

GitHub Actions / Test and lint / Code standards

'Deno' is not defined
oauth: {
clientId: Deno.env.get("GITHUB_APP_CLIENT_ID"),
clientSecret: Deno.env.get("GITHUB_APP_CLIENT_SECRET"),
clientId: Deno.env.get('GITHUB_APP_CLIENT_ID'),

Check warning on line 25 in netlify/edge-functions/github-webhooks.js

View workflow job for this annotation

GitHub Actions / Test and lint / Code standards

'Deno' is not defined
clientSecret: Deno.env.get('GITHUB_APP_CLIENT_SECRET'),

Check warning on line 26 in netlify/edge-functions/github-webhooks.js

View workflow job for this annotation

GitHub Actions / Test and lint / Code standards

'Deno' is not defined
},
webhooks: {
secret: Deno.env.get("GITHUB_APP_WEBHOOK_SECRET"),
secret: Deno.env.get('GITHUB_APP_WEBHOOK_SECRET'),

Check warning on line 29 in netlify/edge-functions/github-webhooks.js

View workflow job for this annotation

GitHub Actions / Test and lint / Code standards

'Deno' is not defined
},
log: console,
});

githubApp(Deno.env.toObject(), app);

Check warning on line 34 in netlify/edge-functions/github-webhooks.js

View workflow job for this annotation

GitHub Actions / Test and lint / Code standards

'Deno' is not defined

export const config = {
path: "/api/github/webhooks",
path: '/api/github/webhooks',
};

/**
* @param {Request} request
*/
export default async (request) => {
if (request.method !== "POST") {
if (request.method !== 'POST') {
app.log.warn(`Method ${request.method} not allowed`);
return new Response("Not found", { status: 404 });
return new Response('Not found', { status: 404 });
}

const event = {
id: request.headers.get("x-github-delivery"),
name: request.headers.get("x-github-event"),
signature: request.headers.get("x-hub-signature-256"),
id: request.headers.get('x-github-delivery'),
name: request.headers.get('x-github-event'),
signature: request.headers.get('x-hub-signature-256'),
payload: await request.text(),
};

try {
await app.webhooks.verifyAndReceive(event);

return new Response('{ "ok": true }', {
headers: { "content-type": "application/json" },
headers: { 'content-type': 'application/json' },
});
} catch (error) {
app.log.error(error);

return new Response(`{ "error": "${error.message}" }`, {
status: 500,
headers: { "content-type": "application/json" },
headers: { 'content-type': 'application/json' },
});
}
};

0 comments on commit 2654ac9

Please sign in to comment.