name: Backport
on:
  pull_request_target:
    types:
      - closed
      - labeled

permissions:
  contents: read

jobs:
  backport:
    runs-on: ubuntu-latest
    name: Backport

    permissions:
      pull-requests: write

    # Adapt https://github.com/m-kuhn/backport
    steps:
      - name: Backport Bot
        id: backport
        if: github.event.pull_request.merged && ( ( github.event.action == 'closed' && contains( join( github.event.pull_request.labels.*.name ), 'backport') ) || contains( github.event.label.name, 'backport' ) )
        uses: m-kuhn/backport@7f3cab83e4b3b26aefcffda21851c3dc3d389f45 # v1.2.7
        with:
          github_token: ${{ secrets.BACKPORT_TOKEN }}
