diff --git a/lib/Gist.js b/lib/Gist.js index 14b71322..60f18cf5 100644 --- a/lib/Gist.js +++ b/lib/Gist.js @@ -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 diff --git a/test/gist.spec.js b/test/gist.spec.js index c9c2e393..af24f966 100644 --- a/test/gist.spec.js +++ b/test/gist.spec.js @@ -10,6 +10,7 @@ describe('Gist', function() { let gistId; let github; let commentId; + let revisionId; before(function() { github = new Github({ @@ -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(); })); @@ -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() {
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: