Skip to content

Conversation

@runningcode
Copy link
Contributor

Summary

This PR modifies sentry-cli to skip setting base_sha and base_ref when they are auto-inferred and base_sha equals head_sha.

Changes

  • Added tracking to distinguish between user-provided CLI arguments and auto-inferred values for base_sha and base_ref
  • When both values are auto-inferred and base_sha == head_sha, we now set both to None before sending to the API
  • User-provided values via --base-sha and --base-ref are always respected regardless of their values

Rationale

When base_sha equals head_sha, there is no meaningful comparison baseline since we'd be comparing a commit against itself. This typically occurs in certain CI scenarios where the auto-inference logic cannot determine a proper base commit. By skipping these values, we allow the backend to handle the comparison more appropriately.

Closes EME-607

🤖 Generated with Claude Code

@linear
Copy link

linear bot commented Nov 7, 2025

@runningcode runningcode force-pushed the no/eme-607-skip-base-sha-when-equal-to-head branch from 2c02e58 to c5cb821 Compare November 7, 2025 16:21
@runningcode runningcode marked this pull request as ready for review November 10, 2025 08:25
@runningcode runningcode requested review from a team and szokeasaurusrex as code owners November 10, 2025 08:25
Comment on lines +255 to +265
&& !base_ref_from_user
&& base_sha.is_some()
&& head_sha.is_some()
&& base_sha.as_deref() == head_sha.as_deref()
{
debug!(
"Base SHA equals head SHA ({}), and both were auto-inferred. Skipping base_sha and base_ref, but keeping head_sha.",
base_sha.as_deref().expect("base_sha is Some at this point")
);
base_sha = None;
base_ref = None;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: In GitHub Actions, if base_sha == head_sha, the reliable GITHUB_BASE_REF value is incorrectly cleared because base_ref_from_user only checks CLI args.
Severity: CRITICAL | Confidence: 1.00

🔍 Detailed Analysis

When running in a GitHub Actions pull request context, if base_sha and head_sha are identical, the base_ref value populated from the GITHUB_BASE_REF environment variable is incorrectly cleared to None. This occurs because the base_ref_from_user flag only checks for CLI arguments, causing the clearing logic at src/commands/build/upload.rs:254~265 to treat the reliable GitHub Actions-provided base_ref as an auto-inferred value that should be discarded. This results in the backend receiving base_ref: None instead of the correct base branch name.

💡 Suggested Fix

Adjust the condition for clearing base_ref to distinguish between values derived from git introspection and those reliably provided by the GITHUB_BASE_REF environment variable. Ensure base_ref from GITHUB_BASE_REF is not cleared.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/commands/build/upload.rs#L254-L265

Potential issue: When running in a GitHub Actions pull request context, if `base_sha`
and `head_sha` are identical, the `base_ref` value populated from the `GITHUB_BASE_REF`
environment variable is incorrectly cleared to `None`. This occurs because the
`base_ref_from_user` flag only checks for CLI arguments, causing the clearing logic at
`src/commands/build/upload.rs:254~265` to treat the reliable GitHub Actions-provided
`base_ref` as an auto-inferred value that should be discarded. This results in the
backend receiving `base_ref: None` instead of the correct base branch name.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentional, we want to clear the GITHUB_BASE_REF if it was auto-inferred and the base-sha and head-sha match.

Copy link
Member

@szokeasaurusrex szokeasaurusrex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changelog looks good, I'll leave the code changes for the Emerge Tools team to review.

Once they approve, I'll stamp this for the CHANGELOG changes (I am code owner there)

runningcode and others added 3 commits November 10, 2025 10:40
…auto-inference (EME-607)

When auto-inferring VCS metadata, if base_sha equals head_sha, we now skip
setting both base_sha and base_ref (but still set head_sha) since comparing
a commit to itself provides no meaningful baseline. This only applies when
both base values are auto-inferred; user-provided values via CLI arguments
are always respected.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
…auto-inference (EME-607)

When auto-inferring VCS metadata, if base_sha equals head_sha, we now skip
setting both base_sha and base_ref (but still set head_sha) since comparing
a commit to itself provides no meaningful baseline. This only applies when
both base values are auto-inferred; user-provided values via CLI arguments
are always respected.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@runningcode runningcode force-pushed the no/eme-607-skip-base-sha-when-equal-to-head branch from 17a9795 to f1ad020 Compare November 10, 2025 09:41
Copy link
Contributor

@chromy chromy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks!

@runningcode runningcode merged commit b8c061f into master Nov 10, 2025
27 checks passed
@runningcode runningcode deleted the no/eme-607-skip-base-sha-when-equal-to-head branch November 10, 2025 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants