Skip to content

Commit c679496

Browse files
committed
Create or update issue comments.
1 parent 3a25b3c commit c679496

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

src/cml.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class CML {
163163
const triggerSha = await this.triggerSha();
164164
const {
165165
commitSha: inCommitSha = triggerSha,
166-
// issue: issueId,
166+
issue: issueId,
167167
rmWatermark,
168168
update,
169169
pr,
@@ -267,6 +267,23 @@ class CML {
267267
return body.includes('watermark.svg');
268268
});
269269
};
270+
// Create or update an issue comment.
271+
if (issueId) {
272+
if (update) {
273+
comment = updatableComment(await drv.issueComments({ issueId }));
274+
275+
if (comment)
276+
return await drv.issueCommentUpdate({
277+
report,
278+
id: comment.id,
279+
issueId
280+
});
281+
}
282+
return await drv.issueCommentCreate({
283+
report,
284+
issueId
285+
});
286+
}
270287

271288
const isBB = this.driver === BB;
272289
if (pr || isBB) {

src/drivers/bitbucket_cloud.js

+12
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ class BitbucketCloud {
5656
).links.html.href;
5757
}
5858

59+
async issueComments(opts = {}) {
60+
const { projectPath } = this;
61+
const { issueId } = opts;
62+
63+
const endpoint = `/repositories/${projectPath}/issues/${issueId}/comments/`;
64+
return (await this.paginatedRequest({ endpoint, method: 'GET' })).map(
65+
({ id, content: { raw: body = '' } = {} }) => {
66+
return { id, body };
67+
}
68+
);
69+
}
70+
5971
async commentCreate(opts = {}) {
6072
const { projectPath } = this;
6173
const { commitSha, report } = opts;

src/drivers/github.js

+16
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,22 @@ class Github {
574574
return htmlUrl;
575575
}
576576

577+
async issueComments(opts = {}) {
578+
const { issueId } = opts;
579+
const { owner, repo } = ownerRepo({ uri: this.repo });
580+
const { issues } = octokit(this.token, this.repo);
581+
582+
const { data: comments } = await issues.listComments({
583+
owner,
584+
repo,
585+
issue_number: issueId
586+
});
587+
588+
return comments.map(({ id, body }) => {
589+
return { id, body };
590+
});
591+
}
592+
577593
async prCommentCreate(opts = {}) {
578594
const { report: body, prNumber } = opts;
579595
const { owner, repo } = ownerRepo({ uri: this.repo });

src/drivers/gitlab.js

+16
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,22 @@ class Gitlab {
363363
return `${this.repo}/-/issues/${issueId}#note_${id}`;
364364
}
365365

366+
async issueComments(opts = {}) {
367+
const projectPath = await this.projectPath();
368+
const { issueId } = opts;
369+
370+
const endpoint = `/projects/${projectPath}/issues/${issueId}/notes`;
371+
372+
const comments = await this.request({
373+
endpoint,
374+
method: 'GET'
375+
});
376+
377+
return comments.map(({ id, body }) => {
378+
return { id, body };
379+
});
380+
}
381+
366382
async prCommentCreate(opts = {}) {
367383
const projectPath = await this.projectPath();
368384
const { report, prNumber } = opts;

0 commit comments

Comments
 (0)