From 57cd1f93db1b2ea9499b63bb475a66eab48f8bbb Mon Sep 17 00:00:00 2001 From: Reuven Harrison Date: Sun, 26 Apr 2026 01:16:56 +0300 Subject: [PATCH] feat(pr-comment): capture pull_request.base.sha as base_sha The action now extracts the PR's base SHA from the GitHub event payload and includes it in two places: - The free-review-page URL emitted as a ::notice:: annotation now uses the base SHA instead of the branch name, so the link is commit-pinned and stays valid even if the base branch advances after the PR was opened. - The JSON payload sent to oasdiff-service gains a github.base_sha field alongside the existing github.base_ref. The service stores it on the report so the review page can show the exact base content oasdiff compared against, rather than chasing whatever main happens to point at when the reviewer opens the page. base_ref is preserved for backward compatibility with reports stored before this field existed and for the small subset of pull_request events where pull_request.base.sha is empty. --- pr-comment/entrypoint.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pr-comment/entrypoint.sh b/pr-comment/entrypoint.sh index f238e4a..69e2ff2 100755 --- a/pr-comment/entrypoint.sh +++ b/pr-comment/entrypoint.sh @@ -58,6 +58,13 @@ if [ -z "$head_sha" ]; then head_sha="$GITHUB_SHA" fi +# Capture the PR base SHA (the commit the PR is opened against). Pinning to +# the SHA gives the review page a stable base reference: if the base branch +# advances after the PR was opened, the review still shows the comparison +# against the original base. base_ref is still sent for backward compatibility +# with reports that don't yet have base_sha. +base_sha=$(jq -r '.pull_request.base.sha // empty' "$GITHUB_EVENT_PATH") + # Extract owner and repo from GITHUB_REPOSITORY owner="${GITHUB_REPOSITORY%%/*}" repo="${GITHUB_REPOSITORY#*/}" @@ -67,7 +74,9 @@ urlencode() { printf '%s' "$1" | jq -sRr @uri; } # Strip git ref prefix (e.g. "origin/main:path.yaml" -> "path.yaml", "HEAD:path.yaml" -> "path.yaml") base_path=$(echo "$base" | sed 's/.*://') rev_path=$(echo "$revision" | sed 's/.*://') -free_review_url="https://www.oasdiff.com/review?owner=${owner}&repo=${repo}&base_sha=${GITHUB_BASE_REF}&rev_sha=${head_sha}&base_file=$(urlencode "$base_path")&rev_file=$(urlencode "$rev_path")" +# Prefer the base SHA over the branch name so the link is commit-pinned. +free_base_sha="${base_sha:-$GITHUB_BASE_REF}" +free_review_url="https://www.oasdiff.com/review?owner=${owner}&repo=${repo}&base_sha=${free_base_sha}&rev_sha=${head_sha}&base_file=$(urlencode "$base_path")&rev_file=$(urlencode "$rev_path")" echo "::notice::📋 View API changes → ${free_review_url}" # Build the JSON payload @@ -78,10 +87,11 @@ payload=$(jq -n \ --argjson pr "$pr_number" \ --arg sha "$head_sha" \ --arg base_ref "$GITHUB_BASE_REF" \ + --arg base_sha "$base_sha" \ --arg base_file "$base" \ --arg rev_file "$revision" \ --argjson changes "$changes" \ - '{github: {token: $token, owner: $owner, repo: $repo, pull_number: $pr, head_sha: $sha, base_ref: $base_ref}, base_file: $base_file, rev_file: $rev_file, changes: $changes}') + '{github: {token: $token, owner: $owner, repo: $repo, pull_number: $pr, head_sha: $sha, base_ref: $base_ref, base_sha: $base_sha}, base_file: $base_file, rev_file: $rev_file, changes: $changes}') # POST to oasdiff-service (requires token) if [ -z "$oasdiff_token" ]; then