-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.js
More file actions
48 lines (42 loc) · 1.42 KB
/
github.js
File metadata and controls
48 lines (42 loc) · 1.42 KB
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
var path = require('path')
, colors = require('irc-colors')
, api = require('zenircbot-api')
, zen = new api.ZenIRCBot()
, sub = zen.get_redis_client()
, github_config = api.load_config(path.join(__dirname, 'github.json'))
zen.register_commands(path.basename(__filename), [])
sub.subscribe('web_in')
sub.on('message', function(channel, message){
message = JSON.parse(message)
if (message.app !== 'github') {
return null
}
var data = JSON.parse(message.body.payload)
, branch = data.ref.substr(11)
, repo = data.repository.name
, full_repo = data.repository.owner.name + '/' + repo
, name_str = ''
, channels = []
Object.keys(github_config.patterns).forEach(function(pattern) {
var regex = new RegExp(pattern)
if (regex.test(full_repo)) {
channels += github_config.patterns[pattern]
}
})
channels = channels || github_config.default_channel
data.commits.forEach(function(commit) {
if (commit.author.username) {
name_str = (' - ' + commit.author.username +
' (' + commit.author.name + ')')
} else if (commit.author.name) {
name_str = ' - ' + commit.author.name
} else {
name_str = ''
}
message = (full_repo + ': ' + commit.id.substr(0,7) + ' *' +
colors.green(branch) + '* ' +
commit.message + name_str)
zen.send_privmsg(channels, message)
console.log(channels + ' -> ' + message)
})
})