Skip to content

Commit

Permalink
Handle null branch
Browse files Browse the repository at this point in the history
  • Loading branch information
akaihola committed Jul 30, 2024
1 parent 93cec2d commit ec0c7d2
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions .github/actions/commit-range/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,26 @@ runs:
--head ${{ github.ref_name }} \
--json number,baseRefName \
--limit 1)
if [[ -n "$pr_info" ]]; then
if [[ \
-n "$pr_info" && \
"$(echo "$pr_info" | jq '.[0].baseRefName')" != "null" \
]]; then
base_branch=$(echo "$pr_info" | jq -r '.[0].baseRefName')
echo "Associated PR found."
echo "Associated PR found. Base branch: ${base_branch}"
else
echo "No associated PR found. Using default branch as base."
echo "No associated PR found or base branch is null."
echo "Using default branch as base."
base_branch=$(gh api repos/${{ github.repository }} --jq '.default_branch')
echo "Default branch: ${base_branch}"
fi
echo "Base branch: ${base_branch}"
branch_point=$(git merge-base origin/${base_branch} ${{ github.sha }})
echo "Fetching the branch point..."
if ! branch_point=$(git merge-base origin/${base_branch} ${{ github.sha }})
then
echo "Failed to find merge-base."
echo "Using the first commit of the current branch."
branch_point=$(git rev-list --max-parents=0 HEAD)
fi
echo "Branch point: ${branch_point}"
range="${branch_point}...${{ github.sha }}"
Expand Down

0 comments on commit ec0c7d2

Please sign in to comment.