Skip to content

Commit

Permalink
feature(repository): add method to get a single commit
Browse files Browse the repository at this point in the history
  • Loading branch information
randalpinto authored and clayreimann committed May 23, 2016
1 parent c27af21 commit aa7ba49
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/Repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,18 @@ class Repository extends Requestable {
return this._request('GET', `/repos/${this.__fullname}/commits`, options, cb);
}

/**
* Gets a single commit information for a repository
* @see https://developer.github.com/v3/repos/commits/#get-a-single-commit
* @param {string} ref - the reference for the commit-ish
* @param {Requestable.callback} cb - will receive the commit information
* @return {Promise} - the promise for the http request
*/
getSingleCommit(ref, cb) {
ref = ref || '';
return this._request('GET', `/repos/${this.__fullname}/commits/${ref}`, null, cb);
}

/**
* Get tha sha for a particular object in the repository. This is a convenience function
* @see https://developer.github.com/v3/repos/contents/#get-contents
Expand Down
17 changes: 17 additions & 0 deletions test/repository.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,23 @@ describe('Repository', function() {
}));
});

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

done();
}));
});

it('should fail when null ref is passed', function(done) {
remoteRepo.getSingleCommit(null, assertFailure(done, function(err) {
expect(err.status).to.be(404);
done();
}));
});

it('should show repo contributors', function(done) {
remoteRepo.getContributors(assertSuccessful(done, function(err, contributors) {
if (!(contributors instanceof Array)) {
Expand Down

0 comments on commit aa7ba49

Please sign in to comment.