Repository navigation
fix(cli): Start the set-commits fallback at the previous release - #2478
Conversation
The local fallback always read the last --initial-depth commits, so consecutive releases shared commits. Read the commits since the previous release's last commit, and use --initial-depth only without one in the local history. Fixes getsentry#2472 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@srednoff888-art is attempting to deploy a commit to the Sentry Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Thanks @srednoff888-art, and thanks @JPeer264 for the clear issue. The approach is right: it matches what sentry-cli v2 did with previous-with-commits and keeps the --initial-depth fallback that #2472 asks for. I'd take this once the points below are handled.
About the 2 failing checks. Both are Vercel (Vercel – cli, Vercel – sentry-local) asking a Sentry team member to authorize a deploy from a fork. They don't say anything about the code. The checks that matter (Test, Warden, Dependency Review, Secret Scan) haven't run: they show action_required, so a maintainer has to approve the workflows for this fork. Locally on 4ee8a542 I ran typecheck and lint for packages/cli (both pass) plus test/commands/release, test/lib/git* and test/lib/api/releases.test.ts (175 passed). The full CLI unit run fails only in test/commands/dashboard/widget/preservation.test.ts, which times out on main in the same environment too.
Changes I'd ask for:
- Don't send the request when the range is empty. Sentry ignores an empty
commitslist (if commit_list:insrc/sentry/releases/endpoints/organization_release_details.py), so it does no harm. But it's a wasted PUT, and v2 skipped it and printed "No commits found. Leaving release alone." (inline comment). - Reword the empty-range message.
previous-with-commitsreturns the given release itself when that release already has commits (see the docstring insrc/sentry/issues/endpoints/organization_release_previous_commits.py). Re-runningset-commitsfor the same version is common, for example when several bundler-plugin builds share one release. In that case the commit is this release's own last commit, so "the previous release's commit" is misleading (inline comment). - Optional: add a
log.debug("Could not read the previous release's commit", error)to the silentcatchingetPreviousReleaseCommit(packages/cli/src/lib/api/releases.ts) and drop its grandfatheredno-silent-catchdisable (#1531). The default fallback depends on it now, so a failed lookup that quietly drops to--initial-depthshould be visible with--verbose.
Not blocking, a follow-up at most. If a release is re-run under the same version after new commits land, the range is only the new commits. Sentry's set_commits replaces the release's commit list (ReleaseCommit.objects.filter(release=release).delete() in src/sentry/models/releases/set_commits.py), so the commits sent earlier drop off. v2 behaves the same, so this keeps parity. The response includes version, so a later change could detect that the returned release is this one and handle that case on purpose.
The tests run against a real temp repository and cover the cached path, the unmatched repository, other-branch commits and option-like SHAs, which is good.
| const commits = getCommitLog(cwd, { depth, paths, from }); | ||
| if (commits.length === 0) { | ||
| if (commits.length === 0 && sincePreviousRelease) { | ||
| log.info(`No commits since the previous release's commit ${from}.`); |
There was a problem hiding this comment.
Two things here.
- With
sincePreviousRelease, an empty range still falls through tosetCommitsLocal(org, version, []). Sentry treats an empty list as a no-op, so it's only a wasted request. v2 returned early ("Leaving release alone"). Could this skip the PUT and return the current release instead (getReleaseis already exported)? previous-with-commitsalso returns this release when it already has commits, so on a re-runfromis this release's own last commit. Something likeNo new commits since ${from}, the last commit Sentry has for this release or the one before it.would be accurate in both cases.
There was a problem hiding this comment.
Both done in f53e281. With an empty range setCommitsFromLocal now logs No new commits since <sha>, the last commit Sentry has for this release or the one before it. Leaving the release alone. and returns getRelease(org, version) instead of sending the PUT. The test for that case now checks that setCommitsLocal isn't called, and it fails without the change.
When the previous release's commit is HEAD, set-commits sent an empty commit list. Sentry ignores it, so skip the request and return the release, as sentry-cli v2 did. The commit can also be this release's own last commit, so say so in the message. Log why the previous release's commit could not be read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the review. f53e281 handles the three points:
|
There was a problem hiding this comment.
Thanks @srednoff888-art, f53e281 handles all three points. With an empty range it skips the PUT and returns getRelease, which is a GET on the release details endpoint and accepts org:ci tokens, so CI tokens still work. The message is accurate for re-runs now, and the catch logs at debug level without the grandfathered disable.
On f53e281, CLI typecheck and lint pass, and test/commands/release, test/lib/git* and test/lib/api/releases.test.ts pass on Linux (175 tests), including the set-commits tests that need a git checkout. It also merges cleanly with current main. Nothing more from me. The re-run case is fine as a follow-up.
Fixes #2472.
Summary
Without a flag, when no repository integration matches,
release set-commitsnow sends the local commits since the previous release's last commit. Before, it always sent the last--initial-depthcommits, so consecutive releases shared commits.Changes
getPreviousReleaseCommit, already used by--auto) and reads<commit>..HEAD. All three fallback paths do this, including the cached "no repository integration" one. The range bounds itself, so--initial-depthdoesn't cut it.--initial-depthcommits, as before, when there is no previous release or its commit isn't an ancestor ofHEAD: a shallow clone, rewritten history, another branch or another repository. In that last group it warns.sentry-cliv2 needed--ignore-missingfor this and failed otherwise; I followed the issue and fall back.isInHeadHistory()inlib/git.ts(git merge-base --is-ancestor), which rejects option-like refs likegetMergeBasedoes.--helpdescribes the fallback. Explicit--local,--from,--path,--autoand--commitdon't change.The fallback makes one more request,
previous-with-commits. A failed request counts as no previous release, as in--auto.Tests
New tests run the command in a temporary git repository with the API mocked: the range, the cached path, an empty range, the unmatched repository, and the four cases that keep
--initial-depth. Three of them fail without the change; the four--initial-depthcases pin behavior that stays.On Windows,
test/commands/release,test/lib/git*andtest/lib/api/releases.test.tsgive 169 passed and 6 failed. The same 6 fail onmainhere: they build the repository path fromURL.pathname, which is/G:/…. Oxlint and Oxfmt are clean on the changed files, andtscreports nothing in the changed source files. I didn't run the full quality gate.🤖 Generated with Claude Code