PR number or branch name on pull_request type types close

I have some trouble to get the branch name and the pull request number on pull_request type close…

If I close a pull request, it works as expected, but If I merge the pull request, the GITHUB_REF value is set on ‘master’ and I cant do that anymore to retrieve the PR number : 

echo ::set-env name=PR_NUMBER::$(echo $GITHUB_REF | awk -F 'refs/pull/|/merge' '{print $2}')

It should always be available as part of the pull request event payload under “number”. So:

jobs:
  some-job:
    steps:
      - name: Show PR number
        env:
          PR_NUMBER: ${{ github.event.pull_request.number }}
        run: echo "The PR number is $PR_NUMBER"
2 Likes