name: Post to Mastodon on PR Merge

on:
  pull_request:
    branches:
      - main
    types:
      - closed

permissions:
  pull-requests: read

jobs:
  post_to_mastodon:
    if: github.event.pull_request.merged == true
    runs-on: ubuntu-latest
    steps:
      - name: Post to Mastodon
        uses: nick-fields/retry@v2
        with:
          timeout_minutes: 2
          max_attempts: 3
          run: |
            git checkout ${{ github.event.pull_request.head.sha }}
            export MASTODONBOT="${{ secrets.MASTODONBOT }}"
            export PR_TITLE="${{ github.event.pull_request.title }}"
            ./post_to_mastodon.sh