asjon/scripts/github.coffee

49 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-26 20:41:44 +02:00
if process.env.AUTO_INFORM_ON_START
r = room: process.env.AUTO_INFORM_ON_START.replace(':','#')
robot.send r, 'asjon avviato e operativo!'
2015-04-26 20:34:44 +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 15:26:59 +02:00
dest = name: req.params.name, room: req.params.room.replace(':','#')
robot.emit 'githubhook', req.body, req.params
2015-04-26 20:22:49 +02:00
s = 'Branch '+req.body.ref+' aggiornato!\n'
cm = req.body.commits.map (c) ->
[c.committer.username,c.message].join ' -> '
robot.send dest, s+cm.join('\n')
robot.respond /(?:(?:mostra(?:mi)?|fammi vedere) )?(?:le )?issue(?:s)?/i, (res) ->
2015-04-25 18:26:24 +02:00
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
2015-04-29 15:18:03 +02:00
if data.length is 0 then return res.send '0 issues'
2015-04-25 18:26:24 +02:00
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'
2015-04-25 18:37:13 +02:00
robot.respond /linkami (?:la )?issue (?:(?:n(?:°)?(?: )?)|numero )?(\d+)/i, (res) ->
base = 'http://github.com/fazo96/asjon/issues/'
res.send base+res.match[1]
robot.respond /linkami (?:la )?repo (\w+\/\w+)/i, (res) ->
res.send 'https://github.com/'+res.match[1]