no issues for milestone warning
This commit is contained in:
parent
8a115037c4
commit
5220316bca
|
@ -4,11 +4,15 @@ req = require './request'
|
|||
module.exports =
|
||||
'get_current': (user, repo, cb) ->
|
||||
req.milestones user, repo, (err, data) ->
|
||||
# Request errors.
|
||||
return cb err if err
|
||||
# GitHub errors.
|
||||
return cb data.message if data.message
|
||||
return cb 'No open milestones for a repo' unless data.length
|
||||
# Go through the milestones looking for one that ends/ended soonest.
|
||||
max = [ null, 'A' ]
|
||||
for i, { due_on } of data when due_on < max[1]
|
||||
max = [ parseInt(i), due_on ]
|
||||
cb null, data[max[0]]
|
||||
# Empty warning.
|
||||
return cb null, 'No open milestones for repo' unless data.length
|
||||
# Find the one due on soonest (string comparison).
|
||||
max = { 'due_on': 'A' }
|
||||
( max = ms for ms in data when ms.due_on < max.due_on )
|
||||
# Empty milestone?
|
||||
return cb null, 'No issues for milestone' if max.open_issues + max.closed_issues is 0
|
||||
cb null, null, max
|
|
@ -20,7 +20,7 @@ module.exports =
|
|||
}
|
||||
]
|
||||
|
||||
milestones.get_current null, null, (err, milestone) ->
|
||||
milestones.get_current null, null, (err, warn, milestone) ->
|
||||
assert.ifError err
|
||||
assert.equal milestone.number, 1
|
||||
done.call null
|
||||
|
@ -45,7 +45,7 @@ module.exports =
|
|||
}
|
||||
]
|
||||
|
||||
milestones.get_current null, null, (err, milestone) ->
|
||||
milestones.get_current null, null, (err, warn, milestone) ->
|
||||
assert.ifError err
|
||||
assert.equal milestone.number, 2
|
||||
done.call null
|
||||
|
@ -54,14 +54,32 @@ module.exports =
|
|||
req.milestones = (user, repo, cb) ->
|
||||
cb null, []
|
||||
|
||||
milestones.get_current null, null, (err, milestone) ->
|
||||
assert.equal err, 'No open milestones for a repo'
|
||||
milestones.get_current null, null, (err, warn, milestone) ->
|
||||
assert.ifError err
|
||||
assert.equal warn, 'No open milestones for repo'
|
||||
done.call null
|
||||
|
||||
'get current when not found': (done) ->
|
||||
req.milestones = (user, repo, cb) ->
|
||||
cb null, { 'message': 'Not Found' }
|
||||
|
||||
milestones.get_current null, null, (err, milestone) ->
|
||||
milestones.get_current null, null, (err, warn, milestone) ->
|
||||
assert.equal err, 'Not Found'
|
||||
done.call null
|
||||
|
||||
'get current when no issues': (done) ->
|
||||
req.milestones = (user, repo, cb) ->
|
||||
cb null, [
|
||||
{
|
||||
'number': 1
|
||||
'created_at': '2013-01-01T00:00:00Z'
|
||||
'due_on': '2013-02-01T00:00:00Z',
|
||||
'open_issues': 0,
|
||||
'closed_issues': 0
|
||||
}
|
||||
]
|
||||
|
||||
milestones.get_current null, null, (err, warn, milestone) ->
|
||||
assert.ifError err
|
||||
assert.equal warn, 'No issues for milestone'
|
||||
done.call null
|
Loading…
Reference in New Issue