This repository has been archived by the owner on Dec 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
56 lines (52 loc) · 1.8 KB
/
lock-stale-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
name: Auto Lock Stale Discussions
# lock discussions that have not been updated in 30 days,
# starting with oldest, and running once per day
on:
schedule:
- cron: '0 0 * * *' # Runs every day at midnight UTC
jobs:
close_discussion:
runs-on: ubuntu-latest
steps:
- name: get-stale-discussions
id: get-stale-discussions
run: |
staleDiscussionsQuery="repo:amyegan/community-test updated:<$(date -d "-30days" -I) sort:updated-asc is:unlocked"
discussions=$(gh api graphql -F searchQuery="$staleDiscussionsQuery" -f query='
query oldDiscussions($searchQuery: String!) {
search(query:$searchQuery, type:DISCUSSION, first: 20) {
nodes {
... on Discussion {
id
locked
url
}
}
}
}
' --jq '.data.search.nodes')
echo "DISCUSSIONS_TO_LOCK=$discussions" >> $GITHUB_ENV
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: lock-discussions
run: |
echo "$DISCUSSIONS_TO_LOCK" | jq -r '"Closing \(length) stale discussions: "'
for id in $(jq -r '.[].id' <<< "$DISCUSSIONS_TO_LOCK")
do
lockSucceeded="$(gh api graphql -F discussionId=$id -f query='
mutation lock($discussionId:ID!) {
lockLockable(input: {lockableId:$discussionId}) {
actor {
login
}
lockedRecord {
activeLockReason
locked
}
}
}
' --jq '.data.lockLockable.lockedRecord.locked')"
echo "Locked $id: $lockSucceeded"
done
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}