Repository navigation
Update tracked branch heads from full scans - #479
Conversation
PR SummaryMedium Risk Overview
Docs and changelog describe branch heads and the Reviewed by Cursor Bugbot for commit 2b912ed. Configure here. |
8cefa17 to
6a297e9
Compare
|
bugbot run |
There was a problem hiding this comment.
David Larsen (@dc-larsen), please tighten the promotion gate and verify the server behavior before including this in 2.16.0.
Use scan context to decide head eligibility
- The promotion check treats a missing PR number as a branch run. I reproduced a GitHub PR event with
--pr-number 0requesting head promotion, including when the SCM adapter selected the comparison flow. Use resolved scan context to keep PR/MR runs out of the new promotion path even when a PR number is unavailable. Add a regression test through the CLI path. - An explicit
--default-branchon a PR still requests head promotion today. Please test this case and align the code, docs, and PR body with the intended compatibility behavior. If the existing explicit behavior stays, say so and avoid the blanket promise that PR scans never request promotion. Test--no-default-branchon a tracked-branch run too. - Validate the revised build in staging for a default branch, a tracked non-default branch, an untracked branch, and the explicit opt-out. Confirm which scans update the branch head and that the tracked scan leaves the repository’s default branch intact. The current live check predates the opt-out gate.
Docs, changelog, and stack
- Suggested title: Update tracked branch heads from full scans. Keep the body focused on the behavior change, the dependency on #478, and the final validation. In code, keep one comment describing server-side eligibility. Remove the historical wording from the test comment and name the PR test for the case it covers.
- Under Changed in the shared
2.16.0changelog and in the Public Changelog block, explain the upgrade effect: “Full scans of branches that match an organization’s tracked branch patterns can update those branch heads, so findings from those branches can appear on the organization Alerts page after upgrade.” Note the--no-default-branchopt-out and explain that untracked branches are ineligible. The CLI reference should link the behavior to Settings > Alerts > Scans and clarify that--pending-headremains deprecated and has no effect. A pointer from the existing README CI guidance is enough. - Rebase and retarget this PR to
mainafter #478 lands. Keep #478’s 2.16.0 version and drop the independent 2.15.9 bump. #478’s new public flag drives the minor bump. This PR’s upgrade impact belongs in the same release notes. Rerun CI and Bugbot on the final stack.
…branch Default-branch detection read only the CI variables. On GitHub Actions it compared GITHUB_REF to the repository's default branch and checked that the GITHUB_SHA commit is on it; --branch and --commit-sha were never consulted. A workflow_run job triggered by develop (the default branch) that checks out a release tag on main and passes --branch main --commit-sha <tag> was detected as a default-branch scan. The full scan was created with make_default_branch=true and set_as_pending_head=true, which moved the repository's default branch to main, and with develop's commit message. Without --scm, DEFAULT_BRANCH=false did not help, and nothing could turn --default-branch detection off. When --branch or --commit-sha names a different ref than the CI variables, the scan is no longer treated as the default branch unless that branch is the default branch and that commit is on it. A commit missing from the checkout cannot be checked, so it is not treated as the default branch either. The check can only turn detection off; --default-branch still marks a scan explicitly. The commit message and the committer fallback now come from the --commit-sha commit when the checkout has it. Changed-file detection still reads the CI variables. Add --no-default-branch, which forces make_default_branch and set_as_pending_head off whatever git or the CI environment says. It is mutually exclusive with --default-branch, on the command line and in a --config file. Set the version to 2.16.0.
GitHub Actions sets GITHUB_ACTOR, which get_formatted_committer prefers over the commit's committer, so the --commit-sha committer test failed in CI.
With --scm github, the SCM adapter's is_default_branch was copied into config.default_branch, so DEFAULT_BRANCH=true restored default-branch status after git had rejected a mismatched --branch or --commit-sha. resolve_default_branch() now makes the decision in one place: --no-default-branch and --default-branch are authoritative, and otherwise the SCM and git detection results are combined before the explicit-ref check runs. Git.apply_explicit_ref() only records the named ref and switches the commit details; explicit_ref_allows_default_branch() does the check. Adds CLI-path tests with SCM detection enabled covering both outgoing flags, the explicit overrides, and the commit message and committer fallback. Sets the release to 2.16.0 and updates the CLI reference, README and CHANGELOG.
81105de to
8cae773
Compare
6a297e9 to
b398abc
Compare
|
bugbot run |
When the clone lacks the CI commit, Git falls back to HEAD. A --commit-sha naming that checkout then matched self.commit and was not treated as an explicit ref, so the reachability check never ran and DEFAULT_BRANCH=true with --scm github could still mark a scan of another ref as the default branch. Compare with the CI SHA when there is one.
Full scans sent set_as_pending_head=is_default_branch, so only a default-branch scan could become a head. The API also makes a scan the head of a branch that matches the organization's tracked branch patterns (Settings > Alerts > Scans), but only when the request sets set_as_pending_head, and it ignores the flag on branches it doesn't track. Python CLI scans of a tracked branch were never that branch's head, so their findings never reached the organization Alerts page. Branch runs now send set_as_pending_head=true and let the API decide. make_default_branch is unchanged. A run counts as a pull or merge request when it has a PR number, when the SCM adapter selected the comparison flow, or when the CI environment describes a PR or MR event, so a PR run with --pr-number 0 stays out of the new path. A scan marked as the default branch, including one with an explicit --default-branch on a PR, still requests it as before, and --no-default-branch keeps it off. --pending-head stays a deprecated no-op. Its warning, the CLI reference, the README and the CHANGELOG describe the new behavior. Shares the 2.16.0 version set in #478.
b398abc to
29b1612
Compare
|
bugbot run |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 2b912ed. Configure here.
Stacked on #478 for the shared 2.16.0 release.
Full scans can update heads for branches that match an organization's tracked branch patterns. This lets findings from those branches appear on the organization Alerts page. The API decides which branches are tracked, and this change preserves the repository's default branch.
Pull and merge request runs on non-default branches skip automatic promotion even when the PR number is unavailable. Automatic branch-head updates also skip a Git scan if the checkout lacks its explicitly requested commit.
--default-branchretains its explicit behavior.--no-default-branchopts a scan out of both updates.Verification
Public Changelog
Full scans of tracked branches can update branch heads, so findings from those branches can appear on the organization Alerts page after upgrade. Use
--no-default-branchto opt a scan out.Refs: CE-529