asjon/scripts/github.coffee

48 lines
1.7 KiB
CoffeeScript
Raw Normal View History

# Description:
# interazioni tra asjon e github
2015-04-25 18:26:24 +02:00
#
# Requires:
# "github": "0.2.4"
#
# Commands:
# asjon mostra le issue - mostra le issue aperte su fazo96/asjon
#
# Author:
# Enrico Fasoli (fazo96)
GitHubAPI = require 'github'
github = new GitHubAPI version: '3.0.0'
module.exports = (robot) ->
2015-04-25 15:21:57 +02:00
robot.router.post '/hubot/githubhook/:room/:name', (req, res) ->
2015-04-25 14:39:57 +02:00
res.send 200
2015-04-25 14:58:20 +02:00
if !process.env.GITHUB_API_SECRET
console.log 'non sono configurato per GITHUB API WEBHOOKS!'
return
2015-04-25 15:21:57 +02:00
else if "sha1="+process.env.GITHUB_API_SECRET isnt req.headers["x-hub-signature"]
2015-04-25 14:58:20 +02:00
console.log 'MALFORMED GITHUB API SECRET: was',
2015-04-25 15:21:57 +02:00
req.headers["x-hub-signature"], 'but expected', "sha1="+process.env.GITHUB_API_SECRET
2015-04-25 14:58:20 +02:00
return
2015-04-25 15:26:59 +02:00
dest = name: req.params.name, room: req.params.room.replace(':','#')
2015-04-25 15:24:46 +02:00
if req.body.ref is 'refs/heads/master'
2015-04-25 14:39:57 +02:00
s = 'Sono stato aggiornato!\n'
cm = req.body.commits.map (c) ->
[c.committer.username,c.message].join ' -> '
commits = cm.join '\n'
2015-04-25 15:21:57 +02:00
robot.send dest, s+commits
2015-04-25 18:26:24 +02:00
if process.env.AUTO_KILL_ON_UPDATE
setTimeout 1000, ->
console.log 'DYING NOW AS REQUESTED!'
process.exit 0
robot.respond /(?:(?:mostra(?:mi)?|fammi vedere) )(?:le )?issue(?:s)?/i, (res) ->
msg = state: 'open', user: 'fazo96', repo: 'asjon', sort: 'updated'
res.send 'controllo issues...'
github.issues.repoIssues msg, (err,data) ->
if err then return res.send err
r = data.map (i) ->
labels = i.labels.map((x) -> x.name).join ', '
if labels is '' then labels = 'nessuno'
["#"+i.number,i.title,"By: "+i.user.login,'Tags: '+labels].join(' | ')
res.send r.join '\n'