11# Find details about the PR associated with this ref
2- # Outputs:
3- # prnumber: the ID number of the associated PR
4- # headref: the name of the head branch of the PR
5- # baseref: the name of the base branch of the PR
62name : PR Details
73on :
84 workflow_call :
1814 outputs :
1915 pr_id :
2016 description : The ID of the PR found
21- value : ${{ jobs.prdetails.outputs.pr_id }}
17+ value : ${{ fromJSON( jobs.prdetails.outputs.result).number }}
2218 head_branch :
2319 description : The head branch of the PR found
24- value : ${{ jobs.prdetails.outputs.head_branch }}
20+ value : ${{ fromJSON( jobs.prdetails.outputs.result).head.ref }}
2521 base_branch :
2622 description : The base branch of the PR found
27- value : ${{ jobs.prdetails.outputs.base_branch }}
23+ value : ${{ fromJSON(jobs.prdetails.outputs.result).base.ref }}
24+ data :
25+ description : The JSON data of the pull request API object
26+ value : ${{ jobs.prdetails.outputs.result }})
2827
2928jobs :
3029 prdetails :
@@ -33,27 +32,18 @@ jobs:
3332 steps :
3433 - name : " 🔍 Read PR details"
3534 id : details
36- # We need to find the PR number that corresponds to the branch, which we do by searching the GH API
37- # The workflow_run event includes a list of pull requests, but it doesn't get populated for
38- # forked PRs: https://docs.github.com/en/rest/reference/checks#create-a-check-run
39- run : |
40- head_branch='${{ inputs.owner }}:${{ inputs.branch }}'
41- echo "Head branch: $head_branch"
42- pulls_uri="https://api.github.com/repos/${{ github.repository }}/pulls?head=$(jq -Rr '@uri' <<<$head_branch)"
43- pr_data=$(curl -s -H 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' "$pulls_uri")
44-
45- pr_number=$(jq -r '.[] | .number' <<< "$pr_data")
46- echo "PR number: $pr_number"
47- echo "::set-output name=prnumber::$pr_number"
48-
49- head_ref=$(jq -r '.[] | .head.ref' <<< "$pr_data")
50- echo "Head ref: $head_ref"
51- echo "::set-output name=headref::$head_ref"
52-
53- base_ref=$(jq -r '.[] | .base.ref' <<< "$pr_data")
54- echo "Base ref: $base_ref"
55- echo "::set-output name=baseref::$base_ref"
35+ uses : actions/github-script@v5
36+ with :
37+ # We need to find the PR number that corresponds to the branch, which we do by searching the GH API
38+ # The workflow_run event includes a list of pull requests, but it doesn't get populated for
39+ # forked PRs: https://docs.github.com/en/rest/reference/checks#create-a-check-run
40+ script : |
41+ const [owner, repo] = "${{ github.repository }}".split("/");
42+ const response = await github.rest.pulls.list({
43+ head: "${{ inputs.owner }}:${{ inputs.branch }}",
44+ owner,
45+ repo,
46+ });
47+ return response.data[0];
5648 outputs :
57- pr_id : ${{ steps.details.outputs.prnumber }}
58- head_branch : ${{ steps.details.outputs.headref }}
59- base_branch : ${{ steps.details.outputs.baseref }}
49+ result : ${{ steps.details.outputs.result }}
0 commit comments