Skip to content

Update tracked branch heads from full scans - #479

Open
David Larsen (dc-larsen) wants to merge 2 commits into
dl/default-branch-explicit-argsfrom
dl/tracked-branch-pending-head
Open

David Larsen (dc-larsen) wants to merge 2 commits into
dl/default-branch-explicit-argsfrom
dl/tracked-branch-pending-head

Conversation

@dc-larsen

@dc-larsen David Larsen (dc-larsen) commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

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-branch retains its explicit behavior. --no-default-branch opts a scan out of both updates.

Verification

  • Unit and core suite passes with locked dependencies. It covers the PR-event classification, explicit override and opt-out, and missing-commit cases.
  • A test organization was used to verify default, tracked, untracked, and opt-out behavior on the earlier tracked-branch build. The new missing-commit behavior is covered by a local CLI regression test.

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-branch to opt a scan out.


Refs: CE-529

@dc-larsen
David Larsen (dc-larsen) requested a review from a team as a code owner December 1, 2026 19:36
@cursor

cursor Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes when scans request branch head promotion, which affects org Alerts visibility after upgrade; behavior is gated by PR detection and explicit flags but is broader than default-branch-only promotion.

Overview
Full scans on non–default-branch pushes can now request a branch head update, not only when the run is treated as the default branch. The API still promotes only the default branch or org tracked branch patterns; the CLI always asks on eligible runs and relies on the server to accept or ignore.

set_as_pending_head is driven by new request_branch_head() logic: honor --no-default-branch (never ask), always ask when --default-branch / default-branch detection applies, otherwise ask on branch full scans but not on pull/merge request runs (including PR events with no PR number, via new is_pull_request_environment()), and not when --commit-sha names a commit missing from the checkout unless --default-branch is explicit.

Docs and changelog describe branch heads and the --pending-head deprecation message is updated accordingly; tests cover the new matrix.

Reviewed by Cursor Bugbot for commit 2b912ed. Configure here.

@lelia

lelia commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@lelia lelia self-assigned this Dec 2, 2026

@lelia lelia left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 0 requesting 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-branch on 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-branch on 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.0 changelog 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-branch opt-out and explain that untracked branches are ineligible. The CLI reference should link the behavior to Settings > Alerts > Scans and clarify that --pending-head remains deprecated and has no effect. A pointer from the existing README CI guidance is enough.
  • Rebase and retarget this PR to main after #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.

@dc-larsen
David Larsen (dc-larsen) force-pushed the dl/default-branch-explicit-args branch from 81105de to 8cae773 Compare December 2, 2026 15:40
@dc-larsen
David Larsen (dc-larsen) force-pushed the dl/tracked-branch-pending-head branch from 6a297e9 to b398abc Compare December 2, 2026 15:50
@dc-larsen David Larsen (dc-larsen) changed the title Ask for the branch head on every non-PR full scan Update tracked branch heads from full scans Dec 2, 2026
@dc-larsen

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

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.
@dc-larsen
David Larsen (dc-larsen) force-pushed the dl/tracked-branch-pending-head branch from b398abc to 29b1612 Compare December 2, 2026 16:03
@dc-larsen

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@lelia

lelia commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ 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.

This branch was previously deployed

1 inactive (outdated) deployment
socket-firewall — 6a297e94 Deployed Dec 1, 2026 by dc-larsen via python-sfw-smoke-enterprise #720
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.

2 participants