primo passo integrazione con drone

This commit is contained in:
Enrico Fasoli 2015-04-28 17:50:59 +02:00
parent 508c81fa8a
commit 5a5850ad80
5 changed files with 3115 additions and 1 deletions

34
scripts/drone.coffee Normal file
View File

@ -0,0 +1,34 @@
# Description:
# integrazione con drone.io e funzioni annesse
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# hubot (mostrami la) copertura (dei test)
#
# Author:
# Enrico Fasoli (fazo96)
moment = require 'moment'
module.exports = (robot) ->
robot.respond /(?:mostrami la )?(?:copertura|coverage)(?: dei test)?/i, (res) ->
url = 'https://drone.io/github.com/fazo96/asjon/files/coverage/coverage.'
robot.http(url+'json')
.get() (err, resp, body) ->
try
report = JSON.parse body
catch e
return res.send 'errore'
unless report?.files?.push? and report?.coverage?.toFixed?
return res.send 'errore'
t = '=== Coverage: ' + report.coverage.toFixed(0) + '%'
t += report.files.map (f) ->
'\n - ' + f.filename + ' is covered at ' + f.coverage.toFixed(0) + '%'
t += '\nHTML report: '+url+'html'
t += '\nJSON report: '+url+'json'
res.send t

View File

@ -83,7 +83,7 @@ module.exports = (robot) ->
res.send 'anche io ti amo '+(res.message.user.name+' ' or '')+'<3'
robot.respond /ti odio/i, (res) ->
res.send 'ma cosa ho fatto di male '+(res.message.user.name or '')+'? :('
robot.hear /(?:ehi|ciao|(?:bella(?: li)?)) (?:asjon|assa|assion(?:i|e))/i, (res) ->
robot.hear /(?:ehi|ciao|we|(?:bella(?: li)?)) (?:asjon|assa|assion(?:i|e))/i, (res) ->
console.log res.match
saluti = ['ciao', 'bella', 'è arrivato', 'eccolooo', 'dimmi', 'weeee', 'ehilà']
res.send res.random(saluti)+' '+res.message.user.name+'!'

3031
test/coverage.json Normal file

File diff suppressed because it is too large Load Diff

49
test/drone-test.coffee Normal file
View File

@ -0,0 +1,49 @@
nock = require 'nock'
expect = require("chai").should()
Asjon = require '../asjon-testing.coffee'
asjon = undefined
describe 'modulo drone', ->
before (done) ->
# Inizializzo robot
Asjon (assa) ->
asjon = assa
after asjon.after
afterEach asjon.clear
require('../scripts/drone.coffee')(asjon.robot)
done()
it 'dovrebbe rispondere quando interrogato', (done) ->
nock('https://drone.io')
.get('/github.com/fazo96/asjon/files/coverage/coverage.json')
.reply 200, { coverage: 0, files: [] }
questions = [
"asjon mostrami la copertura dei test"
"asjon copertura dei test"
"asjon copertura"
"asjon coverage"
]
acc = 0
asjon.receive (e,l) ->
acc++
if acc is questions.length then done()
questions.map (q) -> asjon.send q
it 'dovrebbe reagire correttamente a un errore', (done) ->
nock('https://drone.io')
.get('/github.com/fazo96/asjon/files/coverage/coverage.json')
.reply 200, 'invalid answer'
asjon.receive (e,l) ->
l.join().should.equal 'errore'
done()
asjon.send 'asjon coverage'
it 'dovrebbe parsare correttamente il report json', (done) ->
nock('https://drone.io')
.get('/github.com/fazo96/asjon/files/coverage/coverage.json')
.replyWithFile 200, __dirname+'/coverage.json'
asjon.receive (e,l) ->
l.join().should.match /^=== Coverage: /g
done()
asjon.send 'asjon coverage'