github -> gogs
This commit is contained in:
parent
2210914740
commit
ec09b5f00b
@ -9,9 +9,8 @@
|
||||
"chai": "^2.3.0",
|
||||
"cheerio": "^0.19.0",
|
||||
"coffee-coverage": "^0.4.6",
|
||||
"coffee-script": "^1.9.2",
|
||||
"coffeescript": "^1.9.2",
|
||||
"fast-levenshtein": "^1.0.6",
|
||||
"github": "^0.2.4",
|
||||
"hubot": "^2.12.0",
|
||||
"hubot-bitcoin": "^1.0.3",
|
||||
"hubot-diagnostics": "0.0.1",
|
||||
@ -26,7 +25,7 @@
|
||||
"hubot-rules": "^0.1.0",
|
||||
"hubot-scripts": "^2.5.16",
|
||||
"hubot-shipit": "^0.2.0",
|
||||
"hubot-matrix": "rnhmjoj/hubot-matrix",
|
||||
"hubot-matrix": "git+https://maxwell.ydns.eu/git/rnhmjoj/hubot-matrix.git",
|
||||
"hubot-youtube": "^0.1.2",
|
||||
"mocha": "^3.2.0",
|
||||
"moment": "^2.10.2",
|
||||
|
@ -1,9 +1,14 @@
|
||||
# Description:
|
||||
# interazioni tra asjon e github
|
||||
# interazioni tra asjon e git
|
||||
#
|
||||
# Requires:
|
||||
# "github": "0.2.4"
|
||||
# Dependencies:
|
||||
# None
|
||||
#
|
||||
# Configuration:
|
||||
# HUBOT_GIT_URL - git server API base url
|
||||
# HUBOT_GIT_TOKEN - Gogs v1 or GitHub v3 API token
|
||||
# HUBOT_GIT_REPO - repository name (owner/repo)
|
||||
#
|
||||
# Commands:
|
||||
# asjon mostra le issue - mostra le issue aperte su rnhmjoj/asjon
|
||||
#
|
||||
@ -11,14 +16,11 @@
|
||||
# Enrico Fasoli (fazo96)
|
||||
# Michele Guerini Rocco (rnhmjoj)
|
||||
|
||||
GitHubAPI = require 'github'
|
||||
github = new GitHubAPI version: '3.0.0'
|
||||
|
||||
module.exports = (robot) ->
|
||||
githubhook = (req, res) ->
|
||||
githook = (req, res) ->
|
||||
res.send 200
|
||||
dest = name: req.params.name, room: id: req.params.room
|
||||
robot.emit 'githubhook', req.body, req.params
|
||||
robot.emit 'githook', req.body, req.params
|
||||
s = "branch #{req.body.ref} aggiornato!\n"
|
||||
cm = req.body.commits.map (c) ->
|
||||
[c.committer.username, c.message].join ' -> '
|
||||
@ -26,13 +28,23 @@ module.exports = (robot) ->
|
||||
|
||||
unless process.env.TESTING_ASJON
|
||||
# Disabilito http route durante i test
|
||||
robot.router.post '/hubot/githubhook/:room/:name?', githubhook
|
||||
robot.router.post '/hubot/githook/:room/:name?', githook
|
||||
|
||||
robot.respond /(?:(?:mostra(?:mi)?|fammi vedere) )?(?:le )?issue(?:s)?/i, (res) ->
|
||||
msg = state: 'open', user: 'rnhmjoj', repo: 'asjon', sort: 'updated'
|
||||
res.send 'controllo issues...'
|
||||
github.issues.repoIssues msg, (err,data) ->
|
||||
url = process.env.HUBOT_GIT_URL
|
||||
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) ->
|
||||
if err then return res.send err
|
||||
data = JSON.parse body
|
||||
if data.length is 0 then return res.send '0 issues'
|
||||
r = data.map (i) ->
|
||||
labels = i.labels.map((x) -> x.name).join ', '
|
||||
@ -41,13 +53,15 @@ module.exports = (robot) ->
|
||||
res.send r.join '\n'
|
||||
|
||||
robot.respond /linkami (?:la )?issue (?:(?:n(?:°)?(?: )?)|numero )?(\d+)/i, (res) ->
|
||||
base = 'http://github.com/rnhmjoj/asjon/issues/'
|
||||
url = process.env.HUBOT_GIT_URL
|
||||
repo = process.env.HUBOT_GIT_REPO
|
||||
base = "#{url}/#{repo}/issues/"
|
||||
res.send base+res.match[1]
|
||||
|
||||
robot.respond /linkami (?:la )?repo (\w+\/\w+)/i, (res) ->
|
||||
res.send 'https://github.com/'+res.match[1]
|
||||
res.send "#{url}/#{res.match[1]}/"
|
||||
|
||||
# rendo l'handler dell'hook di github accessibile
|
||||
# rendo l'handler dell'hook di git accessibile
|
||||
# in caso serve (nei test)
|
||||
return githubhook
|
||||
return githook
|
||||
|
@ -85,7 +85,7 @@ module.exports = (robot) ->
|
||||
runCmd ssh, res, ->
|
||||
res.send "connessione chiusa. reverse shell terminata"
|
||||
|
||||
robot.on 'githubhook', (data,params) ->
|
||||
robot.on 'githook', (data,params) ->
|
||||
if data.ref is 'refs/heads/master' and process.env.AUTO_KILL_ON_UPDATE
|
||||
dest = name: params.name, room: params.room
|
||||
res = send: (x) -> robot.send dest, x
|
||||
|
@ -929,7 +929,7 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"filename": "scripts/github.coffee",
|
||||
"filename": "scripts/git.coffee",
|
||||
"coverage": 10.344827586206897,
|
||||
"hits": 3,
|
||||
"misses": 26,
|
||||
@ -1016,7 +1016,7 @@
|
||||
"coverage": ""
|
||||
},
|
||||
"21": {
|
||||
"source": " robot.router.post '/hubot/githubhook/:room/:name?', (req, res) ->",
|
||||
"source": " robot.router.post '/hubot/githook/:room/:name?', (req, res) ->",
|
||||
"coverage": 0
|
||||
},
|
||||
"22": {
|
||||
@ -1028,7 +1028,7 @@
|
||||
"coverage": 0
|
||||
},
|
||||
"24": {
|
||||
"source": " robot.emit 'githubhook', req.body, req.params",
|
||||
"source": " robot.emit 'githook', req.body, req.params",
|
||||
"coverage": 0
|
||||
},
|
||||
"25": {
|
||||
@ -2541,7 +2541,7 @@
|
||||
"coverage": ""
|
||||
},
|
||||
"60": {
|
||||
"source": " robot.on 'githubhook', (data,params) ->",
|
||||
"source": " robot.on 'githook', (data,params) ->",
|
||||
"coverage": 1
|
||||
},
|
||||
"61": {
|
||||
|
@ -3,17 +3,20 @@ expect = require("chai").should()
|
||||
|
||||
Asjon = require './asjon-testing.coffee'
|
||||
asjon = undefined
|
||||
githubhook = undefined
|
||||
githook = undefined
|
||||
|
||||
describe 'modulo github', ->
|
||||
describe 'modulo git', ->
|
||||
before (done) ->
|
||||
# Inizializzo robot
|
||||
Asjon (assa) ->
|
||||
asjon = assa
|
||||
after asjon.after
|
||||
afterEach asjon.clear
|
||||
githubhook = require('../scripts/github.coffee')(asjon.robot)
|
||||
githook = require('../scripts/git.coffee')(asjon.robot)
|
||||
done()
|
||||
process.env.HUBOT_GIT_URL = 'https://git.example.com'
|
||||
process.env.HUBOT_GIT_REPO = 'owner/asjon'
|
||||
process.env.HUBOT_GIT_TOKEN = 'secret'
|
||||
|
||||
it 'dovrebbe rispondere a "mostra le issues"', (done) ->
|
||||
questions = [
|
||||
@ -23,8 +26,8 @@ describe 'modulo github', ->
|
||||
"asjon le issue"
|
||||
"asjon issue"
|
||||
]
|
||||
nock('https://api.github.com')
|
||||
.get('/repos/fazo96/asjon/issues?state=open&sort=updated')
|
||||
nock('https://git.example.com')
|
||||
.get('/repos/owner/asjon/issues?state=open&sort=updated')
|
||||
.times(questions.length)
|
||||
.reply 200, []
|
||||
acc = 0
|
||||
@ -34,8 +37,8 @@ describe 'modulo github', ->
|
||||
questions.map (q) -> asjon.send q
|
||||
|
||||
it 'dovrebbe rispondere correttamente in caso di 0 issues', (done) ->
|
||||
nock('https://api.github.com')
|
||||
.get('/repos/rnhmjoj/asjon/issues?state=open&sort=updated')
|
||||
nock('https://git.example.com')
|
||||
.get('/repos/owner/asjon/issues?state=open&sort=updated')
|
||||
.reply 200, []
|
||||
acc = 0
|
||||
asjon.receive (e,l) ->
|
||||
@ -62,8 +65,8 @@ describe 'modulo github', ->
|
||||
login: 'user'
|
||||
|
||||
it 'dovrebbe rispondere correttamente in caso di 1 o più issues', (done) ->
|
||||
nock('https://api.github.com')
|
||||
.get('/repos/rnhmjoj/asjon/issues?state=open&sort=updated')
|
||||
nock('https://git.example.com')
|
||||
.get('/repos/owner/asjon/issues?state=open&sort=updated')
|
||||
.reply 200, [issue1, issue2]
|
||||
acc = 0
|
||||
asjon.receive (e,l) ->
|
||||
@ -81,16 +84,16 @@ describe 'modulo github', ->
|
||||
acc = 0
|
||||
asjon.receive (e,l) ->
|
||||
if acc is 0
|
||||
l.join().should.equal 'http://github.com/rnhmjoj/asjon/issues/5'
|
||||
l.join().should.equal 'https://git.example.com/owner/asjon/issues/5'
|
||||
else
|
||||
l.join().should.equal 'http://github.com/rnhmjoj/asjon/issues/456'
|
||||
l.join().should.equal 'https://git.example.com/owner/asjon/issues/456'
|
||||
acc++
|
||||
if acc is 2 then done()
|
||||
asjon.send 'asjon linkami la issue numero 5'
|
||||
asjon.send 'asjon linkami issue 456'
|
||||
|
||||
it 'dovrebbe rendere disponibile l\'handler del webhook', ->
|
||||
githubhook.should.not.be.undefined
|
||||
githook.should.not.be.undefined
|
||||
|
||||
it 'dovrebbe informare correttamente riguardo gli aggiornamenti', (done) ->
|
||||
acc = 0
|
||||
@ -110,10 +113,10 @@ describe 'modulo github', ->
|
||||
l.join().should.equal 'branch '+req.body.ref+' aggiornato!\ntest -> commit'
|
||||
acc++
|
||||
if acc is 2 then done()
|
||||
githubhook req, res
|
||||
githook req, res
|
||||
req.body.ref = 'refs/heads/master'
|
||||
req.body.commits.push
|
||||
committer:
|
||||
username: 'test'
|
||||
message: 'commit'
|
||||
githubhook req, res
|
||||
githook req, res
|
@ -88,4 +88,4 @@ describe 'modulo shell', ->
|
||||
if acc is 3
|
||||
done()
|
||||
process.env.AUTO_KILL_ON_UPDATE = 'true'
|
||||
asjon.robot.emit 'githubhook', data, params
|
||||
asjon.robot.emit 'githook', data, params
|
||||
|
Loading…
Reference in New Issue
Block a user