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
62 lines (58 loc) · 2.09 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
57
58
59
60
61
62
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: '45 * * * *'
workflow_dispatch:
jobs:
close_discussion:
runs-on: ubuntu-latest
steps:
- name: get-stale-discussions
id: get-stale-discussions
run: |
staleDiscussionsQuery="repo:vercel/community updated:<$(date -d "-1days" -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
}
}
addDiscussionComment(input: {discussionId: $discussionId, body: "This discussion was automatically locked because the community moved to a new site. Please join us at [vercel.community](https://vercel.community)"}) {
comment {
body
}
}
}
' --jq '.data.lockLockable.lockedRecord.locked')"
echo "Locked $id: $lockSucceeded"
done
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}