basic pigeon-holing of issues into days

This commit is contained in:
Radek Stepan 2013-08-13 16:29:25 +01:00
parent 696f493ca0
commit bb3ce0fcc2
2 changed files with 33 additions and 1 deletions

View File

@ -52,4 +52,19 @@ module.exports =
cb null, warnings, filtered
catch err
return cb err, warnings
return cb err, warnings
# Map a collection of closed issues into days.
'into_days': (collection, cb) ->
days = {}
for issue in collection
{ state, number, closed_at } = issue
number ?= '?'
return "Issue ##{number} does not have a `closed_at` parameter" unless closed_at
unless matches = closed_at.match /^(\d{4}-\d{2}-\d{2})T(.*)/
return "Issue ##{number} does not match the `closed_at` pattern"
[ date, time ] = matches[1...]
days[date] ?= []
days[date].push issue
cb null, days

View File

@ -181,4 +181,21 @@ module.exports =
assert.ifError err
assert.equal warn.length, 1
assert.equal data.length, 1
done.call null
'organize issues into days': (done) ->
issues.into_days [
{ number: 1, closed_at: '2013-05-09T10:04:53Z' }
{ number: 2, closed_at: '2013-05-09T09:04:53Z' }
{ number: 3, closed_at: '2013-05-10T09:04:53Z' }
], (err, data) ->
assert.ifError err
assert.deepEqual data,
'2013-05-09': [
{ number: 1, closed_at: '2013-05-09T10:04:53Z' }
{ number: 2, closed_at: '2013-05-09T09:04:53Z' }
]
'2013-05-10': [
{ number: 3, closed_at: '2013-05-10T09:04:53Z' }
]
done.call null