Skip to content

refactor: reduce complexity of populate_custom_safe_output_jobs in custom_jobs.rs - #1815

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-custom-jobs-36a94c411e2a7b4e
Draft

refactor: reduce complexity of populate_custom_safe_output_jobs in custom_jobs.rs#1815
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-custom-jobs-36a94c411e2a7b4e

Conversation

@github-actions

@github-actions github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

What was complex

populate_custom_safe_output_jobs in src/audit/analyzers/custom_jobs.rs was flagged by clippy::too_many_lines (147/100). The per-tool loop body inlined three separate concerns:

  1. Cross-checking a catalog entry's aw_info metadata against the typed pipeline graph (job identity, approval path, and component provenance), pushing High-severity findings on mismatch.
  2. Matching the tool against ADO timeline jobs to select the executed job.
  3. Merging the result with the previous audit run's report for fields not supplied by current artifacts.

What changed

Extracted two focused helpers with no behavioural change:

  • correlate_tool_with_graph(audit, tool, entry, findings) -> ToolGraphCorrelation — owns all three graph/metadata mismatch checks and returns a small struct (expected_job_id, graph_display_name, approval_path, graph_is_authoritative).
  • build_report_for_tool(audit, tool, entry, correlation, proposal_counts, previous_entry) -> CustomSafeOutputJobAudit — owns timeline matching and the previous-run fallback merge, returning the final report.

populate_custom_safe_output_jobs now just loops calling these two helpers and building the report list.

Before/after

  • Before: 148-line function, too_many_lines (147/100) clippy warning.
  • After: ~50-line function; warning cleared. (A separate pre-existing function, add_report_findings, still reports 131/100 but was out of scope for this change.)

Verification

  • cargo build — clean
  • cargo clippy --all-targets --all-features — no warnings
  • cargo test — full suite passes, including the 10 existing custom_jobs::tests cases (unchanged, no test modifications needed)

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • spsprodeus21.vssps.visualstudio.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "spsprodeus21.vssps.visualstudio.com"

See Network Configuration for more information.

Generated by Cyclomatic Complexity Reducer · aut00 · 95 AIC · ⌖ 13.3 AIC · ⊞ 11K ·

…stom_jobs.rs

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
2 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

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.

0 participants