This repository has been archived by the owner on Jan 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCI.js
72 lines (61 loc) · 1.85 KB
/
CI.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
66
67
68
69
70
71
72
var http = require('http');
var greq = require('./hook/git_request');
var db = require('./db_actions');
var git = require('./hook/git_actions');
require('./logger');
// VM builder
require('./builder/virtual.js');
// task manager
require('./tasker/taskman');
function getPost(request, response, callback) {
var queryData = "";
if (typeof callback !== 'function') return null;
if (request.method == 'POST') {
request.on('data', function (data) {
queryData += data;
if (queryData.length > 1e6) {
queryData = "";
response.writeHead(413, {'Content-Type': 'text/plain'}).end();
request.connection.destroy();
}
});
request.on('end', function () {
try {
request.post = JSON.parse(queryData);
callback();
} catch (e) {
// TODO log bad request
response.writeHead(200, "OK", {'Content-Type': 'text/plain'});
response.end();
}
});
} else {
response.writeHead(405, {'Content-Type': 'text/plain'});
response.end();
}
}
db.getGithubUser(function (data) {
if (!data || !data.username) {
throw new Error("Github user data or data.username is undefined or null");
}
git.setLogin(data.username, data.password);
http.createServer(function (request, response) {
if (request.method == 'POST') {
getPost(request, response, function () {
try {
greq.OnRequest(request, response);
} catch (e) {
// TODO log the things went bad
logme("Error On Request: ", e, "red");
}
response.writeHead(200, "OK", {'Content-Type': 'text/plain'});
response.end();
});
} else {
// TODO locate webUI here
response.writeHead(200, "OK", {'Content-Type': 'text/plain'});
response.end();
}
}).listen(8080);
logme("Github WebHook Server Started on 8080", "green");
});