Skip to content

Commit dd47baf

Browse files
mvadariCopilotTapanito
authored
Discussion management (#426)
Co-authored-by: Copilot <[email protected]> Co-authored-by: Vito Tumas <[email protected]>
1 parent 8f203a0 commit dd47baf

File tree

4 files changed

+530
-0
lines changed

4 files changed

+530
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Filter discussions that should be closed
2+
# A discussion should be closed if:
3+
# 1. It has a warning comment containing the unique marker
4+
# 2. That warning comment was posted by the bot
5+
# 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)
7+
#
8+
# Input: GraphQL response with discussions data
9+
# Arguments:
10+
# $warningCutoff - ISO 8601 timestamp for warning age threshold
11+
# $marker - Unique marker string to identify warning comments
12+
# $botLogin - GitHub login of the bot user
13+
# Output: JSON objects (one per line) for discussions that should be closed
14+
15+
.data.repository.discussions.nodes[]
16+
17+
# Only process open discussions
18+
| select(.closed == false)
19+
20+
# Store the discussion for later reference
21+
| . as $discussion
22+
23+
# Find the most recent warning comment from the bot
24+
# Note: We only look at the last 100 comments (fetched by the shell script).
25+
# This is intentional - if there are 100+ comments after a warning, the discussion
26+
# is clearly active and should not be closed.
27+
| (
28+
(.comments.nodes // [])
29+
| map(
30+
select(.body | contains($marker))
31+
| select(.author.login == $botLogin)
32+
)
33+
| last
34+
) as $warningComment
35+
36+
# Only proceed if a warning comment exists
37+
| select($warningComment != null)
38+
39+
# Only proceed if the warning comment is old enough
40+
| select($warningComment.createdAt <= $warningCutoff)
41+
42+
# Only proceed if the discussion hasn't been updated since the warning
43+
| select($discussion.updatedAt < $warningComment.createdAt)
44+
45+
# Output as JSON
46+
| @json
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Filter discussions that should receive a warning
2+
# A discussion should be warned if:
3+
# 1. It hasn't been updated in STALE_DAYS
4+
# 2. Either:
5+
# a. It doesn't have a warning comment (with unique marker) from the bot yet, OR
6+
# b. It has a warning from the bot but was updated after that warning (user responded, so we warn again)
7+
#
8+
# Input: GraphQL response with discussions data
9+
# Arguments:
10+
# $staleCutoff - ISO 8601 timestamp for staleness threshold
11+
# $marker - Unique marker string to identify warning comments
12+
# $botLogin - GitHub login of the bot user
13+
# Output: JSON objects (one per line) for discussions that should be warned
14+
15+
.data.repository.discussions.nodes[]
16+
17+
# Only process open discussions
18+
| select(.closed == false)
19+
20+
# Only process discussions that are stale (not updated recently)
21+
| select(.updatedAt < $staleCutoff)
22+
23+
# Store the discussion for later reference
24+
| . as $discussion
25+
26+
# Find the most recent warning comment from the bot
27+
# Note: We only look at the last 100 comments (fetched by the shell script).
28+
# This is intentional - if there are 100+ comments after a warning, the discussion
29+
# is clearly active and should not be warned again.
30+
| (
31+
(.comments.nodes // [])
32+
| map(
33+
select(.body | contains($marker))
34+
| select(.author.login == $botLogin)
35+
)
36+
| last
37+
) as $warningComment
38+
39+
# Only proceed if:
40+
# - No warning comment exists yet, OR
41+
# - Discussion was updated after the last warning (user responded)
42+
| select(
43+
$warningComment == null
44+
or $discussion.updatedAt > $warningComment.createdAt
45+
)
46+
47+
# Output as JSON
48+
| @json

0 commit comments

Comments
 (0)