Skip to content

Commit

Permalink
Add methods to fetch gist's commit and specific revision (#412)
Browse files Browse the repository at this point in the history
  • Loading branch information
fkling authored and clayreimann committed Jan 5, 2017
1 parent f075749 commit 46dd1d7
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/Gist.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,27 @@ class Gist extends Requestable {
return this._request204or404(`/gists/${this.__id}/star`, null, cb);
}

/**
* List the gist's commits
* @see https://developer.github.com/v3/gists/#list-gist-commits
* @param {Requestable.callback} [cb] - will receive the array of commits
* @return {Promise} - the Promise for the http request
*/
listCommits(cb) {
return this._requestAllPages(`/gists/${this.__id}/commits`, null, cb);
}

/**
* Fetch one of the gist's revision.
* @see https://developer.github.com/v3/gists/#get-a-specific-revision-of-a-gist
* @param {string} revision - the id of the revision
* @param {Requestable.callback} [cb] - will receive the revision
* @return {Promise} - the Promise for the http request
*/
getRevision(revision, cb) {
return this._request('GET', `/gists/${this.__id}/${revision}`, null, cb);
}

/**
* List the gist's comments
* @see https://developer.github.com/v3/gists/comments/#list-comments-on-a-gist
Expand Down
32 changes: 32 additions & 0 deletions test/gist.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('Gist', function() {
let gistId;
let github;
let commentId;
let revisionId;

before(function() {
github = new Github({
Expand Down Expand Up @@ -51,6 +52,7 @@ describe('Gist', function() {
expect(gist).to.have.own('public', testGist.public);
expect(gist).to.have.own('description', testGist.description);
gistId = gist.id;
revisionId = gist.history[0].version;

done();
}));
Expand Down Expand Up @@ -99,6 +101,36 @@ describe('Gist', function() {
it('should delete comment', function(done) {
gist.deleteComment(commentId, assertSuccessful(done));
});

it('should update gist', function(done) {
const newGist = {
files: {
'README.md': {
content: 'README updated',
},
},
};
gist.update(newGist, assertSuccessful(done, function(err, gist) {
expect(gist.history.length).to.be(2);
expect(gist.files['README.md']).to.have.own('content', newGist.files['README.md'].content);
done();
}));
});

it('should list commits', function(done) {
gist.listCommits(assertSuccessful(done, function(err, commits) {
expect(commits).to.be.an.array();
done();
}));
});

it('should get revision', function(done) {
gist.getRevision(revisionId, assertSuccessful(done, function(err, gist) {
expect(gist.history.length).to.be(1);
expect(gist.files['README.md']).to.have.own('content', testGist.files['README.md'].content);
done();
}));
});
});

describe('deleting', function() {
Expand Down

0 comments on commit 46dd1d7

Please sign in to comment.