gh-find-current-pr
gh-find-current-pr copied to clipboard
Find pr during workflow triggered by push after rebase merge
This is what I found to work. It's not fool-proof as the same commit message could occur more than once and have been in more than one pr.
- name: Find PR
id: find_pr
env:
GH_TOKEN: ${{ github.token }}
run: |
prs=$(gh pr list --search "${{ github.event.head_commit.message }}" --state merged)
number=$(echo $prs | cut -d ' ' -f 1)
echo "number=$number" >> $GITHUB_OUTPUT
It would be nice if this action could be made to accommodate this situation. If I get time, I'll take a look at the source to see if there's a sane way to add it.
Fun facts:
- due to rebase, the commit sha has changed and the new one was never tied to a pr
- the topic branch may already be deleted (as it is in my case)
- searching the reflog you'd still end up having to use the message at some point afaict