name: Commands
on:
  issue_comment:
    types:
      - created
      - edited

jobs:
  rebase:
    name: Rebase
    if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '@jellyfin-bot rebase') && github.event.comment.author_association == 'MEMBER'
    runs-on: ubuntu-latest
    steps:
      - name: Notify as seen
        uses: peter-evans/create-or-update-comment@c6c9a1a66007646a28c153e2a8580a5bad27bcfa # v3.0.2
        with:
          token: ${{ secrets.JF_BOT_TOKEN }}
          comment-id: ${{ github.event.comment.id }}
          reactions: '+1'
      - name: Checkout the latest code
        uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
        with:
          token: ${{ secrets.JF_BOT_TOKEN }}
          fetch-depth: 0
      - name: Automatic Rebase
        uses: cirrus-actions/rebase@b87d48154a87a85666003575337e27b8cd65f691 # 1.8
        env:
          GITHUB_TOKEN: ${{ secrets.JF_BOT_TOKEN }}
      - name: Comment on failure
        if: failure()
        uses: peter-evans/create-or-update-comment@c6c9a1a66007646a28c153e2a8580a5bad27bcfa # v3.0.2
        with:
          token: ${{ secrets.JF_BOT_TOKEN }}
          issue-number: ${{ github.event.issue.number }}
          body: |
            I'm sorry @${{ github.event.comment.user.login }}, I'm afraid I can't do that.
