+
Skip to content

Add options for getting list pull requests #250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 40 additions & 4 deletions github.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
};

Expand Down
25 changes: 15 additions & 10 deletions test/test.repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Expand Down Expand Up @@ -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: {
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载