-
Notifications
You must be signed in to change notification settings - Fork 135
Refactor buildRunnerConfig to reduce cyclomatic complexity #2186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Extract middleware configuration and remote authentication logic into separate helper functions to reduce the cyclomatic complexity of buildRunnerConfig from 16 to below the gocyclo threshold of 15. Changes: - Add configureMiddlewareAndOptions helper function to handle middleware setup, authorization config loading, and environment file processing - Add configureRemoteAuth helper function to handle remote server metadata and direct remote URL authentication configuration - Maintain all existing functionality while improving code organization Fixes linter error: "cyclomatic complexity 16 of func buildRunnerConfig is high (> 15)" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2186 +/- ##
==========================================
- Coverage 53.13% 53.08% -0.05%
==========================================
Files 222 222
Lines 28904 28904
==========================================
- Hits 15359 15345 -14
- Misses 12402 12420 +18
+ Partials 1143 1139 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the buildRunnerConfig function to reduce its cyclomatic complexity from 16 to 15 by extracting conditional logic into two helper functions. The refactoring improves code organization without changing behavior.
Key Changes:
- Extracted middleware configuration logic into
configureMiddlewareAndOptionshelper function - Extracted remote authentication logic into
configureRemoteAuthhelper function
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
@claude please review this |
|
Claude finished @JAORMX's task —— View job Code Review CompleteTasks
Review SummaryThis PR successfully achieves its goal of reducing cyclomatic complexity through well-structured extraction of helper functions. The refactoring improves code organization and readability. However, there is a critical compilation error that needs to be addressed. Critical Issue: Compilation Error ❌Location: Problem: The function
Impact: This code will not compile correctly when the global Solution: Update // Line 551 - update the call site
remoteAuthConfig := getRemoteAuthFromRemoteServerMetadata(remoteServerMetadata, runFlags)
// Line 593 - update the function signature
func getRemoteAuthFromRemoteServerMetadata(remoteServerMetadata *registry.RemoteServerMetadata, runFlags *RunFlags) *runner.RemoteAuthConfig {This was correctly identified by the Copilot reviewer as well. Positive Aspects ✅
Additional Observations
RecommendationRequest Changes: The compilation error must be fixed before this can be merged. Once the Job Run | Branch: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blocking until we fix the issue
Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Summary
Refactor the
buildRunnerConfigfunction to reduce its cyclomatic complexity from 16 to below the gocyclo threshold of 15.Changes
configureMiddlewareAndOptionshelper functionconfigureRemoteAuthhelper functionTest plan
task lint-fix)task test)Technical Details
The
buildRunnerConfigfunction atcmd/thv/app/run_flags.go:390had a cyclomatic complexity of 16, which exceeded the configured threshold of 15. This was causing the gocyclo linter check to fail.The refactoring extracts conditional logic into focused helper functions:
configureMiddlewareAndOptions- Handles middleware setup, authorization config loading, OIDC/telemetry configuration, and environment file processingconfigureRemoteAuth- Handles remote server metadata authentication and direct remote URL authenticationThis reduces complexity while maintaining clear separation of concerns and improving code readability.
🤖 Generated with Claude Code