Skip to content

Commit 233e987

Browse files
committed
fix(ci): use full scans outside pull requests
1 parent 4c44d10 commit 233e987

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

socketsecurity/socketcli.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ def _select_pull_request_provider(integration_type: str, scm_type: str) -> str:
133133
return scm_type if scm_type in ("github", "gitlab") else integration_type
134134

135135

136+
def _should_create_scm_diff(
137+
event_type: str,
138+
enable_diff: bool = False,
139+
force_diff_mode: bool = False,
140+
) -> bool:
141+
return event_type == "diff" or enable_diff or force_diff_mode
142+
143+
136144
def build_socket_sdk(config: CliConfig) -> socketdev:
137145
cli_user_agent_string = f"SocketPythonCLI/{config.version}"
138146
return socketdev(
@@ -680,7 +688,8 @@ def _is_unprocessed(c):
680688
return False
681689
return True
682690

683-
if scm is not None and scm.check_event_type() == "comment":
691+
scm_event_type = scm.check_event_type() if scm is not None else None
692+
if scm_event_type == "comment":
684693
# FIXME: This entire flow should be a separate command called "filter_ignored_alerts_in_comments"
685694
# It's not related to scanning or diff generation - it just:
686695
# 1. Triggers on comments in GitHub/GitLab
@@ -734,9 +743,13 @@ def _is_unprocessed(c):
734743
else:
735744
log.info("Ignore commands disabled (--disable-ignore), skipping comment processing")
736745

737-
elif scm is not None and scm.check_event_type() != "comment" and not force_api_mode:
746+
elif scm is not None and not force_api_mode:
738747
log.info("Push initiated flow")
739-
if scm.check_event_type() == "diff":
748+
if _should_create_scm_diff(
749+
scm_event_type,
750+
enable_diff=config.enable_diff,
751+
force_diff_mode=force_diff_mode,
752+
):
740753
log.info("Starting comment logic for PR/MR event")
741754
diff = core.create_new_diff(
742755
scan_paths,
@@ -874,15 +887,14 @@ def _is_unprocessed(c):
874887
)
875888
else:
876889
log.info("Starting non-PR/MR flow")
877-
diff = core.create_new_diff(
890+
diff = core.create_full_scan_with_report_url(
878891
scan_paths,
879892
params,
880893
no_change=should_skip_scan,
881894
save_files_list_path=config.save_submitted_files_list,
882895
save_manifest_tar_path=config.save_manifest_tar,
883896
base_paths=base_paths,
884897
explicit_files=scan_explicit_files,
885-
external_href=pr_context.url,
886898
)
887899

888900
output_handler.handle_output(diff)

tests/unit/test_socketcli.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ def test_pr_context_provider_uses_integration_without_comment_adapter():
7474
assert socketcli._select_pull_request_provider("azure", "api") == "azure"
7575

7676

77+
def test_scm_merge_request_event_creates_diff():
78+
assert socketcli._should_create_scm_diff("diff") is True
79+
80+
81+
def test_scm_branch_event_defaults_to_full_scan():
82+
assert socketcli._should_create_scm_diff("main") is False
83+
84+
85+
@pytest.mark.parametrize("override", ["enable_diff", "force_diff_mode"])
86+
def test_scm_branch_event_honors_diff_override(override):
87+
options = {override: True}
88+
assert socketcli._should_create_scm_diff("main", **options) is True
89+
90+
7791
# ---------------------------------------------------------------------------
7892
# Buildkite-aware infrastructure error formatting.
7993
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)