-
Notifications
You must be signed in to change notification settings - Fork 1
/
mu2ch-webhook.js
128 lines (96 loc) · 3.54 KB
/
mu2ch-webhook.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
var http = require('http')
var createHandler = require('github-webhook-handler')
var handler = createHandler({ path: '/webhook', secret: 'myhashsecret' })
http.createServer(function (req, res) {
handler(req, res, function (err) {
res.statusCode = 404
res.end('no such location')
})
}).listen(7777)
function send_notification(message) {
var st = new ltx.Element(
'message',
{ to: "mu2ch@conference.jabber.ru", type: 'groupchat' }
).c('body').t(message)
client.send(st)
}
handler.on('error', function (err) {
console.error('Error:', err.message)
})
handler.on('issue_comment', function (event) {
issue = event.payload['issue']
comment = event.payload['comment']
sender = event.payload['sender']['login']
send_notification("[issues] " + sender + " comment " + "issue: #" + issue['number'] + " " + issue['title'] + " " + comment['html_url'] + "\r\n" + issue['body'])
})
handler.on('issues', function (event) {
issue = event.payload['issue']
if (event.payload['action'] == 'opened') {
send_notification("[issues] " + event.payload['sender']['login']+ " " + event.payload['action'] + " # " + issue['number'] + " " + issue['title'] + " " + issue['html_url'] + "\r\n " + issue['body']) } else {
send_notification("[issues] " + event.payload['sender']['login']+ " " + event.payload['action'] + " # " + issue['number'] + " " + issue['title'] + " " + issue['html_url'] + "\r\n ")
}
})
handler.on('gollum', function (event) {
console.log('gollum ' + JSON.stringify(event.payload['sender']));
sender = event.payload['sender']['login']
page = event.payload['pages'][0]
send_notification("[wiki] " + sender + " " + page['action'] + " " + page['title'] + " " + page['html_url'])
})
handler.on('push', function (event) {
head_commit = event.payload['head_commit']
send_notification("[push] " + event.payload['pusher']['name'] + " " + event.payload['commits'].length + " commit(s)" + " " + head_commit['message'] + " " + event.payload['compare'])
})
handler.on('commit', function (event) {
head_commit = event.payload['head_commit']
commits_count = len(event.payload.commits)
send_notification("[commit] " + head_commit['author']['name'] + " " + head_commit['message'] + " " + head_commit["url"])
})
var Client = require('node-xmpp-client')
, argv = process.argv
, ltx = require('ltx')
var client = new Client({
jid: '',
password: '',
host:'',
reconnect: true
})
process.argv.forEach(function(val, index, array) {
console.log(index + ': ' + val);
});
var x = 0, old = x, average = 0
setInterval(function () {
var n = x - old
// console.log(n, average)
average = (n + average) * 0.5
old = x
}, 1e3)
var c = 0
client.on('stanza', function(stanza) {
console.log('Received stanza: ', c++, stanza.toString())
})
client.on('online', function() {
console.log('Client is online')
client.send('<presence/>')
var presence = new ltx.Element('presence',
{ to: "mu2ch@conference.jabber.ru/github-bot" }).c('x', { xmlns: 'http://jabber.org/protocol/muc' })
client.send(presence)
})
client.on('offline', function () {
console.log('Client is offline')
})
client.on('connect', function () {
console.log('Client is connected')
})
client.on('reconnect', function () {
console.log('Client reconnects …')
})
client.on('disconnect', function (e) {
console.log('Client is disconnected', client.connection.reconnect, e)
})
client.on('error', function(e) {
console.error(e)
process.exit(1)
})
process.on('exit', function () {
client.end()
})