-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
53 lines (45 loc) · 1.43 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const express = require('express');
const { newClient } = require('./client');
const { isDetaRuntime, verifySignature } = require('./util');
const { EventHandler } = require('./event-handler');
// configuration
const config = {
// size of fix cache cache
cacheSize: parseInt(process.env.CACHE_SIZE),
// size of commit history in days to check on installation
historySize: parseInt(process.env.HISTORY_SIZE),
// name of branch to track fix merges on
trackedBranch: process.env.TRACKED_BRANCH,
// keywords for fix commit messages
fixKeywords: process.env.FIX_KEY_WORDS.split(','),
// paths to skip in the cache
skipPaths: process.env.SKIP_PATHS.split(','),
};
// express app
const app = express();
// webhook events handler
const eventHandler = new EventHandler(config);
// middlewares
app.use(express.json()); // parse body as application/json
app.use(verifySignature); // verify signature with webhook secret
// webhook main handler
app.post('/', async (req, res) => {
try{
await eventHandler.handleEvent(req);
} catch (err){
console.error(err);
return res.status(500).send('internal server error');
}
return res.send('ok');
});
// marketplace handler
app.post('/marketplace', (req, res) => {
return res.send('ok');
});
if (isDetaRuntime()){
module.exports = app;
} else {
app.listen(9000, () => {
console.log('Local server, listening at port:9000')
});
}