[code-simplifier] refactor: simplify id-token permission handling with switch statement#18741
Closed
github-actions[bot] wants to merge 2 commits intomainfrom
Closed
Conversation
Replace chained if/else with repeated nil-pointer dereferences with a
clean switch statement. Dereference IDToken once into a local variable,
then use a switch to separate the three distinct cases: explicitly
disabled ("none"), explicitly enabled ("write"), or auto-detected.
This follows the project convention of preferring switch statements
over chained if/else for multi-case logic.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Overview
Simplifies recently merged code from PR #18701 (OIDC/vault action auto-detection) by replacing chained
if/elseconditions with a cleanswitchstatement inpkg/workflow/safe_outputs_permissions.go.Files Simplified
pkg/workflow/safe_outputs_permissions.go— id-token permission logic inComputePermissionsForSafeOutputsImprovement Made
Before (repeated nil-pointer dereferences in chained if/else):
After (single nil deref, switch on the three distinct cases):
This eliminates the duplicated
safeOutputs.IDToken != nilnil-checks and uses a switch statement, per the project's standard of preferring switch statements over chained if/else for multi-case logic (per AGENTS.md).Changes Based On
Recent code merged from:
Testing
TestStepsRequireIDToken,TestComputePermissionsForSafeOutputs_IDToken)make build)Review Focus
Please verify that the three cases (explicit
"none", explicit"write", auto-detect) produce identical behavior to the original if/else chain.References: