Skip to content

Commit 7708de7

Browse files
committed
allow the warning message to change
1 parent ec05fb4 commit 7708de7

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,21 @@ rm -f discussions_page.json
136136
TOTAL_DISCUSSIONS=$(jq '.data.repository.discussions.nodes | length' discussions.json)
137137
echo "Fetched $TOTAL_DISCUSSIONS discussions across $PAGE_COUNT page(s)"
138138

139+
# Define the unique marker used to identify warning comments
140+
# This HTML comment is invisible to users but allows the script to reliably detect
141+
# warning comments even if the WARNING_MESSAGE text changes over time.
142+
# IMPORTANT: This marker must match the one in WARNING_MESSAGE in the workflow file.
143+
MARKER="<!-- stale-discussion-warning -->"
144+
139145
# Process discussions to close
140146
# A discussion should be closed if:
141-
# 1. It has a warning comment containing the configured WARNING_MESSAGE
147+
# 1. It has a warning comment containing the unique marker
142148
# 2. That warning comment was posted by the bot
143149
# 3. That warning comment is older than WARNING_DAYS
144150
# 4. The discussion hasn't been updated since the warning (or updates are also old)
145151
echo ""
146152
echo "=== Discussions to close - warned ${WARNING_DAYS}+ days ago with no activity ==="
147-
cat discussions.json | jq -r --arg warningCutoff "$CLOSE_CUTOFF" --arg warningMessage "$WARNING_MESSAGE" --arg botLogin "$BOT_LOGIN" '.data.repository.discussions.nodes[] | select(.closed == false) | . as $discussion | ((.comments.nodes // []) | map(select(.body | contains($warningMessage)) | select(.author.login == $botLogin)) | last) as $warningComment | select($warningComment != null) | select($warningComment.createdAt < $warningCutoff) | select($discussion.updatedAt <= $warningComment.createdAt) | @json' | while IFS= read -r discussion; do
153+
cat discussions.json | jq -r --arg warningCutoff "$CLOSE_CUTOFF" --arg marker "$MARKER" --arg botLogin "$BOT_LOGIN" '.data.repository.discussions.nodes[] | select(.closed == false) | . as $discussion | ((.comments.nodes // []) | map(select(.body | contains($marker)) | select(.author.login == $botLogin)) | last) as $warningComment | select($warningComment != null) | select($warningComment.createdAt < $warningCutoff) | select($discussion.updatedAt <= $warningComment.createdAt) | @json' | while IFS= read -r discussion; do
148154
if [ -n "$discussion" ]; then
149155
DISCUSSION_ID=$(echo "$discussion" | jq -r '.id')
150156
DISCUSSION_NUMBER=$(echo "$discussion" | jq -r '.number')
@@ -191,11 +197,11 @@ done
191197
# A discussion should be warned if:
192198
# 1. It hasn't been updated in STALE_DAYS
193199
# 2. Either:
194-
# a. It doesn't have a warning comment from the bot yet, OR
200+
# a. It doesn't have a warning comment (with unique marker) from the bot yet, OR
195201
# b. It has a warning from the bot but was updated after that warning (user responded, so we warn again)
196202
echo ""
197203
echo "=== Discussions to warn - stale for ${STALE_DAYS}+ days, not yet warned ==="
198-
cat discussions.json | jq -r --arg staleCutoff "$STALE_CUTOFF" --arg warningMessage "$WARNING_MESSAGE" --arg botLogin "$BOT_LOGIN" '.data.repository.discussions.nodes[] | select(.closed == false) | select(.updatedAt < $staleCutoff) | . as $discussion | ((.comments.nodes // []) | map(select(.body | contains($warningMessage)) | select(.author.login == $botLogin)) | last) as $warningComment | select($warningComment == null or $discussion.updatedAt > $warningComment.createdAt) | @json' | while IFS= read -r discussion; do
204+
cat discussions.json | jq -r --arg staleCutoff "$STALE_CUTOFF" --arg marker "$MARKER" --arg botLogin "$BOT_LOGIN" '.data.repository.discussions.nodes[] | select(.closed == false) | select(.updatedAt < $staleCutoff) | . as $discussion | ((.comments.nodes // []) | map(select(.body | contains($marker)) | select(.author.login == $botLogin)) | last) as $warningComment | select($warningComment == null or $discussion.updatedAt > $warningComment.createdAt) | @json' | while IFS= read -r discussion; do
199205
if [ -n "$discussion" ]; then
200206
DISCUSSION_ID=$(echo "$discussion" | jq -r '.id')
201207
DISCUSSION_NUMBER=$(echo "$discussion" | jq -r '.number')

0 commit comments

Comments
 (0)