Skip to content

Commit 6a297e9

Browse files
committed
Ask for the branch head on every non-PR full scan
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 they never reached organization alerts. Full scans that aren't for a pull request now send set_as_pending_head=true and let the API decide. make_default_branch is unchanged, so the repository's default branch only moves as before. Pull request scans keep sending it only on the default branch, and --no-default-branch keeps it off, as its help text promises. --pending-head stays a deprecated no-op. Its warning and the CLI reference now say that tracked branches get a head scan too. Bump version to 2.15.9.
1 parent 81105de commit 6a297e9

8 files changed

Lines changed: 68 additions & 7 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
## 2.15.9
4+
5+
### Fixed
6+
7+
- Full scans of a branch that matches your organization's tracked branch
8+
patterns become that branch's head scan. Previously only default-branch scans
9+
did. Pull request scans, scans of untracked branches and scans run with
10+
`--no-default-branch` are unchanged.
11+
312
## 2.15.8
413

514
### Added

‎docs/cli-reference.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ The CLI uses intelligent default branch detection with the following priority:
729729

730730
When `--branch` or `--commit-sha` names a different ref than the CI variables, git repository analysis also checks the ref you passed: the scan is not treated as the default branch unless that branch is the default branch and that commit is on it. These flags never turn detection on; use `--default-branch` for that. With `--commit-sha`, the commit message and committer come from that commit when it is in the checkout.
731731

732-
A scan on the default branch also becomes that branch's head scan. `--pending-head` is deprecated and has no effect: it is still accepted so existing pipelines keep working, but it logs a warning. Use `--default-branch` instead.
732+
A full scan of the default branch, or of a branch that matches your organization's tracked branch patterns (**Settings > Alerts > Scans**), becomes that branch's head scan. Full scans of other branches, pull request scans and scans run with `--no-default-branch` don't. `--pending-head` is deprecated and has no effect: it is still accepted so existing pipelines keep working, but it logs a warning. Use `--default-branch` to mark the default branch.
733733
734734
## Who can ignore an alert
735735

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
66

77
[project]
88
name = "socketsecurity"
9-
version = "2.15.8"
9+
version = "2.15.9"
1010
requires-python = ">= 3.11"
1111
license = {"file" = "LICENSE"}
1212
dependencies = [

‎socketsecurity/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
__author__ = 'socket.dev'
2-
__version__ = '2.15.8'
2+
__version__ = '2.15.9'
33
USER_AGENT_NAME = 'socket-python-cli'
44
USER_AGENT = f'{USER_AGENT_NAME}/{__version__}'

‎socketsecurity/config.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,9 @@ def _from_args(cls, args_list: Optional[List[str]] = None) -> 'CliConfig':
504504

505505
if args.pending_head:
506506
logging.warning(
507-
"--pending-head is deprecated and has no effect. A scan becomes the head scan "
508-
"when it runs on the default branch; use --default-branch to mark it as such."
507+
"--pending-head is deprecated and has no effect. A full scan becomes its branch's "
508+
"head scan on the default branch or a tracked branch; use --default-branch "
509+
"to mark the default branch."
509510
)
510511

511512
# argparse only enforces the mutually exclusive group for real CLI args;

‎socketsecurity/socketcli.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,11 @@ def main_code(config: Optional[CliConfig] = None):
732732
pull_request=pr_number,
733733
committers=config.committers,
734734
make_default_branch=is_default_branch,
735-
set_as_pending_head=is_default_branch,
735+
# The API makes a scan its branch's head only on the default branch or a
736+
# branch matching the org's tracked branch patterns, and ignores the flag
737+
# elsewhere. A pull request scan never becomes a head, and neither does a
738+
# scan run with --no-default-branch.
739+
set_as_pending_head=not config.no_default_branch and (is_default_branch or not pr_number),
736740
tmp=False,
737741
scan_type='socket_tier1' if config.reach else 'socket',
738742
workspace=config.workspace or None,
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""Which full scans ask the API to become their branch's head scan."""
2+
3+
from tests.core.test_strict_blocking_no_manifest_change import cli_runtime # noqa: F401
4+
5+
6+
def _scan_params(runtime):
7+
runtime.full_scan.assert_called_once()
8+
return runtime.full_scan.call_args.args[1]
9+
10+
11+
def test_branch_scan_asks_to_be_the_branch_head(cli_runtime): # noqa: F811
12+
# The API honors this only for tracked branches, so the CLI no longer decides.
13+
assert cli_runtime.run() == 0
14+
15+
params = _scan_params(cli_runtime)
16+
assert params.branch == "feature"
17+
assert params.set_as_pending_head is True
18+
assert params.make_default_branch is False
19+
20+
21+
def test_default_branch_scan_is_the_head_and_the_default_branch(cli_runtime): # noqa: F811
22+
cli_runtime.git_repo.is_default_branch = True
23+
24+
assert cli_runtime.run() == 0
25+
26+
params = _scan_params(cli_runtime)
27+
assert params.set_as_pending_head is True
28+
assert params.make_default_branch is True
29+
30+
31+
def test_pull_request_scan_is_never_a_head(cli_runtime): # noqa: F811
32+
assert cli_runtime.run(["--pr-number", "42"]) == 0
33+
34+
params = _scan_params(cli_runtime)
35+
assert params.set_as_pending_head is False
36+
assert params.make_default_branch is False
37+
38+
39+
def test_no_default_branch_scan_is_never_a_head(cli_runtime): # noqa: F811
40+
# --no-default-branch promises the scan won't become the default branch or a head.
41+
cli_runtime.git_repo.is_default_branch = True
42+
43+
assert cli_runtime.run(["--no-default-branch"]) == 0
44+
45+
params = _scan_params(cli_runtime)
46+
assert params.set_as_pending_head is False
47+
assert params.make_default_branch is False

‎uv.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)