Skip to content

refactor: reduce complexity of add_report_findings in custom_jobs.rs - #2167

Closed
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-custom-jobs-add-report-findings-7a4253e5af2c7a1a
Closed

github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-custom-jobs-add-report-findings-7a4253e5af2c7a1a

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Summary

add_report_findings in src/audit/analyzers/custom_jobs.rs exceeded Clippy's too_many_lines threshold (131/100), driven by a single loop body containing six independent, inline if/Finding-push blocks.

Change

Extracted each independent check into its own well-named helper function returning Option<Finding>, appended to the findings vec via Vec::extend:

  • incomplete_provenance_finding
  • job_identity_mismatch_finding
  • ran_without_proposals_finding
  • ran_after_unsafe_detection_finding
  • ran_without_approval_finding
  • expected_job_missing_finding

The loop body in add_report_findings is now a short, readable sequence of calls. No public API changed, and behaviour is identical (same findings, same order, for the same inputs).

Before / after

  • Before: clippy::too_many_lines warning (131/100) on add_report_findings.
  • After: no too_many_lines warning for this function.

Verification

  • cargo build — passes
  • cargo test (full suite) — all tests pass, including all 9 existing unit tests in audit::analyzers::custom_jobs
  • cargo clippy --all-targets --all-features — clean, no warnings

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 · auto · 77.1 AIC · ⌖ 6.68 AIC · ⊞ 10.2K ·

Extract each independent finding check in add_report_findings into its
own well-named helper function returning Option<Finding>, appended via
Vec::extend. This flattens the previously monolithic loop body (six
inline if/push blocks, 131 lines, exceeding clippy::too_many_lines'
100-line threshold) into small, individually testable predicates:

- incomplete_provenance_finding
- job_identity_mismatch_finding
- ran_without_proposals_finding
- ran_after_unsafe_detection_finding
- ran_without_approval_finding
- expected_job_missing_finding

No behavioural change: same findings are produced in the same order
for the same inputs. All existing unit tests in this module continue
to pass, and the clippy::too_many_lines warning for this function no
longer appears.

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.

@jamesadevine

Copy link
Copy Markdown
Collaborator

Closed as partially superseded by aggregate PR #2189, which retains the add_report_findings helper extraction. Unrelated or overlapping cumulative changes were intentionally omitted.

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.

1 participant