name: Sync Pull Request
on:
  pull_request_target:
    types: [labeled]

jobs:
  sync_pull_request:
    runs-on: ubuntu-latest
    if: contains(github.event.pull_request.labels.*.name, 'ci sync')
    steps:
      - name: Remove label
        run: |
          # The label is always removed so that this action can be triggered
          # again by adding the label even if the sync fails.

          curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -X "DELETE" https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/ci%20sync
      - uses: actions/checkout@v2
        with:
          fetch-depth: '0'
      - name: Sync with master
        env:
          # Assign the contributor-specified branch name to an environment
          # variable to sanitize it and avoid arbitrary bash code injection by
          # non-privileged users.
          HEAD_REF: ${{ github.event.pull_request.head.ref }}
        run: |
          set -xe
          git remote add pr_remote ${{ github.event.pull_request.head.repo.html_url }}
          git fetch pr_remote $HEAD_REF
          git checkout -b pr_branch pr_remote/$HEAD_REF
          git config user.name github-actions
          git config user.email github-actions@github.com
          git merge origin/master
          git push pr_remote HEAD:${{ github.event.pull_request.head.ref }}

name: Sync Pull Request
on:
  pull_request_target:
    types: [labeled]

jobs:
  sync_pull_request:
    runs-on: ubuntu-latest
    if: contains(github.event.pull_request.labels.*.name, 'ci sync')
    steps:
      - name: Remove label
        run: |
          # The label is always removed so that this action can be triggered
          # again by adding the label even if the sync fails.

          curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -X "DELETE" https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/ci%20sync
      - uses: actions/checkout@v2
        with:
          fetch-depth: '0'
      - name: Sync with master
        env:
          # Assign the contributor-specified branch name to an environment
          # variable to sanitize it and avoid arbitrary bash code injection by
          # non-privileged users.
          PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
        run: |
          set -xe
          git remote add pr_remote ${{ github.event.pull_request.head.repo.html_url }}
          git fetch pr_remote $PR_HEAD_REF
          git checkout -b pr_branch pr_remote/$PR_HEAD_REF
          git config user.name github-actions
          git config user.email github-actions@github.com
          git merge origin/master
          git push pr_remote HEAD:$PR_HEAD_REF

Fix missing occurrence of branch name
Fix missing occurrence of branch name
