name: Typecho Hotfix Merge

on:
  pull_request:
    types:
      - closed
      - labeled
    branches:
      - master

jobs:
  auto-merge:
    if: github.event.action == 'closed' && github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'fix/')
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - name: Merge to dev branch
        uses: devmasx/merge-branch@master
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          from_branch: ${{ github.event.pull_request.head.ref }}
          target_branch: dev
    
  label-merge:
    if: github.event.action == 'labeled' && !startsWith(github.event.pull_request.head.ref, 'fix/')
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - name: Merge to dev branch
        uses: devmasx/merge-branch@master
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          label_name: 'merge-to-dev'
          target_branch: dev