Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/discord-discussions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ jobs:
command -v discord_applied_tags >/dev/null 2>&1 || discord_applied_tags() { printf '[]'; }
command -v extract_discord_thread >/dev/null 2>&1 || extract_discord_thread() { :; }
command -v discord_archive_thread >/dev/null 2>&1 || discord_archive_thread() { :; }
command -v discord_set_tags >/dev/null 2>&1 || discord_set_tags() { :; }

NUMBER="${{ github.event.discussion.number }}"
OWNER="${REPO%/*}"
Expand Down Expand Up @@ -340,6 +341,10 @@ jobs:
FINAL_THREAD_ID="${DISCORD_THREAD_ID:-}"
[ -z "$FINAL_THREAD_ID" ] && FINAL_THREAD_ID="${WINNER_THREAD_ID:-}"
[ -z "$FINAL_THREAD_ID" ] && FINAL_THREAD_ID="${NEW_THREAD_ID:-}"
# Keep forum tags live (open/closed, answered/unanswered, category,
# label changes). Webhooks can't edit applied_tags after creation, so
# the bot re-applies them each event, before archiving.
discord_set_tags "$FINAL_THREAD_ID" "$APPLIED_TAGS"
if [ "$IS_CLOSED" = "true" ]; then
discord_archive_thread "$FINAL_THREAD_ID" true
else
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/discord-issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
command -v discord_applied_tags >/dev/null 2>&1 || discord_applied_tags() { printf '[]'; }
command -v extract_discord_thread >/dev/null 2>&1 || extract_discord_thread() { :; }
command -v discord_archive_thread >/dev/null 2>&1 || discord_archive_thread() { :; }
command -v discord_set_tags >/dev/null 2>&1 || discord_set_tags() { :; }

NUMBER="${{ github.event.issue.number }}"

Expand Down Expand Up @@ -235,6 +236,10 @@ jobs:
FINAL_THREAD_ID="${DISCORD_THREAD_ID:-}"
[ -z "$FINAL_THREAD_ID" ] && FINAL_THREAD_ID="${WINNER_THREAD_ID:-}"
[ -z "$FINAL_THREAD_ID" ] && FINAL_THREAD_ID="${NEW_THREAD_ID:-}"
# Keep forum tags live (open→closed, label changes). Webhooks can't edit
# applied_tags after creation, so the bot re-applies them each event.
# Done before archiving, while the thread is still active.
discord_set_tags "$FINAL_THREAD_ID" "$APPLIED_TAGS"
if [ "$STATE" = "open" ]; then
discord_archive_thread "$FINAL_THREAD_ID" false
else
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/discord-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ jobs:
command -v discord_applied_tags >/dev/null 2>&1 || discord_applied_tags() { printf '[]'; }
command -v extract_discord_thread >/dev/null 2>&1 || extract_discord_thread() { :; }
command -v discord_archive_thread >/dev/null 2>&1 || discord_archive_thread() { :; }
command -v discord_set_tags >/dev/null 2>&1 || discord_set_tags() { :; }

# ── Resolve PR number ────────────────────────────────────────────
if [ "$EVENT_NAME" = "pull_request" ] || [ "$EVENT_NAME" = "pull_request_target" ] || [ "$EVENT_NAME" = "pull_request_review" ]; then
Expand Down Expand Up @@ -337,6 +338,10 @@ jobs:
FINAL_THREAD_ID="${DISCORD_THREAD_ID:-}"
[ -z "$FINAL_THREAD_ID" ] && FINAL_THREAD_ID="${WINNER_THREAD_ID:-}"
[ -z "$FINAL_THREAD_ID" ] && FINAL_THREAD_ID="${NEW_THREAD_ID:-}"
# Keep forum tags live (open→closed→merged/draft, label changes).
# Webhooks can't edit applied_tags after creation, so the bot re-applies
# them each event. Done before archiving, while the thread is still active.
discord_set_tags "$FINAL_THREAD_ID" "$APPLIED_TAGS"
if [ "$PR_STATE" = "open" ]; then
discord_archive_thread "$FINAL_THREAD_ID" false
else
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/scripts/discord-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,22 @@ discord_archive_thread() {
-d "{\"archived\": ${archived}}" \
"https://discord.com/api/v10/channels/${thread_id}" || true
}

# ── Live forum tag sync ──────────────────────────────────────────────────
# discord_set_tags <thread_id> <applied_tags_json> — re-apply a forum thread's
# tags so they track the current state/labels (open→closed→merged, label adds).
# Webhooks can only set applied_tags at creation, so keeping them live needs a
# BOT token with Manage Threads/Posts. No-op unless DISCORD_GITHUB_BOT_TOKEN is
# set, a thread id is known, and the tag list is non-empty (an empty list means
# the channel has no tag config — never clobber it to untagged). Best-effort.
discord_set_tags() {
local thread_id="$1" tags="$2"
[ -z "${DISCORD_GITHUB_BOT_TOKEN:-}" ] && return 0
[ -z "$thread_id" ] && return 0
{ [ -z "$tags" ] || [ "$tags" = "[]" ]; } && return 0
curl -sS -o /dev/null --connect-timeout 10 --max-time 30 -X PATCH \
-H "Authorization: Bot ${DISCORD_GITHUB_BOT_TOKEN}" \
-H "Content-Type: application/json" \
-d "{\"applied_tags\": ${tags}}" \
"https://discord.com/api/v10/channels/${thread_id}" || true
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
}
Loading