diff --git a/.github/workflows/discord-notification.yml b/.github/workflows/discord-notification.yml new file mode 100644 index 0000000000..3efbdcbb17 --- /dev/null +++ b/.github/workflows/discord-notification.yml @@ -0,0 +1,18 @@ +name: "Send discord notification when a PR is ready for review" + +on: + pull_request: + types: + - opened + - ready_for_review + +jobs: + call_reusable_workflow: + if: github.event.pull_request.draft == false + uses: ./.github/workflows/shareable-discord-notification.yml + with: + PR_TITLE: ${{ github.event.pull_request.title }} + PR_URL: ${{ github.event.pull_request.html_url }} + PR_AUTHOR: ${{ github.event.pull_request.user.login }} + secrets: + DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_PR_REVIEWS_WEBHOOK }} diff --git a/.github/workflows/pr-opened.yml b/.github/workflows/pr-opened.yml deleted file mode 100644 index 8e098f1e3c..0000000000 --- a/.github/workflows/pr-opened.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: "Notify Discord on New PR (with Thread)" - -on: - pull_request: - types: - - opened - - ready_for_review - -jobs: - discord_notification: - # still guard out any drafts (just in case) - if: github.event.pull_request.draft == false - runs-on: ubicloud-standard-2 - steps: - - name: Send Discord notification and start a thread - env: - WEBHOOK_URL: ${{ secrets.DISCORD_PR_REVIEWS_WEBHOOK }} - PR_TITLE: ${{ github.event.pull_request.title }} - PR_URL: ${{ github.event.pull_request.html_url }} - PR_AUTHOR: ${{ github.event.pull_request.user.login }} - run: | - payload=$(jq -n \ - --arg content "${PR_URL}" \ - --arg thread "$PR_TITLE by \`${PR_AUTHOR}\`" \ - '{ - content: $content, - thread_name: $thread, - auto_archive_duration: 10080 - }' - ) - curl -H "Content-Type: application/json" \ - -X POST \ - --data "$payload" \ - "$WEBHOOK_URL" diff --git a/.github/workflows/shareable-discord-notification.yml b/.github/workflows/shareable-discord-notification.yml new file mode 100644 index 0000000000..f4fd942708 --- /dev/null +++ b/.github/workflows/shareable-discord-notification.yml @@ -0,0 +1,46 @@ +name: "Send discord notification when a PR is ready for review" + +on: + workflow_call: + inputs: + PR_TITLE: + description: "The title of the PR" + required: true + type: string + PR_URL: + description: "The URL of the PR" + required: true + type: string + PR_AUTHOR: + description: "The author of the PR" + required: true + type: string + secrets: + DISCORD_WEBHOOK_URL: + description: "Discord Webhook URL" + required: true + +jobs: + send_notification: + runs-on: ubicloud-standard-2 + steps: + - name: Send Discord notification and start a thread + env: + WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }} + PR_TITLE: ${{ inputs.PR_TITLE }} + PR_URL: ${{ inputs.PR_URL }} + PR_AUTHOR: ${{ inputs.PR_AUTHOR }} + run: | + payload=$(jq -n \ + --arg content "${PR_URL}" \ + --arg thread "$PR_TITLE by \`${PR_AUTHOR}\`" \ + '{ + content: $content, + thread_name: $thread, + auto_archive_duration: 10080 + }' + ) + curl -H "Content-Type: application/json" \ + -X POST \ + --data "$payload" \ + "$WEBHOOK_URL"