forked from issc29/github-webhook-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·65 lines (55 loc) · 1.65 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
54
55
56
57
58
59
60
61
62
63
64
65
'use strict';
const querystring = require('querystring');
var request = require('request');
const yaml = require('js-yaml');
const fs = require('fs');
exports.handler = (event, context, callback) => {
var status = {}
//var a = JSON.parse(event.headers)
//console.log(event.headers["X-GitHub-Event"]);
//console.log(event)
//console.log(event)
const params = querystring.parse(event.body);
const jsonBody = JSON.parse(params["payload"])
const repo_name = jsonBody["repository"]["full_name"]
// Get document, or throw exception on error
var doc
try {
var configPath = os.environ['LAMBDA_TASK_ROOT'] + "/mappings.yaml"
doc = yaml.safeLoad(fs.readFileSync(configPath));
console.log(doc);
} catch (e) {
console.log(e);
}
console.log(doc["repositories"])
if(repo_name == "issc29-GHfB/test") {
var endpoint = "https://requestb.in/rmttt7rm"
var headers = {
'content-type': event.headers["content-type"],
'X-GitHub-Delivery': event.headers["X-GitHub-Delivery"],
'X-GitHub-Event': event.headers["X-GitHub-Event"]
}
var options = {
url: endpoint,
method: 'POST',
timeout: 1500,
headers: headers,
body: event.body
}
request(options, function (error, response, body) {
if(error) {
console.log(error)
callback(null, error)
}
else {
status = {
"statusCode": response.statusCode,
"headers": response.headers,
"body": response.body
}
console.log(status)
callback(null, response.statusCode);
}
})
}
};