-
Notifications
You must be signed in to change notification settings - Fork 10
feature: fetch codacy default values for all tools patterns when no token init - PLUTO-1380 #119
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
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 preferencesFootnotes
|
783b122 to
0f54a01
Compare
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 enables fetching and using Codacy’s default patterns when no API token is provided and centralizes pattern-fetching logic in the codacy-client package.
- Support default tool patterns in CLI
initwhen no token is set - Add
GetDefaultToolPatternsConfigendpoint with generic pagination incodacy-client - Refactor init flags and wiring to use shared
domain.InitFlags
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| domain/patternConfiguration.go | Remove obsolete IsCustom field from PatternConfiguration. |
| domain/pagination.go | Introduce Pagination struct to model API pagination metadata. |
| domain/initFlags.go | Define InitFlags struct to hold CLI initialization flags. |
| codacy-client/client.go | Implement getRequest, handlePaginationGeneric, and default-pattern endpoint. |
| codacy-client/client_test.go | Add tests for HTTP requests and pagination; placeholder for default-patterns test. |
| cmd/init.go | Refactor init command to use domain.InitFlags and loop default patterns. |
| cmd/init_test.go | Add test for init with no token, creating default configuration files. |
Comments suppressed due to low confidence (3)
codacy-client/client_test.go:71
- The TestGetDefaultToolPatternsConfig_Empty is currently a placeholder and doesn’t invoke the function under test. Consider refactoring GetDefaultToolPatternsConfig to accept a configurable baseURL or HTTP client so you can write a real unit test without making live API calls.
// TODO: Refactor GetDefaultToolPatternsConfig to accept a baseURL for easier testing
cmd/init_test.go:221
- This test for init with no token will invoke buildDefaultConfigurationFiles and make real HTTP requests via GetDefaultToolPatternsConfig, which may lead to test flakiness. Consider mocking codacyclient.GetDefaultToolPatternsConfig or injecting a fake client to avoid network dependencies.
if err := buildDefaultConfigurationFiles(toolsConfigDir); err != nil {
cmd/init.go:483
- [nitpick] This standalone comment appears to be a leftover and doesn't add context. Consider removing it for clarity.
//
0f54a01 to
0b94fdd
Compare
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 enhances the Codacy CLI by fetching default tool patterns when no API token is provided and adds a new endpoint in the codacy-client package for tool pattern configuration. Key changes include the removal of the IsCustom field from the pattern configuration structure, the addition of a Pagination type and InitFlags struct for improved CLI flag management, and updated initialization and configuration generation logic within the CLI commands.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| domain/patternConfiguration.go | Removed the IsCustom field from PatternConfiguration |
| domain/pagination.go | Added a new Pagination struct to aid in API pagination handling |
| domain/initFlags.go | Introduced a new InitFlags struct with exported fields |
| codacy-client/client.go | Added GetDefaultToolPatternsConfig with generic pagination handling |
| codacy-client/client_test.go | Added tests for the new client functions and pagination handling |
| cmd/init.go & cmd/init_test.go | Updated init command and test to fetch default configurations in local mode |
Comments suppressed due to low confidence (2)
domain/patternConfiguration.go:26
- Ensure that the removal of the IsCustom field is intentional and that any consumers of the PatternConfiguration structure are updated to handle its absence, particularly for JSON (un)marshalling.
- IsCustom bool `json:"isCustom"`
codacy-client/client_test.go:76
- Consider refactoring GetDefaultToolPatternsConfig to accept a base URL or use dependency injection so that it becomes fully testable, which would improve test coverage.
// Placeholder: test cannot be run until function is refactored for testability
cmd/init_test.go
Outdated
| } | ||
|
|
||
| toolsConfigDir := config.Config.ToolsConfigDirectory() | ||
| if err := os.MkdirAll(toolsConfigDir, 0777); err != nil { |
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.
Not using File Perission from cosntants file
codacy-client/client.go
Outdated
| // - fetchPage: a function that fetches a page and returns ([]T, nextCursor, error) | ||
| // | ||
| // Returns a slice of all results of type T and any error encountered. | ||
| func handlePaginationGeneric[T any]( |
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.
- Consider calling this something that makes clear that is fetching all the pages, not just 'handling some output'. Maybe something as 'getAllPages' or something.
- This should not receive an 'initialCursor' as all the calls will just pass "". The idea of passing a cursor could at most be helpful if you were using recursion, and even then could be an Aux function, but as it is, I see no reason to have this parameter
- On the fetchPage arg, seems strange to be a func passing. The logic of fetching a page from an API, should not be a function pass, should be something that exists, some 'GetPage[T](url, cursor, parser)' that is clearly defined. Then this method should receive a parser of some sorts, that converts data => T. Then this getAllPages would in a loop call the GetPage propagating the parser and relying on the returned cursor for the next iteration.
Is this reasonable feedback? Maybe @andrzej-janczak has input?
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.
very reasonable of course. i pushed what I think it's an improvement.
9c480d8 to
1b58153
Compare
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 introduces support for fetching Codacy's default patterns when no API token is provided and adds a new endpoint in the codacy-client package to fetch tool patterns. Key changes include the removal of the unused "IsCustom" field in pattern configurations, the introduction of new pagination and initialization structs, and updates in both client and command implementations to support default configuration generation.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| domain/patternConfiguration.go | Removed the "IsCustom" field from the PatternConfiguration struct. |
| domain/pagination.go | Added a simple Pagination struct for API pagination handling. |
| domain/initFlags.go | Introduced a public InitFlags struct with updated field names. |
| codacy-client/client_test.go | Added tests for getRequest, GetPage, and getAllPages; noted a test for default patterns pending refactoring. |
| codacy-client/client.go | Added GetDefaultToolPatternsConfig and GetRepositoryToolPatterns functions; updated pagination handling in API calls. |
| cmd/init_test.go | Updated tests to verify configuration file creation in “no token” mode. |
| cmd/init.go | Updated flag definition and logic to support fetching default configurations when no token is provided. |
Comments suppressed due to low confidence (2)
domain/patternConfiguration.go:26
- Removal of the 'IsCustom' field should be reviewed to ensure that any logic or tests which previously relied on this property have been properly updated.
- IsCustom bool `json:"isCustom"`
codacy-client/client_test.go:103
- [nitpick] Consider refactoring GetDefaultToolPatternsConfig to accept a base URL or leverage dependency injection, which would improve testability and allow for full coverage of default tool patterns fetching.
// TODO: Refactor GetDefaultToolPatternsConfig to accept a baseURL for easier testing
…cy-client package where api requests should be handled
1b58153 to
9b41044
Compare
Use Codacy Default Patterns when no Token is provided
Overview
This PR introduces two main improvements:
codacy-clientpackage to fetch patterns for supported toolsChanges
Default Patterns Support
New Pattern Fetching Endpoint
GetDefaultToolPatternsConfigfunction incodacy-clientpackage