Skip to content

Commit 15c68a5

Browse files
ychuaclayreimann
authored andcommitted
feature(comment): add list, get, edit and delete for issue comments
1 parent e404aeb commit 15c68a5

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

lib/Issue.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,28 @@ class Issue extends Requestable {
4444
this._requestAllPages(`/repos/${this.__repository}/issues`, options, cb);
4545
}
4646

47+
/**
48+
* List comments on an issue
49+
* @see https://developer.github.com/v3/issues/comments/#list-comments-on-an-issue
50+
* @param {number} issue - the id of the issue to get comments from
51+
* @param {Requestable.callback} [cb] - will receive the comments
52+
* @return {Promise} - the promise for the http request
53+
*/
54+
listIssueComments(issue, cb) {
55+
this._request('GET', `/repos/${this.__repository}/issues/${issue}/comments`, null, cb); // jscs:ignore
56+
}
57+
58+
/**
59+
* Get a single comment on an issue
60+
* @see https://developer.github.com/v3/issues/comments/#get-a-single-comment
61+
* @param {number} id - the comment id to get
62+
* @param {Requestable.callback} [cb] - will receive the comment
63+
* @return {Promise} - the promise for the http request
64+
*/
65+
getIssueComment(id, cb) {
66+
this._request('GET', `/repos/${this.__repository}/issues/comments/${id}`, null, cb); // jscs:ignore
67+
}
68+
4769
/**
4870
* Comment on an issue
4971
* @see https://developer.github.com/v3/issues/comments/#create-a-comment
@@ -56,6 +78,29 @@ class Issue extends Requestable {
5678
this._request('POST', `/repos/${this.__repository}/issues/${issue}/comments`, {body: comment}, cb); // jscs:ignore
5779
}
5880

81+
/**
82+
* Edit a comment on an issue
83+
* @see https://developer.github.com/v3/issues/comments/#edit-a-comment
84+
* @param {number} id - the comment id to edit
85+
* @param {string} comment - the comment to edit
86+
* @param {Requestable.callback} [cb] - will receive the edited comment
87+
* @return {Promise} - the promise for the http request
88+
*/
89+
editIssueComment(id, comment, cb) {
90+
this._request('PATCH', `/repos/${this.__repository}/issues/comments/${id}`, {body: comment}, cb); // jscs:ignore
91+
}
92+
93+
/**
94+
* Delete a comment on an issue
95+
* @see https://developer.github.com/v3/issues/comments/#delete-a-comment
96+
* @param {number} id - the comment id to delete
97+
* @param {Requestable.callback} [cb] - will receive true if the request is successful
98+
* @return {Promise} - the promise for the http request
99+
*/
100+
deleteIssueComment(id, cb) {
101+
this._request('DELETE', `/repos/${this.__repository}/issues/comments/${id}`, null, cb); // jscs:ignore
102+
}
103+
59104
/**
60105
* Edit an issue
61106
* @see https://developer.github.com/v3/issues/#edit-an-issue

test/issue.spec.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ describe('Issue', function() {
88
let github;
99
let remoteIssues;
1010
let remoteIssueId;
11+
let remoteIssueCommentId;
1112

1213
before(function() {
1314
github = new Github({
@@ -38,7 +39,7 @@ describe('Issue', function() {
3839
});
3940
});
4041

41-
describe('creating/modifiying', function() {
42+
describe('creating/modifiying/editing/deleting', function() {
4243
// 200ms between tests so that Github has a chance to settle
4344
beforeEach(function(done) {
4445
setTimeout(done, 200);
@@ -67,6 +68,38 @@ describe('Issue', function() {
6768
}));
6869
});
6970

71+
it('should list issue comments', function(done) {
72+
remoteIssues.listIssueComments(remoteIssueId, assertSuccessful(done, function(err, comments) {
73+
expect(comments).to.be.an.array();
74+
expect(comments[0]).to.have.own('body', 'Comment test');
75+
remoteIssueCommentId = comments[0].id
76+
done();
77+
}));
78+
});
79+
80+
it('should get a single issue comment', function(done) {
81+
remoteIssues.getIssueComment(remoteIssueCommentId, assertSuccessful(done, function(err, comment) {
82+
expect(comment).to.have.own('body', 'Comment test');
83+
done();
84+
}));
85+
});
86+
87+
it('should edit issue comment', function(done) {
88+
remoteIssues.editIssueComment(remoteIssueCommentId, 'Comment test edited', assertSuccessful(done, function(err, comment) {
89+
expect(comment).to.have.own('body', 'Comment test edited');
90+
91+
done();
92+
}));
93+
});
94+
95+
it('should delete issue comment', function(done) {
96+
remoteIssues.deleteIssueComment(remoteIssueCommentId, assertSuccessful(done, function(err, response) {
97+
expect(response).to.be.true;
98+
99+
done();
100+
}));
101+
});
102+
70103
it('should edit issues title', function(done) {
71104
const newProps = {
72105
title: 'Edited title'

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy