2015-04-25 14:24:13 +02:00
|
|
|
# Description:
|
2018-06-08 08:57:39 +02:00
|
|
|
# interazioni tra asjon e git
|
2015-04-25 18:26:24 +02:00
|
|
|
#
|
2018-06-08 08:57:39 +02:00
|
|
|
# Dependencies:
|
|
|
|
# None
|
2015-04-25 18:26:24 +02:00
|
|
|
#
|
2018-06-08 08:57:39 +02:00
|
|
|
# Configuration:
|
2018-06-12 01:50:40 +02:00
|
|
|
# HUBOT_GIT_URL - git server url
|
|
|
|
# HUBOT_GIT_API - git server API url
|
2018-06-08 08:57:39 +02:00
|
|
|
# HUBOT_GIT_TOKEN - Gogs v1 or GitHub v3 API token
|
|
|
|
# HUBOT_GIT_REPO - repository name (owner/repo)
|
|
|
|
#
|
2015-04-25 18:26:24 +02:00
|
|
|
# Commands:
|
2017-02-27 15:35:53 +01:00
|
|
|
# asjon mostra le issue - mostra le issue aperte su rnhmjoj/asjon
|
2015-04-25 18:26:24 +02:00
|
|
|
#
|
|
|
|
# Author:
|
|
|
|
# Enrico Fasoli (fazo96)
|
2017-02-27 15:35:53 +01:00
|
|
|
# Michele Guerini Rocco (rnhmjoj)
|
2015-04-25 18:26:24 +02:00
|
|
|
|
2015-04-25 14:24:13 +02:00
|
|
|
module.exports = (robot) ->
|
2018-06-08 08:57:39 +02:00
|
|
|
githook = (req, res) ->
|
2015-04-25 14:39:57 +02:00
|
|
|
res.send 200
|
2017-02-27 15:35:53 +01:00
|
|
|
dest = name: req.params.name, room: id: req.params.room
|
2018-06-08 08:57:39 +02:00
|
|
|
robot.emit 'githook', req.body, req.params
|
2017-02-27 15:35:53 +01:00
|
|
|
s = "branch #{req.body.ref} aggiornato!\n"
|
2015-04-26 20:22:49 +02:00
|
|
|
cm = req.body.commits.map (c) ->
|
2017-02-27 15:35:53 +01:00
|
|
|
[c.committer.username, c.message].join ' -> '
|
|
|
|
robot.send dest, s + cm.join '\n'
|
2015-04-29 16:02:46 +02:00
|
|
|
|
2015-04-29 15:35:16 +02:00
|
|
|
unless process.env.TESTING_ASJON
|
|
|
|
# Disabilito http route durante i test
|
2018-06-08 08:57:39 +02:00
|
|
|
robot.router.post '/hubot/githook/:room/:name?', githook
|
2015-04-26 20:22:49 +02:00
|
|
|
|
|
|
|
robot.respond /(?:(?:mostra(?:mi)?|fammi vedere) )?(?:le )?issue(?:s)?/i, (res) ->
|
2017-02-27 15:35:53 +01:00
|
|
|
msg = state: 'open', user: 'rnhmjoj', repo: 'asjon', sort: 'updated'
|
2015-04-25 18:26:24 +02:00
|
|
|
res.send 'controllo issues...'
|
2018-06-12 01:50:40 +02:00
|
|
|
url = process.env.HUBOT_GIT_API
|
2018-06-08 08:57:39 +02:00
|
|
|
repo = process.env.HUBOT_GIT_REPO
|
|
|
|
token = process.env.HUBOT_GIT_TOKEN
|
|
|
|
|
|
|
|
if not token
|
|
|
|
return res.send 'non ho il token per la repo'
|
|
|
|
|
|
|
|
robot.http("#{url}/repos/#{repo}/issues?state=open&sort=updated")
|
|
|
|
.header('Authorization', 'token '+token)
|
|
|
|
.get() (err, r, body) ->
|
2015-04-25 18:26:24 +02:00
|
|
|
if err then return res.send err
|
2018-06-08 08:57:39 +02:00
|
|
|
data = JSON.parse body
|
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) ->
|
2018-06-08 08:57:39 +02:00
|
|
|
url = process.env.HUBOT_GIT_URL
|
|
|
|
repo = process.env.HUBOT_GIT_REPO
|
|
|
|
base = "#{url}/#{repo}/issues/"
|
2015-04-25 18:37:13 +02:00
|
|
|
res.send base+res.match[1]
|
|
|
|
|
2015-04-26 20:27:26 +02:00
|
|
|
robot.respond /linkami (?:la )?repo (\w+\/\w+)/i, (res) ->
|
2018-06-12 01:50:40 +02:00
|
|
|
url = process.env.HUBOT_GIT_URL
|
2018-06-08 08:57:39 +02:00
|
|
|
res.send "#{url}/#{res.match[1]}/"
|
2015-04-26 20:27:26 +02:00
|
|
|
|
2018-06-08 08:57:39 +02:00
|
|
|
# rendo l'handler dell'hook di git accessibile
|
2015-04-29 15:35:16 +02:00
|
|
|
# in caso serve (nei test)
|
2018-06-08 08:57:39 +02:00
|
|
|
return githook
|
2015-04-29 15:35:16 +02:00
|
|
|
|