This repository has been archived by the owner on May 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrelease_hook.js
81 lines (72 loc) · 2.58 KB
/
release_hook.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
73
74
75
76
77
78
79
80
81
var fs = require('fs');
var http = require('http');
var request = require('request');
var moment = require('moment-timezone');
var hook = fs.readFileSync('hook', "utf8").toString().trim();
const server = http.createServer();
server.on('request', (req, response) => {
// we should only get POSTS, so ignore everything else.
response.writeHead(200,{"Content-Type":"application/json"});
if (req.method == "POST") {
console.log("START==========================================================START")
console.log("Got a post request. Doing stuff..")
var git;
var payload;
var body = '';
req.on('data', (chunk) => {
body += chunk;
}).on('end', () => {
git = JSON.parse(body)
console.log("==========================================================")
console.log(git)
console.log("==========================================================")
if (git.action != "published") {return}
console.log(git.release.body)
body = git.release.body;
var start_reg = /[\s\S]*## Highlights/g; // match the stuff at the start
var start = body.match(start_reg)[0]; // save it
var re = /[\s\S]*END PGP SIGNATURE-*/g; // match stuff at the start with a PGP signature to strip it out.
var pgp_match = body.match(re);
if (pgp_match){
body = body.replace(re, '');
body = start + body
}
if (body.length >= 2000) {
body = body.slice(0,1900);
body = body.replace(/\n.*$/, '');
body += "\n\n - [And more...](" + git.release.html_url + ")";
}
username = "Release"
if (git.repository.name == "WeakAuras2") {username = "WeakAuras"}
if (git.repository.name == "WeakAuras-Companion") {username = "WeakAuras Companion"}
payload = {
"username": username,
"avatar_url": "https://media.forgecdn.net/avatars/62/782/636142194921799650.png",
"embeds": [{
"title": "New Release: " + git.release.tag_name,
"description": body,
"url": git.release.html_url,
"color": 1399932,
"timestamp": moment().format(),
}]
}
request({
url: hook,
method: "POST",
body: payload,
json: true
})
console.log("payload:")
console.log(payload);
response.end("I got your response.");
console.log("end ========================================================== end")
}).on('error', (e) => {
console.log("Error on request: " + e)
});
}
else {
response.end("Undefined request .");
}
});
server.listen(8000);
console.log("Server running on port 8000");