filter issues matching regex

This commit is contained in:
Radek Stepan 2013-08-13 15:47:52 +01:00
parent 7bbe71d718
commit 696f493ca0
3 changed files with 63 additions and 3 deletions

View File

@ -3,9 +3,9 @@
[ ![Codeship Status for radekstepan/github-burndown-chart](https://www.codeship.io/projects/d69f4420-e5b0-0130-bbae-1632ddfb80f8/status?branch=rework)](https://www.codeship.io/projects/5855)
##Next ->
##Next
[ ] Write tests to fetch open/closed issues (and save ourselves the trouble when milestone has 0 issues count)
Map all issues matching a given regex label to their ids (for later update) and to individual days in the duration of a milestone.
##Project Charter

View File

@ -32,4 +32,24 @@ module.exports =
async.parallel [
_.partial one_status, 'open'
_.partial one_status, 'closed'
], cb
], cb
# Filter an array of incoming issues based on a regex.
'filter': (collection, regex, cb) ->
warnings = null
try
filtered = _.filter collection, ({ labels, number }) ->
number ?= '?'
return false unless labels
switch ( {} for { name } in labels when name and regex.test(name) ).length
when 0 then false
when 1 then true
else
warnings ?= []
warnings.push "Issue ##{number} has multiple matching size labels"
true
cb null, warnings, filtered
catch err
return cb err, warnings

View File

@ -141,4 +141,44 @@ module.exports =
issues.get_all {}, (err, [ open, closed ]) ->
assert.equal err, 'Not Found'
assert.equal called, 1
done.call null
'filter on existing label regex': (done) ->
issues.filter [ { labels: [ { name: 'size 5' } ] } ]
, /size (\d)+$/, (err, warn, data) ->
assert.ifError err
assert.ifError warn
assert.equal data.length, 1
done.call null
'filter when no labels': (done) ->
issues.filter [ { } ]
, /size (\d)+$/, (err, warn, data) ->
assert.ifError err
assert.ifError warn
assert.equal data.length, 0
done.call null
'filter when empty labels': (done) ->
issues.filter [ { labels: [] } ]
, /size (\d)+$/, (err, warn, data) ->
assert.ifError err
assert.ifError warn
assert.equal data.length, 0
done.call null
'filter when not matching regex': (done) ->
issues.filter [ { labels: [ { name: 'size 1A' } ] } ]
, /size (\d)+$/, (err, warn, data) ->
assert.ifError err
assert.ifError warn
assert.equal data.length, 0
done.call null
'filter when multiple match the regex': (done) ->
issues.filter [ { labels: [ { name: 'size 1' }, { name: 'size 6' } ] } ]
, /size (\d)+$/, (err, warn, data) ->
assert.ifError err
assert.equal warn.length, 1
assert.equal data.length, 1
done.call null