-
-
Notifications
You must be signed in to change notification settings - Fork 863
Expand file tree
/
Copy pathget-issue-comments.js
More file actions
60 lines (46 loc) · 1.3 KB
/
get-issue-comments.js
File metadata and controls
60 lines (46 loc) · 1.3 KB
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
const tenDaysAgo = new Date();
tenDaysAgo.setDate(tenDaysAgo.getDate() - 10);
async function getIssueComments(github, context, issueNum) {
const owner = context.repo.owner;
const repo = context.repo.repo;
const query = `query($owner: String!, $repo: String!, $issueNum: Int!) {
repository(owner: $owner, name: $repo) {
issue(number: $issueNum) {
comments(first: 100) {
nodes {
id
author { login }
createdAt
isMinimized
minimizedReason
}
}
}
}
}`;
const variables = {
owner: owner,
repo: repo,
issueNum: issueNum,
};
let commentIds = [];
let botNames = ["github-actions[bot]", "HackforLABot"];
try {
const response = await github.graphql(query, variables);
let comments = response.repository.issue.comments.nodes || [];
for (let comment of comments) {
let created = new Date(comment.createdAt);
if (
botNames.includes(comment.author?.login) &&
created < tenDaysAgo &&
!comment.isMinimized
) {
commentIds.push(comment.id);
}
}
} catch (error) {
throw new Error(`Error retrieving comments for issue #${issueNum}: ${error}`);
}
return commentIds;
}
module.exports = getIssueComments;