when all issues are emptx

This commit is contained in:
Radek Stepan 2013-08-13 13:58:21 +01:00
parent b6a0866787
commit 689f6868a8
5 changed files with 63 additions and 1 deletions

View File

@ -8,7 +8,8 @@
"dependencies": {
"coffee-script": "~1.6.3",
"async": "~0.2.9",
"proxyquire": "~0.4.1"
"proxyquire": "~0.4.1",
"lodash": "~1.3.1"
},
"devDependencies": {
"mocha": "~1.12.0"

35
src/issues.coffee Normal file
View File

@ -0,0 +1,35 @@
#!/usr/bin/env coffee
{ _ } = require 'lodash'
async = require 'async'
req = require './request'
module.exports =
# Used on an initial fetch of issues for a repo.
'get_all': (opts, cb) ->
done = no
# For each status...
one_status = (status, cb) ->
# Concat them here.
results = []
# One pageful fetch (next pages in series).
do fetch_page = (page = 1) ->
req.all_issues { status: status, page: page }, (err, data) ->
# Request errors.
return cb err if err
# GitHub errors.
return cb data.message if data.message
# Empty?
return cb null, results unless data.length
# Concat.
results = results.concat data
# < 100 results?
return cb null, results if data.length < 100
# Fetch the next page then.
fetch_page page + 1
# For each `open` and `closed` issues in parallel.
async.parallel [
_.partial one_status, 'open'
_.partial one_status, 'closed'
], cb

View File

@ -2,6 +2,7 @@
req = require './request'
module.exports =
# Used at initialization stage.
'get_current': (opts, cb) ->
req.all_milestones opts, (err, data) ->
# Request errors.

View File

@ -3,4 +3,5 @@ module.exports =
'all_milestones': (opts, cb) ->
cb 'Not implemented'
'all_issues': (opts, cb) ->
# { direction: 'asc', per_page: 100 }
cb 'Not implemented'

24
test/issues.coffee Normal file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env coffee
assert = require 'assert'
async = require 'async'
path = require 'path'
proxy = require 'proxyquire'
req = {}
issues = proxy path.resolve(__dirname, '../src/issues.coffee'),
'./request': req
module.exports =
'all empty': (done) ->
called = 0
req.all_issues = (opts, cb) ->
called += 1
cb null, []
issues.get_all {}, (err, [ open, closed ]) ->
assert.ifError err
assert.equal called, 2
assert.equal open.length, 0
assert.equal closed.length, 0
done.call null