diff --git a/README.md b/README.md index ce77612..228dc44 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/issues.coffee b/src/issues.coffee index 4db8016..89f322f 100644 --- a/src/issues.coffee +++ b/src/issues.coffee @@ -32,4 +32,24 @@ module.exports = async.parallel [ _.partial one_status, 'open' _.partial one_status, 'closed' - ], cb \ No newline at end of file + ], 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 \ No newline at end of file diff --git a/test/issues.coffee b/test/issues.coffee index 48e6666..44991f3 100644 --- a/test/issues.coffee +++ b/test/issues.coffee @@ -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 \ No newline at end of file