Skip to content

Commit 6027f56

Browse files
authored
Merge pull request #599 from otaviocx/feature/list-commits-on-pull-request
Add a function to list the commits on a pull request
2 parents 8a4691f + ba74ee2 commit 6027f56

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

lib/Repository.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,23 @@ class Repository extends Requestable {
198198
return this._request('GET', `/repos/${this.__fullname}/commits`, options, cb);
199199
}
200200

201+
/**
202+
* List the commits on a pull request
203+
* @see https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository
204+
* @param {number|string} number - the number of the pull request to list the commits
205+
* @param {Object} [options] - the filtering options for commits
206+
* @param {Requestable.callback} [cb] - will receive the commits information
207+
* @return {Promise} - the promise for the http request
208+
*/
209+
listCommitsOnPR(number, options, cb) {
210+
options = options || {};
211+
if (typeof options === 'function') {
212+
cb = options;
213+
options = {};
214+
}
215+
return this._request('GET', `/repos/${this.__fullname}/pulls/${number}/commits`, options, cb);
216+
}
217+
201218
/**
202219
* Gets a single commit information for a repository
203220
* @see https://developer.github.com/v3/repos/commits/#get-a-single-commit

test/repository.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,24 @@ describe('Repository', function() {
173173
}));
174174
});
175175

176+
it('should list commits on a PR with no options', function(done) {
177+
const PR_NUMBER = 588;
178+
remoteRepo.listCommitsOnPR(PR_NUMBER, assertSuccessful(done, function(err, commits) {
179+
expect(commits).to.be.an.array();
180+
expect(commits.length).to.be.equal(2);
181+
182+
let message1 = 'fix(repository): prevents lib from crashing when not providing optional arguments';
183+
expect(commits[0].author).to.have.own('login', 'hazmah0');
184+
expect(commits[0].commit).to.have.own('message', message1);
185+
186+
let message2 = 'test(repository): updates test to use promise instead of callback';
187+
expect(commits[1].author).to.have.own('login', 'hazmah0');
188+
expect(commits[1].commit).to.have.own('message', message2);
189+
190+
done();
191+
}));
192+
});
193+
176194
it('should get the latest commit from master', function(done) {
177195
remoteRepo.getSingleCommit('master', assertSuccessful(done, function(err, commit) {
178196
expect(commit).to.have.own('sha');

0 commit comments

Comments
 (0)