Get PR Number when using manually trigger the workflow

Is there an easy way to get the PR number in the jobs when using the workflow_dispatch trigger?
In this case, the event that triggers is not a pull_request, therefore some properties are not set in the GitHub context.

I know that I could use the input to send the PR number, but that is not the perfect solution for me.

How would a workflow_dispatched job know it should operate on a PR at all?

Hi @tiagoramalho,

Glad to see you in Github Community Forum!

Do you mean in your workflow_dispatch event, to get the number of the PR which related to the branch? You can get it from pull request rest api, parse(eg: head or base branch) to get the number:

For example, to get the pull request number whose head branch is the current branch:

curl -s -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${{github.repository}}/pulls?head=${{github.repository_owner}}:${{github.ref}} | jq -r '.[] | .number'


Thanks

1 Like