Github ActionsでPRが作成されたときにそのブランチ名を取得する

単純にブランチ名を取得しても remotes/pull/10/merge のような形で自分が作成したブランチ名とは違っていました。 コミットハッシュ値も違うのでベースブランチとPRしたブランチをマージしたものとかなんでしょうか?

PRの最後のコミットハッシュ値github.event.pull_request.head.sha で取得できるのでそこからブランチ名を特定する方法にしたところ無事ブランチ名が取得できました。

name: pr_opened

on:
  pull_request:
    types:
      - opened

jobs:
  comment:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Create comment
      env:
        PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
      run: |
        git fetch --no-tags --depth=1 origin
        HASH_AND_BRANCH=`git name-rev ${PR_HEAD_SHA}`
        BRANCH=`echo "${HASH_AND_BRANCH##*remotes/origin/}"`
        echo "PR Opened" >> comments
        echo "Branch name: ${BRANCH}" >> comments
        sed -i -z 's/\n/\\n/g' comments
    - name: Post comment
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        URL: ${{ github.event.pull_request.comments_url }}
      run: |
        curl -X POST \
             -H "Authorization: token ${GITHUB_TOKEN}" \
             -d "{\"body\": \"$(cat comments)\"}" \
             ${URL}

github.com