-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.ts
80 lines (75 loc) · 2.4 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { getInput, setFailed } from "@actions/core";
import { context, getOctokit } from "@actions/github";
run();
async function run() {
try {
// Note: supporting other event types might require changing the query used
if (!["pull_request", "pull_request_target"].includes(context.eventName)) {
throw new Error(
`This action is not supported for event of type '${context.eventName}'.`
);
}
const token = getInput("github-token", { required: true });
const bodyIncludesInput = getInput("body-includes", { required: true });
const bodyStrings = bodyIncludesInput
.split("\n")
.map((s) => s.trim())
.filter((s) => s.length > 0);
const byAuthor = getInput("by-author", { required: true });
const github = getOctokit(token);
let execute = true;
let nextCursor = undefined;
while (execute) {
const result = await github.graphql(
`query FindComments($owner: String!, $repo: String!, $number: Int!, $nextCursor: String) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $number) {
comments(first: 50, after: $nextCursor) {
pageInfo {
endCursor
hasNextPage
hasPreviousPage
startCursor
}
nodes {
isMinimized
id
author {
login
}
body
}
}
}
}
}`,
{ ...context.issue, nextCursor }
);
const {
pageInfo,
nodes: comments,
} = (result as any).repository.pullRequest.comments;
for (const comment of comments) {
if (
!comment.isMinimized &&
comment.author.login === byAuthor &&
bodyStrings.some((s) => comment.body.includes(s))
) {
console.log("Minimizing " + comment.id);
await github.graphql(
`mutation MarkCommentOutdated($commentId: ID!) {
minimizeComment(input: {subjectId: $commentId, classifier: OUTDATED}) {
clientMutationId
}
}`,
{ commentId: comment.id }
);
}
}
execute = pageInfo.hasNextPage;
nextCursor = pageInfo.endCursor;
}
} catch (error) {
setFailed(error.message);
}
}