name: Bounty completed
description: Awards points and notifies Discord when a bounty PR is merged

on:
  pull_request_target:
    types: [closed]

  workflow_dispatch:
    inputs:
      pr_number:
        description: "PR number to process (for missed bounties)"
        required: true
        type: number

jobs:
  bounty-notify:
    if: >
      github.event_name == 'workflow_dispatch' ||
      (github.event.pull_request.merged == true &&
       contains(join(github.event.pull_request.labels.*.name, ','), 'bounty:'))
    runs-on: ubuntu-latest
    timeout-minutes: 5
    permissions:
      contents: read
      pull-requests: read

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Setup Bun
        uses: oven-sh/setup-bun@v2
        with:
          bun-version: latest

      - name: Award XP and notify Discord
        run: bun run scripts/bounty-tracker.ts notify
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
          GITHUB_REPOSITORY_NAME: ${{ github.event.repository.name }}
          DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_BOUNTY_WEBHOOK_URL }}
          BOT_API_URL: ${{ secrets.BOT_API_URL }}
          BOT_API_KEY: ${{ secrets.BOT_API_KEY }}
          LURKR_API_KEY: ${{ secrets.LURKR_API_KEY }}
          LURKR_GUILD_ID: ${{ secrets.LURKR_GUILD_ID }}
          PR_NUMBER: ${{ inputs.pr_number || github.event.pull_request.number }}
