refactore: using client package for API requests#123
refactore: using client package for API requests#123franciscoovazevedo merged 5 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR refactors API requests by replacing manual HTTP calls with the codacyclient package and updating types to use the domain package. Key changes include updating function signatures and error handling in multiple files, consolidating tool and language definitions into the domain package, and adapting tests accordingly.
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tools/language_config_test.go | Updated tests to use the domain.Tool type. |
| tools/language_config.go | Refactored API calls to use codacyclient.GetRepositoryLanguages; updated type usage. |
| tools/getTools.go | Updated API client integration for fetching tools and their versions. |
| domain/tool.go | Introduced the domain.Tool type to standardize tool definitions. |
| domain/language.go | Introduced domain types for language configuration. |
| codacy-client/client_test.go | Updated tests to match the modified getRequest signature in the client. |
| codacy-client/client.go | Refactored API request functions and streamlined error handling. |
| cmd/init_test.go | Adapted tests to use domain.Tool instead of tools.Tool. |
| cmd/init.go | Updated configuration file generation to use new API call methods. |
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferences |
machadoit
left a comment
There was a problem hiding this comment.
Since we have good tests now, it makes more confident moving forward
|
|
||
| var apiToolConfigurations []domain.PatternConfiguration | ||
| err = json.Unmarshal(objmap["data"], &apiToolConfigurations) | ||
| apiToolConfigurations, err := codacyclient.GetRepositoryToolPatterns(initFlags, tool.Uuid) |
1b58153 to
9b41044
Compare
7329f45 to
2f589f9
Compare
2f589f9 to
24bc3ab
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR refactors API calls to use the centralized codacyclient package and domain types for configuration generation.
- Replaced direct HTTP requests with
codacyclient.Get*functions and updated function signatures to acceptdomain.InitFlags. - Updated imports across tools and command code to use domain models and the new client.
- Removed inline request logic, moved pagination and parsing into client helpers.
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tools/lizard/lizardConfigCreator.go | Simplified metric-type extraction logic |
| tools/language_config.go | Swapped inline HTTP for codacyclient.GetRepositoryLanguages |
| tools/getTools.go | Swapped inline HTTP for codacyclient.GetRepositoryTools and versions |
| codacy-client/client.go | Updated getRequest signature to accept raw token, centralized base URL |
| cmd/init.go | Updated calls to tools package to use domain.InitFlags and codacyclient |
| domain/*.go | Added InitFlags, domain models for tools, languages, pagination, patterns |
| tests | Adjusted tests to use new signatures and domain types |
Comments suppressed due to low confidence (3)
tools/getTools.go:4
- [nitpick] The import alias
codacyClientis inconsistent with the rest of the codebase which usescodacyclient. Rename tocodacyclientfor consistency.
codacyClient "codacy/cli-v2/codacy-client"
tools/lizard/lizardConfigCreator.go:93
- [nitpick] Consider adding unit tests for
getMetricTypeFromPatternIdto cover edge cases like multiple hyphens or invalid formats.
metricType := strings.Join(metricParts[:len(metricParts)-1], "-")
cmd/init.go:284
- The
codacyclientpackage anddomainare not imported in this file—addimport "codacy/cli-v2/codacy-client"andimport "codacy/cli-v2/domain"at the top.
apiToolConfigurations, err := codacyclient.GetRepositoryToolPatterns(initFlags, tool.Uuid)
There was a problem hiding this comment.
Pull Request Overview
Refactors the code to centralize API interactions through the codacyclient package and standardize on shared domain types and InitFlags.
- Replaces inline HTTP request logic with calls to
codacyclientmethods (e.g., fetching tools, languages, patterns). - Updates functions and tests to use
domain.InitFlagsand domain model types. - Consolidates API parsing in
codacy-client/client.goand removes redundant client code.
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tools/lizard/lizardConfigCreator.go | Updated metric‐type extraction logic |
| tools/language_config.go | Switched to codacyclient for fetching repository languages |
| tools/getTools.go | Replaced inline HTTP with codacyClient calls |
| codacy-client/client.go | Centralized request functions and added pagination support |
| cmd/init.go | Updated repository build logic to use InitFlags and client APIs |
| codacy-client/client_test.go | Adapted tests to new getRequest signature |
| domain/patternConfiguration.go | Added new domain types for patterns and pagination |
Comments suppressed due to low confidence (4)
tools/lizard/lizardConfigCreator.go:80
- [nitpick] Consider using
log.Printforfmt.Fprintln(os.Stderr, ...)for warnings so they are sent to stderr and captured by standard logging.
fmt.Printf("Warning: Invalid pattern ID format: %s\n", patternID)
codacy-client/client.go:126
- PatternDefinition does not include Parameters or Enabled fields, so referencing patternDef.Parameters and patternDef.Enabled will not compile. Consider parsing into domain.PatternResponse or adjust to use the correct struct before mapping into PatternConfiguration.
Parameters: patternDef.Parameters,
cmd/init.go:284
- The
codacyclientpackage is not imported in this file, causing an undefined identifier error. Addimport "codacy/cli-v2/codacy-client"with the aliascodacyclient.
apiToolConfigurations, err := codacyclient.GetRepositoryToolPatterns(initFlags, tool.Uuid)
tools/getTools.go:4
- [nitpick] Alias casing for the
codacy-clientimport is inconsistent (codacyClientvs.codacyclient). Standardize on one alias across the codebase to avoid confusion.
codacyClient "codacy/cli-v2/codacy-client"
No description provided.