-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
33 lines (24 loc) · 979 Bytes
/
index.js
File metadata and controls
33 lines (24 loc) · 979 Bytes
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
const express = require('express');
const cors = require('cors');
const bodyparser = require('body-parser');
const app = express();
const port = process.env.PORT | 8558;
const records = require('./assets/record.json');
app.use(cors());
app.use(bodyparser.urlencoded({
extended: true
}));
app.post('/ghwebhooks', (req,res) => {
const payload = JSON.parse(req.body.payload);
const branch = payload.ref.split('/').pop();
const repoName = payload.repository.full_name;
if (records[repoName].branch === branch) {
const { deploy } = require(`./assets/scripts/${records[repoName].script}`);
deploy(records[repoName].dir,repoName,branch);
return res.send('Git pull started. Please go through look services logs for more detail');
} else {
res.statusCode = 401;
return res.send('No record found for the repo');
}
});
app.listen(port,() => console.log(`Github Webhook Hanlder Service running on ${port}`));