Skip to content

Commit 46dd1d7

Browse files
fklingclayreimann
authored andcommitted
1 parent f075749 commit 46dd1d7

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

lib/Gist.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,27 @@ class Gist extends Requestable {
108108
return this._request204or404(`/gists/${this.__id}/star`, null, cb);
109109
}
110110

111+
/**
112+
* List the gist's commits
113+
* @see https://developer.github.com/v3/gists/#list-gist-commits
114+
* @param {Requestable.callback} [cb] - will receive the array of commits
115+
* @return {Promise} - the Promise for the http request
116+
*/
117+
listCommits(cb) {
118+
return this._requestAllPages(`/gists/${this.__id}/commits`, null, cb);
119+
}
120+
121+
/**
122+
* Fetch one of the gist's revision.
123+
* @see https://developer.github.com/v3/gists/#get-a-specific-revision-of-a-gist
124+
* @param {string} revision - the id of the revision
125+
* @param {Requestable.callback} [cb] - will receive the revision
126+
* @return {Promise} - the Promise for the http request
127+
*/
128+
getRevision(revision, cb) {
129+
return this._request('GET', `/gists/${this.__id}/${revision}`, null, cb);
130+
}
131+
111132
/**
112133
* List the gist's comments
113134
* @see https://developer.github.com/v3/gists/comments/#list-comments-on-a-gist

test/gist.spec.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ describe('Gist', function() {
1010
let gistId;
1111
let github;
1212
let commentId;
13+
let revisionId;
1314

1415
before(function() {
1516
github = new Github({
@@ -51,6 +52,7 @@ describe('Gist', function() {
5152
expect(gist).to.have.own('public', testGist.public);
5253
expect(gist).to.have.own('description', testGist.description);
5354
gistId = gist.id;
55+
revisionId = gist.history[0].version;
5456

5557
done();
5658
}));
@@ -99,6 +101,36 @@ describe('Gist', function() {
99101
it('should delete comment', function(done) {
100102
gist.deleteComment(commentId, assertSuccessful(done));
101103
});
104+
105+
it('should update gist', function(done) {
106+
const newGist = {
107+
files: {
108+
'README.md': {
109+
content: 'README updated',
110+
},
111+
},
112+
};
113+
gist.update(newGist, assertSuccessful(done, function(err, gist) {
114+
expect(gist.history.length).to.be(2);
115+
expect(gist.files['README.md']).to.have.own('content', newGist.files['README.md'].content);
116+
done();
117+
}));
118+
});
119+
120+
it('should list commits', function(done) {
121+
gist.listCommits(assertSuccessful(done, function(err, commits) {
122+
expect(commits).to.be.an.array();
123+
done();
124+
}));
125+
});
126+
127+
it('should get revision', function(done) {
128+
gist.getRevision(revisionId, assertSuccessful(done, function(err, gist) {
129+
expect(gist.history.length).to.be(1);
130+
expect(gist.files['README.md']).to.have.own('content', testGist.files['README.md'].content);
131+
done();
132+
}));
133+
});
102134
});
103135

104136
describe('deleting', function() {

0 commit comments

Comments
 (0)