Skip to content

Commit

Permalink
Merge pull request #599 from otaviocx/feature/list-commits-on-pull-re…
Browse files Browse the repository at this point in the history
…quest

Add a function to list the commits on a pull request
  • Loading branch information
j-rewerts committed Jan 25, 2021
2 parents 8a4691f + ba74ee2 commit 6027f56
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/Repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,23 @@ class Repository extends Requestable {
return this._request('GET', `/repos/${this.__fullname}/commits`, options, cb);
}

/**
* List the commits on a pull request
* @see https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository
* @param {number|string} number - the number of the pull request to list the commits
* @param {Object} [options] - the filtering options for commits
* @param {Requestable.callback} [cb] - will receive the commits information
* @return {Promise} - the promise for the http request
*/
listCommitsOnPR(number, options, cb) {
options = options || {};
if (typeof options === 'function') {
cb = options;
options = {};
}
return this._request('GET', `/repos/${this.__fullname}/pulls/${number}/commits`, options, cb);
}

/**
* Gets a single commit information for a repository
* @see https://developer.github.com/v3/repos/commits/#get-a-single-commit
Expand Down
18 changes: 18 additions & 0 deletions test/repository.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,24 @@ describe('Repository', function() {
}));
});

it('should list commits on a PR with no options', function(done) {
const PR_NUMBER = 588;
remoteRepo.listCommitsOnPR(PR_NUMBER, assertSuccessful(done, function(err, commits) {
expect(commits).to.be.an.array();
expect(commits.length).to.be.equal(2);

let message1 = 'fix(repository): prevents lib from crashing when not providing optional arguments';
expect(commits[0].author).to.have.own('login', 'hazmah0');
expect(commits[0].commit).to.have.own('message', message1);

let message2 = 'test(repository): updates test to use promise instead of callback';
expect(commits[1].author).to.have.own('login', 'hazmah0');
expect(commits[1].commit).to.have.own('message', message2);

done();
}));
});

it('should get the latest commit from master', function(done) {
remoteRepo.getSingleCommit('master', assertSuccessful(done, function(err, commit) {
expect(commit).to.have.own('sha');
Expand Down

0 comments on commit 6027f56

Please sign in to comment.