Skip to content

Commit c5a9dd3

Browse files
committed
Make bot produce fewer comments
1 parent 87388a7 commit c5a9dd3

3 files changed

Lines changed: 46 additions & 28 deletions

File tree

dist/index.js

Lines changed: 22 additions & 13 deletions
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/index.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -192,25 +192,34 @@ if (body) {
192192

193193
const compareDate = (a: Date, b: Date) => a == b ? 0 : a < b ? -1 : 1;
194194

195+
const post_comment = () => {
196+
console.log("leaving comment");
197+
octokit.rest.issues.createComment({
198+
owner,
199+
repo,
200+
issue_number: pull_request_number,
201+
body,
202+
});
203+
};
204+
195205
const sorted_comments = comments
196206
.filter((comment) => comment.user?.login == "cppwarningnotifier[bot]")
197207
.toSorted((a, b) => compareDate(new Date(a.created_at), new Date(b.created_at)));
198208
if (sorted_comments.length > 0) {
199209
const latest_comment = sorted_comments[sorted_comments.length - 1];
200-
await octokit.graphql(`
201-
mutation {
202-
minimizeComment(input: { subjectId: "${latest_comment.node_id}", classifier: OUTDATED }) {
203-
clientMutationId
210+
if (latest_comment.body?.includes("warning")) {
211+
// minimize latest comment
212+
await octokit.graphql(`
213+
mutation {
214+
minimizeComment(input: { subjectId: "${latest_comment.node_id}", classifier: OUTDATED }) {
215+
clientMutationId
216+
}
204217
}
205-
}
206-
`);
218+
`);
219+
220+
post_comment();
221+
}
222+
} else {
223+
post_comment();
207224
}
208-
209-
console.log("leaving comment");
210-
octokit.rest.issues.createComment({
211-
owner,
212-
repo,
213-
issue_number: pull_request_number,
214-
body,
215-
});
216225
}

0 commit comments

Comments
 (0)