name: Create discord thread when a PR is opened, react with green checkmark when PR is merged

on:
  pull_request:
    types:
      - opened
      - ready_for_review
      - closed
  issue_comment:
    types:
      - created
      - edited

jobs:
  notify_discord_when_pr_opened:
    if: (github.event.pull_request.draft == false) && (github.event.action == 'opened' || github.event.action == 'ready_for_review')
    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 }}
      PR_STATUS: "opened"
      PR_NUMBER: ${{ github.event.pull_request.number }}
      DISCORD_CHANNEL_ID: "1372204995868491786"
      DISCORD_GUILD_ID: "930051556043276338"
    secrets:
      DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_PR_REVIEWS_WEBHOOK }}
      DISCORD_BOT_TOKEN: ${{ secrets.DISCORD_AI_BOT_TOKEN }}

  merge_success_emoji:
    if: github.event.action == 'closed'
    uses: ./.github/workflows/shareable-discord-notification.yml
    with:
      PR_STATUS: "merged"
      DISCORD_CHANNEL_ID: "1372204995868491786"
      DISCORD_GUILD_ID: "930051556043276338"
      PR_NUMBER: ${{ github.event.pull_request.number }}
    secrets:
      DISCORD_BOT_TOKEN: ${{ secrets.DISCORD_AI_BOT_TOKEN }}

  notify_discord_on_comment:
    if: >
      github.event_name == 'issue_comment'
      && github.event.issue.pull_request
      && github.event.comment.user.login != 'cloudflare-workers-and-pages[bot]'
      && github.event.comment.user.login != 'ellipsis-dev[bot]'
    uses: ./.github/workflows/shareable-discord-notification.yml
    with:
      PR_STATUS: "comment"
      PR_NUMBER: ${{ github.event.issue.number }}
      COMMENT_BODY: ${{ github.event.comment.body }}
      COMMENT_AUTHOR: ${{ github.event.comment.user.login }}
      COMMENT_URL: ${{ github.event.comment.html_url }}
      COMMENT_IS_EDIT: ${{ github.event.action == 'edited' }}
      DISCORD_CHANNEL_ID: "1372204995868491786"
      DISCORD_GUILD_ID: "930051556043276338"
    secrets:
      DISCORD_BOT_TOKEN: ${{ secrets.DISCORD_AI_BOT_TOKEN }}
