fix github webhook response

This commit is contained in:
Enrico Fasoli 2015-04-26 20:22:49 +02:00
parent 7409f6ff5e
commit ae7d15a86d

View File

@ -16,26 +16,19 @@ github = new GitHubAPI version: '3.0.0'
module.exports = (robot) -> module.exports = (robot) ->
robot.router.post '/hubot/githubhook/:room/:name', (req, res) -> robot.router.post '/hubot/githubhook/:room/:name', (req, res) ->
res.send 200 res.send 200
if !process.env.GITHUB_API_SECRET
console.log 'non sono configurato per GITHUB API WEBHOOKS!'
return
else if "sha1="+process.env.GITHUB_API_SECRET isnt req.headers["x-hub-signature"]
console.log 'MALFORMED GITHUB API SECRET: was',
req.headers["x-hub-signature"], 'but expected', "sha1="+process.env.GITHUB_API_SECRET
return
dest = name: req.params.name, room: req.params.room.replace(':','#') dest = name: req.params.name, room: req.params.room.replace(':','#')
if req.body.ref is 'refs/heads/master' s = 'Branch '+req.body.ref+' aggiornato!\n'
s = 'Sono stato aggiornato!\n' cm = req.body.commits.map (c) ->
cm = req.body.commits.map (c) -> [c.committer.username,c.message].join ' -> '
[c.committer.username,c.message].join ' -> ' robot.send dest, s+cm.join('\n')
commits = cm.join '\n'
robot.send dest, s+commits
if process.env.AUTO_KILL_ON_UPDATE if process.env.AUTO_KILL_ON_UPDATE
setTimeout 1000, -> robot.send dest, 'riavvio in 5 SECONDI'
setTimeout 5000, ->
console.log 'DYING NOW AS REQUESTED!' console.log 'DYING NOW AS REQUESTED!'
process.exit 0 process.exit 0
robot.respond /(?:(?:mostra(?:mi)?|fammi vedere) )(?:le )?issue(?:s)?/i, (res) -> robot.respond /(?:(?:mostra(?:mi)?|fammi vedere) )?(?:le )?issue(?:s)?/i, (res) ->
msg = state: 'open', user: 'fazo96', repo: 'asjon', sort: 'updated' msg = state: 'open', user: 'fazo96', repo: 'asjon', sort: 'updated'
res.send 'controllo issues...' res.send 'controllo issues...'
github.issues.repoIssues msg, (err,data) -> github.issues.repoIssues msg, (err,data) ->