Skip to content

refactore: using client package for API requests#123

Merged
franciscoovazevedo merged 5 commits intomainfrom
refactor-client-package
May 26, 2025
Merged

refactore: using client package for API requests#123
franciscoovazevedo merged 5 commits intomainfrom
refactor-client-package

Conversation

@franciscoovazevedo
Copy link
Copy Markdown
Contributor

No description provided.

@franciscoovazevedo franciscoovazevedo changed the base branch from main to pluto-1380 May 15, 2025 13:30
Copy link
Copy Markdown
Contributor

Copilot AI left a 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 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.

Comment thread tools/language_config.go
@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented May 15, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
-0.26% 13.45%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (44f78ac) 4678 1462 31.25%
Head commit (24bc3ab) 4607 (-71) 1428 (-34) 31.00% (-0.26%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#123) 119 16 13.45%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Copy link
Copy Markdown
Contributor

@machadoit machadoit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we have good tests now, it makes more confident moving forward

Comment thread cmd/init.go

var apiToolConfigurations []domain.PatternConfiguration
err = json.Unmarshal(objmap["data"], &apiToolConfigurations)
apiToolConfigurations, err := codacyclient.GetRepositoryToolPatterns(initFlags, tool.Uuid)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

@franciscoovazevedo franciscoovazevedo force-pushed the refactor-client-package branch 3 times, most recently from 7329f45 to 2f589f9 Compare May 19, 2025 16:39
@franciscoovazevedo franciscoovazevedo force-pushed the refactor-client-package branch from 2f589f9 to 24bc3ab Compare May 20, 2025 14:47
@franciscoovazevedo franciscoovazevedo changed the base branch from pluto-1380 to main May 20, 2025 14:48
Copy link
Copy Markdown
Contributor

Copilot AI left a 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 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 accept domain.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 codacyClient is inconsistent with the rest of the codebase which uses codacyclient. Rename to codacyclient for consistency.
codacyClient "codacy/cli-v2/codacy-client"

tools/lizard/lizardConfigCreator.go:93

  • [nitpick] Consider adding unit tests for getMetricTypeFromPatternId to cover edge cases like multiple hyphens or invalid formats.
metricType := strings.Join(metricParts[:len(metricParts)-1], "-")

cmd/init.go:284

  • The codacyclient package and domain are not imported in this file—add import "codacy/cli-v2/codacy-client" and import "codacy/cli-v2/domain" at the top.
apiToolConfigurations, err := codacyclient.GetRepositoryToolPatterns(initFlags, tool.Uuid)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 codacyclient methods (e.g., fetching tools, languages, patterns).
  • Updates functions and tests to use domain.InitFlags and domain model types.
  • Consolidates API parsing in codacy-client/client.go and 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.Printf or fmt.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 codacyclient package is not imported in this file, causing an undefined identifier error. Add import "codacy/cli-v2/codacy-client" with the alias codacyclient.
    apiToolConfigurations, err := codacyclient.GetRepositoryToolPatterns(initFlags, tool.Uuid)

tools/getTools.go:4

  • [nitpick] Alias casing for the codacy-client import is inconsistent (codacyClient vs. codacyclient). Standardize on one alias across the codebase to avoid confusion.
    codacyClient "codacy/cli-v2/codacy-client"

@franciscoovazevedo franciscoovazevedo merged commit a84eb7c into main May 26, 2025
10 checks passed
@alerizzo alerizzo deleted the refactor-client-package branch June 3, 2025 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants