name: Commands
on:
  issue_comment:
    types:
      - created
      - edited
  pull_request_target:
    types:
      - labeled
      - synchronize

permissions: {}
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@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0
        with:
          token: ${{ secrets.JF_BOT_TOKEN }}
          comment-id: ${{ github.event.comment.id }}
          reactions: '+1'

      - name: Checkout the latest code
        uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
        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 }}

  rename:
    name: Rename
    if: contains(github.event.comment.body, '@jellyfin-bot rename') && github.event.comment.author_association == 'MEMBER'
    runs-on: ubuntu-latest
    steps:
      - name: pull in script
        uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
        with:
          repository: jellyfin/jellyfin-triage-script
      - name: install python
        uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
        with:
          python-version: '3.14'
          cache: 'pip'
      - name: install python packages
        run: pip install -r rename/requirements.txt
      - name: run rename script
        run: python3 rename.py
        working-directory: ./rename
        env:
          GH_TOKEN: ${{ secrets.JF_BOT_TOKEN }}
          GH_REPO: ${{ github.repository }}
          ISSUE: ${{ github.event.issue.number }}
          COMMENT_ID: ${{ github.event.comment.id }}
