This repository has been archived by the owner on Dec 20, 2024. It is now read-only.
Auto Lock Stale Discussions #2035
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |