diff --git a/github.js b/github.js index 1ea473fa..fcf55eb1 100644 --- a/github.js +++ b/github.js @@ -411,10 +411,46 @@ // List all pull requests of a respository // ------- - this.listPulls = function(state, cb) { - _request('GET', repoPath + '/pulls' + (state ? '?state=' + state : ''), null, function(err, pulls, xhr) { - if (err) return cb(err); - cb(null, pulls, xhr); + this.listPulls = function(options, cb) { + options = options || {}; + var url = repoPath + "/pulls"; + var params = []; + + if (typeof options === 'string') { + // backward compatibility + params.push('state=' + options); + } + else { + if (options.state) { + params.push("state=" + encodeURIComponent(options.state)); + } + if (options.head) { + params.push("head=" + encodeURIComponent(options.head)); + } + if (options.base) { + params.push("base=" + encodeURIComponent(options.base)); + } + if (options.sort) { + params.push("sort=" + encodeURIComponent(options.sort)); + } + if (options.direction) { + params.push("direction=" + encodeURIComponent(options.direction)); + } + if (options.page) { + params.push("page=" + options.page); + } + if (options.per_page) { + params.push("per_page=" + options.per_page); + } + } + + if (params.length > 0) { + url += "?" + params.join("&"); + } + + _request('GET', url, null, function(err, pulls, xhr) { + if (err) return cb(err); + cb(null, pulls, xhr); }); }; diff --git a/test/test.repo.js b/test/test.repo.js index e3959971..9e992f60 100644 --- a/test/test.repo.js +++ b/test/test.repo.js @@ -210,10 +210,22 @@ describe('Creating new Github.Repository', function() { }); it('should list pulls on repo', function(done) { - repo.listPulls('open', function(err) { - should.not.exist(err); + var repo = github.getRepo('michael', 'github'); + var options = { + state: 'all', + sort: 'updated', + direction: 'desc', + page: 1, + per_page: 100 + }; - // @TODO write better assertion + repo.listPulls(options, function(err, pull_list) { + should.not.exist(err); + pull_list.should.be.instanceof(Array); + pull_list.should.have.length(100); + should.exist(pull_list[0].title); + should.exist(pull_list[0].body); + should.exist(pull_list[0].url); done(); }); }); @@ -251,13 +263,6 @@ describe('Creating new Github.Repository', function() { }); }); - it('should list pull requests on repo', function(done) { - repo.listPulls('open', function(err) { - should.not.exist(err); - done(); - }); - }); - it('should write author and committer to repo', function(done) { var options = { author: {