Skip to content

Commit 2f87a23

Browse files
authored
fix: discussions not closing after 30 days of being stale (#481)
1 parent 6280022 commit 2f87a23

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

.github/scripts/filter-discussions-to-close.jq

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# 1. It has a warning comment containing the unique marker
44
# 2. That warning comment was posted by the bot
55
# 3. That warning comment is older than WARNING_DAYS
6-
# 4. The discussion hasn't been updated since the warning (or updates are also old)
6+
# 4. There are no comments from non-bot users after the warning
77
#
88
# Input: GraphQL response with discussions data
99
# Arguments:
@@ -39,8 +39,20 @@
3939
# Only proceed if the warning comment is old enough
4040
| select($warningComment.createdAt <= $warningCutoff)
4141

42-
# Only proceed if the discussion hasn't been updated since the warning
43-
| select($discussion.updatedAt < $warningComment.createdAt)
42+
# Check if there are any comments from non-bot users after the warning
43+
# Note: We can't rely on updatedAt because the bot's warning comment itself
44+
# updates the discussion's updatedAt timestamp
45+
| (
46+
(.comments.nodes // [])
47+
| map(
48+
select(.createdAt > $warningComment.createdAt)
49+
| select(.author.login != $botLogin)
50+
)
51+
| length
52+
) as $nonBotCommentsAfterWarning
53+
54+
# Only proceed if there are no comments from non-bot users after the warning
55+
| select($nonBotCommentsAfterWarning == 0)
4456

4557
# Output as JSON
4658
| @json

.github/scripts/process-stale-discussions.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,11 @@ echo ""
131131
echo "Bot login: $BOT_LOGIN"
132132

133133
# Verify bot login is accessible
134-
if ! BOT_INFO=$(gh api /users/$BOT_LOGIN 2>&1); then
135-
echo "Warning: Could not verify bot user '$BOT_LOGIN'" >&2
134+
# Note: The REST API uses the [bot] suffix for GitHub App bots, while the GraphQL API
135+
# returns author.login without the suffix. We verify using the [bot] suffix.
136+
BOT_LOGIN_FOR_REST="${BOT_LOGIN}[bot]"
137+
if ! BOT_INFO=$(gh api "/users/$BOT_LOGIN_FOR_REST" 2>&1); then
138+
echo "Warning: Could not verify bot user '$BOT_LOGIN_FOR_REST'" >&2
136139
echo "The script will continue, but make sure BOT_LOGIN is correct." >&2
137140
echo "API Response: $BOT_INFO" >&2
138141
else

.github/workflows/discussions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
- name: Fetch and process stale discussions
4343
env:
4444
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
45-
BOT_LOGIN: ${{ steps.generate_token.outputs.app-slug }}[bot]
45+
BOT_LOGIN: ${{ steps.generate_token.outputs.app-slug }}
4646
STALE_DAYS: ${{ env.STALE_DAYS }}
4747
WARNING_DAYS: ${{ env.WARNING_DAYS }}
4848
WARNING_MESSAGE: ${{ env.WARNING_MESSAGE }}

0 commit comments

Comments
 (0)