Skip to content

refactor(safe-outputs): reduce complexity of execute_vote in update_pr.rs - #2317

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-execute-vote-318bfc5d89d65844
Draft

github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-execute-vote-318bfc5d89d65844

Conversation

@github-actions

@github-actions github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

What was complex

execute_vote in src/safe_outputs/update_pr.rs (the update-pr safe-output's vote operation handler) was flagged by cargo clippy -- -W clippy::too_many_lines at 154/100 lines. It mixed four distinct concerns inline in one function:

  1. Validating the requested vote against the configured allowed-votes list and resolving it to an ADO numeric value.
  2. Resolving the authenticated user's identity via _apis/connectiondata.
  3. A self-approval guard that blocks positive votes when the authenticated identity also created the PR (requires a PR lookup).
  4. Building and sending the final PUT request to the reviewers endpoint.

What changed

Extracted each concern into a focused, independently testable free function, with execute_vote reduced to a ~29-line orchestrator that calls them in sequence and short-circuits on any early-failure ExecutionResult:

  • validate_vote_selection(vote_str, config) -> Result<Result<i32, ExecutionResult>> — allowed-votes policy check + vote-string-to-ADO-value mapping.
  • resolve_authenticated_user_id(operation_ctx) -> Result<Result<String, ExecutionResult>> — _apis/connectiondata lookup.
  • check_self_approval_guard(operation_ctx, vote_value, vote_str, user_id) -> Result<Option<ExecutionResult>> — PR-creator self-vote block.
  • submit_vote(operation_ctx, vote_str, vote_value, user_id) -> Result<ExecutionResult> — PUT to the reviewers endpoint.

No public API, behavior, log messages, or error text changed — this is a pure extract-function refactor. Only src/safe_outputs/update_pr.rs was touched.

Before / after complexity

  • Before: clippy::too_many_lines reported execute_vote at 154/100 lines.
  • After: execute_vote no longer appears in the too_many_lines violation list for this file (only an unrelated, pre-existing function, lookup_reviewer_id, remains flagged at 133/100).

(Note: clippy::cognitive_complexity is restriction-only on this toolchain — clippy 0.1.98 / rustc 1.99.0 — and produces no diagnostics even when enabled, so clippy::too_many_lines was used as the practical complexity proxy, consistent with prior refactors in this repo.)

Validation

  • cargo test --all-targets --all-features — all 3407 tests pass, including the full 36-test safe_outputs::update_pr::tests module (0 failed).
  • cargo clippy --all-targets --all-features — clean aside from pre-existing, unrelated async_trait double_must_use warnings already tracked separately in open PR fix(clippy): bump async-trait to 0.1.92 to clear double_must_use lint #2296; no new warnings introduced.
  • Re-ran the too_many_lines lint scoped to src/safe_outputs/update_pr.rs to confirm execute_vote is no longer flagged.

Checked for duplicate in-flight work first (via GitHub search, since gh is unauthenticated in this environment): PRs #2311, #2272, #2267, #2243 already target other complex functions in agentic_pipeline.rs / compile/mod.rs; none target update_pr.rs or execute_vote.

Warning

Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • releaseassets.githubusercontent.com
  • spsprodeus21.vssps.visualstudio.com

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

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

See Network Configuration for more information.

Generated by Cyclomatic Complexity Reducer · auto · 132.8 AIC · ⌖ 13.3 AIC · ⊞ 11.1K · ◷

…r.rs

Extract execute_vote's allowed-votes validation, authenticated-user-id
resolution, self-approval guard, and vote PUT request into focused
helper functions: validate_vote_selection, resolve_authenticated_user_id,
check_self_approval_guard, and submit_vote. Behaviour is unchanged;
execute_vote itself is now a ~29-line orchestrator.

Before: clippy::too_many_lines flagged execute_vote at 154/100 lines.
After: execute_vote no longer appears in too_many_lines violations.

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

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

This branch has not been deployed

No deployments
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