-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (31 loc) · 1.03 KB
/
index.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
const { App, createNodeMiddleware } = require("octokit");
require("dotenv").config();
const SmeeClient = require("smee-client");
const scanner = require("./scanner");
// instantiate Github App
const app = new App({
appId: process.env.APP_ID,
privateKey: process.env.PRIVATE_KEY,
oauth: {
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
},
webhooks: { secret: process.env.WEBHOOK_SECRET },
});
app.webhooks.onAny(async ({ id, name, payload }) => {
const octokit = await app.getInstallationOctokit(payload.installation.id);
scanner(id, name, octokit, payload);
});
// create local server to receive webhooks
require("http")
.createServer(createNodeMiddleware(app))
.listen(process.env.PORT, () =>
console.info(`App listening on PORT:${process.env.PORT}`)
);
//connect local server to network client in development
const smee = new SmeeClient({
source: "https://smee.io/project-badging",
target: `http://localhost:${process.env.PORT}/api/github/webhooks`,
logger: console,
});
smee.start();