From bb762d72547d3c4af92ee92665f4415ea6faedbd Mon Sep 17 00:00:00 2001 From: "CanbiZ (MickLesk)" <47820557+MickLesk@users.noreply.github.com> Date: Tue, 28 Apr 2026 10:56:16 +0200 Subject: [PATCH] switch discord bot Co-authored-by: Copilot --- .../create-ready-for-testing-message.yml | 20 +++- .github/workflows/defer-discord-thread.yml | 92 +++++++++++++++++++ 2 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/defer-discord-thread.yml diff --git a/.github/workflows/create-ready-for-testing-message.yml b/.github/workflows/create-ready-for-testing-message.yml index 65842cec..2974f480 100644 --- a/.github/workflows/create-ready-for-testing-message.yml +++ b/.github/workflows/create-ready-for-testing-message.yml @@ -170,10 +170,26 @@ jobs: if [ -n "$THREAD_ID" ]; then echo "thread_exists=true" >> "$GITHUB_OUTPUT" + echo "thread_id=$THREAD_ID" >> "$GITHUB_OUTPUT" else echo "thread_exists=false" >> "$GITHUB_OUTPUT" fi + - name: Unlock existing Discord thread (re-labeled after deferral) + if: steps.check_thread.outputs.thread_exists == 'true' + run: | + curl -s -X PATCH "https://discord.com/api/v10/channels/${{ steps.check_thread.outputs.thread_id }}" \ + -H "Authorization: Bot ${{ secrets.DISCORD_BOT_TOKEN }}" \ + -H "Content-Type: application/json" \ + -d '{"locked": false}' + + - name: Unlock GitHub issue (re-labeled after deferral) + if: steps.check_thread.outputs.thread_exists == 'true' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh api --method DELETE /repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/lock || true + - name: Create a forumpost in Discord if: steps.check_thread.outputs.thread_exists != 'true' id: post_to_discord @@ -197,10 +213,6 @@ jobs: STATUS_CODE=$(echo "$RESPONSE" | tail -n 1) if [[ "$HTTP_CODE" == "201" && -n "$THREAD_ID" ]]; then - LOCK_RESPONSE=$(curl -s -X PATCH "https://discord.com/api/v10/channels/$THREAD_ID" \ - -H "Authorization: Bot $DISCORD_BOT_TOKEN" \ - -H "Content-Type: application/json" \ - -d '{"locked": true}') echo "Discord post created successfully!" else echo "Response: $RESPONSE" diff --git a/.github/workflows/defer-discord-thread.yml b/.github/workflows/defer-discord-thread.yml new file mode 100644 index 00000000..7e37b5d0 --- /dev/null +++ b/.github/workflows/defer-discord-thread.yml @@ -0,0 +1,92 @@ +name: Lock Discord Thread and GitHub Issue on Deferral + +on: + issues: + types: + - labeled + - unlabeled + +permissions: + issues: write + +jobs: + defer_discord_thread: + runs-on: ubuntu-latest + if: | + github.repository == 'community-scripts/ProxmoxVED' && ( + (github.event.action == 'labeled' && github.event.label.name == 'deferred') || + (github.event.action == 'unlabeled' && github.event.label.name == 'Ready For Testing') + ) + steps: + - name: Find Discord thread + id: find_thread + run: | + ISSUE_TITLE="${{ github.event.issue.title }}" + + THREAD_ID=$(curl -s "https://discord.com/api/v10/guilds/${{ secrets.DISCORD_GUILD_ID }}/threads/active" \ + -H "Authorization: Bot ${{ secrets.DISCORD_BOT_TOKEN }}" \ + -H "Content-Type: application/json" | \ + jq -r --arg TITLE "$ISSUE_TITLE" --arg PARENT_ID "${{ secrets.DISCORD_CHANNEL_ID }}" \ + '.threads[] | select(.parent_id == $PARENT_ID and .name == ("Wanted Tester for " + $TITLE)) | .id') + + if [ -n "$THREAD_ID" ]; then + echo "Found thread: $THREAD_ID" + echo "thread_id=$THREAD_ID" >> "$GITHUB_OUTPUT" + else + echo "No Discord thread found for: $ISSUE_TITLE" + fi + + - name: Get last GitHub issue comment + if: steps.find_thread.outputs.thread_id != '' + id: last_comment + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + LAST=$(gh issue view ${{ github.event.issue.number }} \ + --repo ${{ github.repository }} \ + --comments \ + --json comments \ + --jq '.comments[-1].body // empty') + + if [[ -z "$LAST" ]]; then + LAST=$(gh issue view ${{ github.event.issue.number }} \ + --repo ${{ github.repository }} \ + --json body \ + --jq '.body') + fi + + { + echo "last_comment<> "$GITHUB_OUTPUT" + + - name: Post deferral notice to Discord thread + if: steps.find_thread.outputs.thread_id != '' + env: + DISCORD_BOT_TOKEN: ${{ secrets.DISCORD_BOT_TOKEN }} + THREAD_ID: ${{ steps.find_thread.outputs.thread_id }} + LAST_COMMENT: ${{ steps.last_comment.outputs.last_comment }} + ISSUE_URL: ${{ github.event.issue.html_url }} + run: | + MESSAGE="$(printf '⏸️ **This script has been deferred.**\n\nLast update from the issue:\n\n%s\n\n🔗 %s' "$LAST_COMMENT" "$ISSUE_URL")" + JSON_PAYLOAD=$(jq -n --arg content "$MESSAGE" '{content: $content}') + curl -s -X POST "https://discord.com/api/v10/channels/$THREAD_ID/messages" \ + -H "Authorization: Bot $DISCORD_BOT_TOKEN" \ + -H "Content-Type: application/json" \ + -d "$JSON_PAYLOAD" + + - name: Lock Discord thread + if: steps.find_thread.outputs.thread_id != '' + run: | + curl -s -X PATCH "https://discord.com/api/v10/channels/${{ steps.find_thread.outputs.thread_id }}" \ + -H "Authorization: Bot ${{ secrets.DISCORD_BOT_TOKEN }}" \ + -H "Content-Type: application/json" \ + -d '{"locked": true}' + + - name: Lock GitHub issue + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh api --method PUT /repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/lock \ + -f lock_reason=resolved