Skip to content

Commit aa7ba49

Browse files
randalpintoclayreimann
authored andcommitted
feature(repository): add method to get a single commit
See: https://developer.github.com/v3/repos/commits/#get-a-single-commit
1 parent c27af21 commit aa7ba49

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/Repository.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,18 @@ class Repository extends Requestable {
174174
return this._request('GET', `/repos/${this.__fullname}/commits`, options, cb);
175175
}
176176

177+
/**
178+
* Gets a single commit information for a repository
179+
* @see https://developer.github.com/v3/repos/commits/#get-a-single-commit
180+
* @param {string} ref - the reference for the commit-ish
181+
* @param {Requestable.callback} cb - will receive the commit information
182+
* @return {Promise} - the promise for the http request
183+
*/
184+
getSingleCommit(ref, cb) {
185+
ref = ref || '';
186+
return this._request('GET', `/repos/${this.__fullname}/commits/${ref}`, null, cb);
187+
}
188+
177189
/**
178190
* Get tha sha for a particular object in the repository. This is a convenience function
179191
* @see https://developer.github.com/v3/repos/contents/#get-contents

test/repository.spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,23 @@ describe('Repository', function() {
138138
}));
139139
});
140140

141+
it('should get the latest commit from master', function(done) {
142+
remoteRepo.getSingleCommit('master', assertSuccessful(done, function(err, commit) {
143+
expect(commit).to.have.own('sha');
144+
expect(commit).to.have.own('commit');
145+
expect(commit).to.have.own('author');
146+
147+
done();
148+
}));
149+
});
150+
151+
it('should fail when null ref is passed', function(done) {
152+
remoteRepo.getSingleCommit(null, assertFailure(done, function(err) {
153+
expect(err.status).to.be(404);
154+
done();
155+
}));
156+
});
157+
141158
it('should show repo contributors', function(done) {
142159
remoteRepo.getContributors(assertSuccessful(done, function(err, contributors) {
143160
if (!(contributors instanceof Array)) {

0 commit comments

Comments
 (0)