Repository navigation
refactor(safe-outputs): reduce complexity of execute_vote in update_pr.rs - #2317
Draft
github-actions[bot] wants to merge 1 commit into
Draft
github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
…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: 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was complex
execute_voteinsrc/safe_outputs/update_pr.rs(theupdate-prsafe-output'svoteoperation handler) was flagged bycargo clippy -- -W clippy::too_many_linesat 154/100 lines. It mixed four distinct concerns inline in one function:allowed-voteslist and resolving it to an ADO numeric value._apis/connectiondata.PUTrequest to the reviewers endpoint.What changed
Extracted each concern into a focused, independently testable free function, with
execute_votereduced to a ~29-line orchestrator that calls them in sequence and short-circuits on any early-failureExecutionResult: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/connectiondatalookup.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.rswas touched.Before / after complexity
clippy::too_many_linesreportedexecute_voteat 154/100 lines.execute_voteno longer appears in thetoo_many_linesviolation list for this file (only an unrelated, pre-existing function,lookup_reviewer_id, remains flagged at 133/100).(Note:
clippy::cognitive_complexityis restriction-only on this toolchain — clippy 0.1.98 / rustc 1.99.0 — and produces no diagnostics even when enabled, soclippy::too_many_lineswas 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-testsafe_outputs::update_pr::testsmodule (0 failed).cargo clippy --all-targets --all-features— clean aside from pre-existing, unrelatedasync_traitdouble_must_usewarnings 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.too_many_lineslint scoped tosrc/safe_outputs/update_pr.rsto confirmexecute_voteis no longer flagged.Checked for duplicate in-flight work first (via GitHub search, since
ghis unauthenticated in this environment): PRs #2311, #2272, #2267, #2243 already target other complex functions inagentic_pipeline.rs/compile/mod.rs; none targetupdate_pr.rsorexecute_vote.Warning
Firewall blocked 2 domains
The following domains were blocked by the firewall during workflow execution:
releaseassets.githubusercontent.comspsprodeus21.vssps.visualstudio.comTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.