From ca21401c60967a56f18632e88766583838c9f7cc Mon Sep 17 00:00:00 2001 From: sairoutine Date: Wed, 28 Oct 2015 12:58:41 +0900 Subject: [PATCH 1/5] Add options for getting pulls --- github.js | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/github.js b/github.js index 1ea473fa..88d7101f 100644 --- a/github.js +++ b/github.js @@ -412,12 +412,49 @@ // ------- 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); + 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); }); }; + // Gets details for a specific pull request // ------- From 2f70781ba674984379ed39ca05728e568490f81d Mon Sep 17 00:00:00 2001 From: sairoutine Date: Sat, 31 Oct 2015 17:04:15 +0900 Subject: [PATCH 2/5] delete no need line break --- github.js | 1 - 1 file changed, 1 deletion(-) diff --git a/github.js b/github.js index 88d7101f..d8d0fb33 100644 --- a/github.js +++ b/github.js @@ -454,7 +454,6 @@ }); }; - // Gets details for a specific pull request // ------- From ec0a4e0d1f7b1b22320e7cf530f4149ebcee04de Mon Sep 17 00:00:00 2001 From: sairoutine Date: Sat, 31 Oct 2015 17:12:02 +0900 Subject: [PATCH 3/5] delete duplicate test --- test/test.repo.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/test/test.repo.js b/test/test.repo.js index e3959971..51c09b29 100644 --- a/test/test.repo.js +++ b/test/test.repo.js @@ -251,13 +251,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: { From e2e37f5b002083f37d96d487891fe2dc864e1452 Mon Sep 17 00:00:00 2001 From: sairoutine Date: Sat, 31 Oct 2015 22:57:00 +0900 Subject: [PATCH 4/5] fix a bug --- github.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github.js b/github.js index d8d0fb33..fcf55eb1 100644 --- a/github.js +++ b/github.js @@ -411,7 +411,7 @@ // List all pull requests of a respository // ------- - this.listPulls = function(state, cb) { + this.listPulls = function(options, cb) { options = options || {}; var url = repoPath + "/pulls"; var params = []; From b9c5faa0e745714d9fdc5852f3c9b72ae909357c Mon Sep 17 00:00:00 2001 From: sairoutine Date: Sat, 31 Oct 2015 22:57:33 +0900 Subject: [PATCH 5/5] add listPulls test --- test/test.repo.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/test/test.repo.js b/test/test.repo.js index 51c09b29..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(); }); });