Skip to content

Commit

Permalink
fix: repository determination without explicit checkout (#18)
Browse files Browse the repository at this point in the history
* fix: repository determination without explicit checkout

* fix: dynamic determinal of commit SHA
  • Loading branch information
rdhar authored Feb 26, 2025
1 parent 2c860e4 commit dfc0b0c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ runs:
# Get PR number using GitHub API for different event triggers.
if [[ "$GITHUB_EVENT_NAME" == "push" ]]; then
# List PRs associated with the commit, then get the PR number from the head ref or the latest PR.
associated_prs=$(gh api /repos/{owner}/{repo}/commits/${GITHUB_SHA}/pulls --header "$GH_API" --method GET --field per_page=100)
associated_prs=$(gh api /repos/${{ github.repository }}/commits/${{ github.event.pull_request.head.sha || github.sha }}/pulls --header "$GH_API" --method GET --field per_page=100)
number=$(echo "$associated_prs" | jq --raw-output '(.[] | select(.head.ref == env.GITHUB_REF_NAME) | .number) // .[0].number // 0')
elif [[ "$GITHUB_EVENT_NAME" == "merge_group" ]]; then
# Get the PR number by parsing the ref name.
number=$(echo "${GITHUB_REF_NAME}" | sed -n 's/.*pr-\([0-9]*\)-.*/\1/p')
else
# Get the PR number from branch name, otherwise fallback on 0 if the PR number is not found.
number=${{ github.event.number || github.event.issue.number }} || $(gh api /repos/{owner}/{repo}/pulls --header "$GH_API" --method GET --field per_page=100 --field head="${branch}" | jq '.[0].number // 0')
number=${{ github.event.number || github.event.issue.number }} || $(gh api /repos/${{ github.repository }}/pulls --header "$GH_API" --method GET --field per_page=100 --field head="${branch}" | jq '.[0].number // 0')
fi
echo "branch=$branch" >> "$GITHUB_OUTPUT"
Expand Down

0 comments on commit dfc0b0c

Please sign in to comment.