Skip to content

Commit cf7e9e5

Browse files
committed
Allow detecting comments from other bots
Signed-off-by: David Kwon <[email protected]>
1 parent b1f7ca3 commit cf7e9e5

File tree

4 files changed

+22
-15
lines changed

4 files changed

+22
-15
lines changed

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/helpers/update-comment-helper.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export class UpdateCommentHelper {
1212
@inject(Octokit)
1313
private readonly octokit: Octokit;
1414

15-
private static readonly GH_ACTION_BOT =
16-
"https://github.com/apps/github-actions";
15+
private static readonly BOT_TYPE =
16+
"Bot";
1717

1818
/**
1919
* Updates a GH comment previously created by the github-actions bot with a new comment
@@ -74,7 +74,7 @@ export class UpdateCommentHelper {
7474
): ArrayType<IssuesListCommentsResponseData> | undefined {
7575
return response.data.find((comment) => {
7676
return (
77-
comment.user.html_url === UpdateCommentHelper.GH_ACTION_BOT
77+
comment.user.type === UpdateCommentHelper.BOT_TYPE
7878
&& searchRegex.test(comment.body)
7979
);
8080
});

tests/helpers/update-comment-helper.spec.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe("Test Helper UpdateCommentHelper", () => {
3232
{
3333
id: 1234,
3434
user: {
35-
html_url: "https://github.com/apps/github-actions",
35+
type: "Bot",
3636
},
3737
body: "Hello world!",
3838
},
@@ -65,14 +65,14 @@ describe("Test Helper UpdateCommentHelper", () => {
6565
{
6666
id: 1234,
6767
user: {
68-
html_url: "https://github.com/apps/github-actions",
68+
type: "Bot",
6969
},
7070
body: "Hello world!",
7171
},
7272
{
7373
id: 1235,
7474
user: {
75-
html_url: "https://github.com/apps/github-actions",
75+
type: "Bot",
7676
},
7777
body: "Test comment",
7878
},
@@ -92,19 +92,19 @@ describe("Test Helper UpdateCommentHelper", () => {
9292
expect(octokit.issues.updateComment).toBeCalledTimes(0);
9393
});
9494

95-
test("comment not found due to no comments by GH bot", async () => {
95+
test("comment not found due to no comments by bot", async () => {
9696
const octokit = setComments([
9797
{
9898
id: 1234,
9999
user: {
100-
html_url: "https://github.com/apps/other-app",
100+
type: "User",
101101
},
102102
body: "Hello world!",
103103
},
104104
{
105105
id: 1235,
106106
user: {
107-
html_url: "https://github.com/dkwon17-test-user",
107+
type: "Organization",
108108
},
109109
body: "Hello world!",
110110
},
@@ -128,7 +128,7 @@ describe("Test Helper UpdateCommentHelper", () => {
128128
{
129129
id: 1234,
130130
user: {
131-
html_url: "https://github.com/apps/github-actions",
131+
type: "Bot",
132132
},
133133
body: "Hello world!",
134134
},
@@ -147,19 +147,26 @@ describe("Test Helper UpdateCommentHelper", () => {
147147
expect(octokit.issues.updateComment).toBeCalledTimes(0);
148148
});
149149

150-
test("update existing comment", async () => {
150+
test("update the correct existing comment", async () => {
151151
const octokit = setComments([
152152
{
153153
id: 1234,
154154
user: {
155-
html_url: "https://github.com/dkwon17-test-user",
155+
type: "User",
156156
},
157157
body: "Hello world!",
158158
},
159159
{
160160
id: 1235,
161161
user: {
162-
html_url: "https://github.com/apps/github-actions",
162+
type: "Bot",
163+
},
164+
body: "Hello world!",
165+
},
166+
{
167+
id: 1236,
168+
user: {
169+
type: "Organization",
163170
},
164171
body: "Hello world!",
165172
},

0 commit comments

Comments
 (0)