-
Notifications
You must be signed in to change notification settings - Fork 1
58 lines (52 loc) · 1.72 KB
/
close-answered-discussions.yml
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
name: Close Answered Discussions
on:
schedule:
- cron: "0 0 * * 1" # Runs every Monday at midnight
jobs:
close-answered-discussions:
runs-on: ubuntu-latest
steps:
- name: Close Answered Discussions
uses: actions/github-script@v6
with:
github-token: ${{ secrets.DISCUSSIONS_CLOSER }}
script: |
const { graphql } = github;
const query = `{
repository(owner: "deepgram", name: "community") {
discussions(first: 100, states: [OPEN]) {
nodes {
id
title
number
isAnswered
url
}
}
}
}`;
const result = await graphql(query, {
headers: {
authorization: `token ${{ secrets.DISCUSSIONS_CLOSER }}`
}
});
// Loop through the discussions and close the ones marked as answered
for (const discussion of result.repository.discussions.nodes) {
if (discussion.isAnswered) {
console.log(`Closing answered discussion: ${discussion.title} (${discussion.url})`);
await graphql(`
mutation($id: ID!) {
closeDiscussion(input: {discussionId: $id}) {
discussion {
title
}
}
}
`, {
headers: {
authorization: `token ${{ secrets.DISCUSSIONS_CLOSER }}`
},
id: discussion.id
});
}
}