Conversation
Add Any() function to pkg/sliceutil for checking if any element satisfies a predicate. Apply it in pkg/cli to replace imperative for-break patterns with a functional, declarative style. Changes: - pkg/sliceutil/sliceutil.go: Add Any[T any] generic function - pkg/sliceutil/sliceutil_test.go: Add comprehensive tests for Any - pkg/cli/engine_secrets.go: Use sliceutil.Any for AlternativeEnvVars exists checks (2 locations), eliminating for+break patterns - pkg/cli/add_workflow_resolution.go: Use sliceutil.Any for hasWildcard detection; pre-allocate parsedSpecs slice with known capacity Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
pelikhan
approved these changes
Mar 12, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new generic sliceutil.Any helper and refactors several pkg/cli loops into a more declarative, short-circuiting predicate style.
Changes:
- Added
sliceutil.Any[T]to centralize “does any element match?” logic with early termination. - Replaced two
for { ... break }existence checks inpkg/cli/engine_secrets.gowithsliceutil.Any. - Updated
ResolveWorkflowsto (a) pre-allocateparsedSpecscapacity and (b) detect wildcards viasliceutil.Any.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/sliceutil/sliceutil.go | Introduces Any[T] predicate helper with short-circuit behavior. |
| pkg/sliceutil/sliceutil_test.go | Adds unit tests covering match/no-match, nil/empty, strings scenario, and early termination. |
| pkg/cli/engine_secrets.go | Simplifies alternative-secret existence checks using sliceutil.Any. |
| pkg/cli/add_workflow_resolution.go | Uses sliceutil.Any for wildcard detection and pre-allocates parsedSpecs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
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.
Applies moderate functional/immutability improvements to the
pkg/clipackage as part of a round-robin systematic refactoring pass.Round-Robin Progress: Run 1 of N — processed
pkg/cli. Next run will processpkg/console.Summary of Changes
New:
sliceutil.Any— Pure Predicate FunctionAdded
Any[T any](slice []T, predicate func(T) bool) booltopkg/sliceutil:trueif any element satisfies the predicate (short-circuits on first match)falsefor nil or empty slicesApplied in
pkg/cli/engine_secrets.go— 2 LocationsTwo identical
exists = true; breakimperative patterns replaced withsliceutil.Any:Applied in
pkg/cli/add_workflow_resolution.go— 2 Improvements1. Wildcard detection replaced with
sliceutil.Any:2. Slice pre-allocation with known capacity:
Benefits
sliceutil.Any(...)immediately expresses intent ("does any element satisfy X?") vs reading through a loop to understand ithasWildcard := false; ... hasWildcard = true) in favour of an immutable assignmentAnyis a general-purpose function; 3 immediate uses inpkg/cliconfirm it's worth havingsliceutil.Map,sliceutil.Filter,sliceutil.Contains—Anyfits naturally alongside themAnyshort-circuits on first match (verified byTestAny_StopsEarly)Testing
TestAny— 7 table-driven test cases covering all edge cases (empty, nil, match, no-match, all-match, single)TestAny_Strings— mirrors the real-worldexistingSecretspattern fromengine_secrets.goTestAny_StopsEarly— verifies short-circuit behaviourengine_secretstests pass (TestGetMissingRequiredSecrets,TestGetEngineSecretNameAndValue, etc.)make test-unit)make fmt)References: