Skip to content

Commit 3a25b3c

Browse files
committed
Driver support for issue comments.
1 parent c60cf52 commit 3a25b3c

File tree

4 files changed

+96
-0
lines changed

4 files changed

+96
-0
lines changed

src/cml.js

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ class CML {
163163
const triggerSha = await this.triggerSha();
164164
const {
165165
commitSha: inCommitSha = triggerSha,
166+
// issue: issueId,
166167
rmWatermark,
167168
update,
168169
pr,

src/drivers/bitbucket_cloud.js

+27
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,33 @@ class BitbucketCloud {
2929
}
3030
}
3131

32+
async issueCommentCreate(opts = {}) {
33+
const { projectPath } = this;
34+
const { issueId, report } = opts;
35+
const endpoint = `/repositories/${projectPath}/issues/${issueId}/comments/`;
36+
return (
37+
await this.request({
38+
endpoint,
39+
method: 'POST',
40+
body: JSON.stringify({ content: { raw: report } })
41+
})
42+
).links.html.href;
43+
}
44+
45+
async issueCommentUpdate(opts = {}) {
46+
const { projectPath } = this;
47+
const { issueId, id, report } = opts;
48+
49+
const endpoint = `/repositories/${projectPath}/issues/${issueId}/comments/${id}`;
50+
return (
51+
await this.request({
52+
endpoint,
53+
method: 'PUT',
54+
body: JSON.stringify({ content: { raw: report } })
55+
})
56+
).links.html.href;
57+
}
58+
3259
async commentCreate(opts = {}) {
3360
const { projectPath } = this;
3461
const { commitSha, report } = opts;

src/drivers/github.js

+34
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,40 @@ class Github {
540540
}
541541
}
542542

543+
async issueCommentCreate(opts = {}) {
544+
const { issueId, report } = opts;
545+
const { owner, repo } = ownerRepo({ uri: this.repo });
546+
const { issues } = octokit(this.token, this.repo);
547+
548+
const {
549+
data: { html_url: htmlUrl }
550+
} = await issues.createComment({
551+
owner,
552+
repo,
553+
report,
554+
issue_number: issueId
555+
});
556+
557+
return htmlUrl;
558+
}
559+
560+
async issueCommentUpdate(opts = {}) {
561+
const { id, report } = opts;
562+
const { owner, repo } = ownerRepo({ uri: this.repo });
563+
const { issues } = octokit(this.token, this.repo);
564+
565+
const {
566+
data: { html_url: htmlUrl }
567+
} = await issues.updateComment({
568+
owner,
569+
repo,
570+
report,
571+
comment_id: id
572+
});
573+
574+
return htmlUrl;
575+
}
576+
543577
async prCommentCreate(opts = {}) {
544578
const { report: body, prNumber } = opts;
545579
const { owner, repo } = ownerRepo({ uri: this.repo });

src/drivers/gitlab.js

+34
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,40 @@ class Gitlab {
329329
}
330330
}
331331

332+
async issueCommentCreate(opts = {}) {
333+
const projectPath = await this.projectPath();
334+
const { issueId, report } = opts;
335+
336+
const endpoint = `/projects/${projectPath}/issues/${issueId}/notes`;
337+
const body = new URLSearchParams();
338+
body.append('body', report);
339+
340+
const { id } = await this.request({
341+
endpoint,
342+
method: 'POST',
343+
body
344+
});
345+
346+
return `${this.repo}/-/issues/${issueId}#note_${id}`;
347+
}
348+
349+
async issueCommentUpdate(opts = {}) {
350+
const projectPath = await this.projectPath();
351+
const { issueId, id: commentId, report } = opts;
352+
353+
const endpoint = `/projects/${projectPath}/issues/${issueId}/notes/${commentId}`;
354+
const body = new URLSearchParams();
355+
body.append('body', report);
356+
357+
const { id } = await this.request({
358+
endpoint,
359+
method: 'PUT',
360+
body
361+
});
362+
363+
return `${this.repo}/-/issues/${issueId}#note_${id}`;
364+
}
365+
332366
async prCommentCreate(opts = {}) {
333367
const projectPath = await this.projectPath();
334368
const { report, prNumber } = opts;

0 commit comments

Comments
 (0)