Skip to content
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

feat: upgrade go libs #38

Merged
merged 1 commit into from
Jan 20, 2025
Merged

feat: upgrade go libs #38

merged 1 commit into from
Jan 20, 2025

Conversation

gfyrag
Copy link
Contributor

@gfyrag gfyrag commented Jan 20, 2025

No description provided.

Copy link

coderabbitai bot commented Jan 20, 2025

Walkthrough

This pull request involves a comprehensive update of import paths across multiple files in the project, transitioning from version 1 to version 2 of the go-libs library. The changes primarily focus on updating import statements to reference the new versioned library paths, specifically adding /v2/ to the import paths. These modifications ensure compatibility with the latest version of the shared library while maintaining the existing code's functionality and structure.

Changes

File Path Change Summary
cmd/root.go Updated import path for service package to v2
cmd/serve.go Updated import paths for multiple packages including sharedapi, auth, licence, otlp, otlptraces, and service to v2
pkg/api/* Multiple files updated with v2 import paths for packages like bunpaginate, pointer, metadata, api, health, service, auth, logging, time, collectionutils, httpserver
pkg/balance.go Updated import path for time package to v2
pkg/credit.go Updated import paths for time and metadata packages to v2
pkg/debit.go Updated import paths for time and metadata packages to v2
pkg/hold.go Updated import path for metadata package to v2
pkg/ledger_interface.go Updated import paths for query, time, collectionutils, metadata, and pointer packages to v2
pkg/manager.go Updated import paths for time and metadata packages to v2
pkg/metadata.go Updated import path for metadata package to v2
pkg/wallet.go Updated import path for metadata package to v2

Poem

🐰 Hop, skip, and a library jump!
Version two is now our chump
Import paths dancing with glee
From v1 to v2, we're free!
CodeRabbit's library upgrade, oh so neat! 🚀


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c6fc6e3 and b72e584.

⛔ Files ignored due to path filters (2)
  • go.mod is excluded by !**/*.mod
  • go.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (33)
  • cmd/root.go (1 hunks)
  • cmd/serve.go (1 hunks)
  • pkg/api/handler_balances_create_test.go (1 hunks)
  • pkg/api/handler_balances_list_test.go (1 hunks)
  • pkg/api/handler_holds_confirm.go (1 hunks)
  • pkg/api/handler_holds_confirm_test.go (1 hunks)
  • pkg/api/handler_holds_get_test.go (1 hunks)
  • pkg/api/handler_holds_list_test.go (1 hunks)
  • pkg/api/handler_holds_void.go (1 hunks)
  • pkg/api/handler_holds_void_test.go (1 hunks)
  • pkg/api/handler_transactions_list_test.go (1 hunks)
  • pkg/api/handler_wallets_create_test.go (1 hunks)
  • pkg/api/handler_wallets_credit.go (1 hunks)
  • pkg/api/handler_wallets_credit_test.go (1 hunks)
  • pkg/api/handler_wallets_debit.go (1 hunks)
  • pkg/api/handler_wallets_debit_test.go (1 hunks)
  • pkg/api/handler_wallets_get_test.go (1 hunks)
  • pkg/api/handler_wallets_list_test.go (1 hunks)
  • pkg/api/handler_wallets_patch.go (1 hunks)
  • pkg/api/handler_wallets_patch_test.go (1 hunks)
  • pkg/api/handler_wallets_summary_test.go (1 hunks)
  • pkg/api/module.go (1 hunks)
  • pkg/api/router.go (1 hunks)
  • pkg/api/utils.go (1 hunks)
  • pkg/api/utils_test.go (1 hunks)
  • pkg/balance.go (1 hunks)
  • pkg/credit.go (1 hunks)
  • pkg/debit.go (1 hunks)
  • pkg/hold.go (1 hunks)
  • pkg/ledger_interface.go (1 hunks)
  • pkg/manager.go (1 hunks)
  • pkg/metadata.go (1 hunks)
  • pkg/wallet.go (1 hunks)
✅ Files skipped from review due to trivial changes (29)
  • pkg/debit.go
  • pkg/wallet.go
  • pkg/api/handler_holds_confirm.go
  • pkg/hold.go
  • pkg/api/handler_holds_void.go
  • pkg/api/handler_wallets_patch.go
  • pkg/balance.go
  • cmd/root.go
  • pkg/api/module.go
  • pkg/ledger_interface.go
  • pkg/api/handler_wallets_create_test.go
  • pkg/api/handler_wallets_debit.go
  • pkg/api/handler_wallets_patch_test.go
  • pkg/api/handler_holds_confirm_test.go
  • pkg/metadata.go
  • pkg/api/utils_test.go
  • pkg/api/handler_wallets_summary_test.go
  • pkg/api/handler_wallets_credit_test.go
  • pkg/manager.go
  • pkg/api/handler_holds_list_test.go
  • pkg/api/handler_wallets_debit_test.go
  • pkg/api/handler_wallets_credit.go
  • pkg/api/handler_balances_create_test.go
  • pkg/api/handler_wallets_get_test.go
  • pkg/api/utils.go
  • pkg/api/handler_holds_void_test.go
  • pkg/api/handler_transactions_list_test.go
  • pkg/api/handler_wallets_list_test.go
  • pkg/api/handler_balances_list_test.go
🔇 Additional comments (6)
pkg/credit.go (1)

9-11: LGTM! Verify API compatibility with v2.

The import paths have been correctly updated to v2. Since this is a major version upgrade, we should verify that the v2 API is compatible with the current usage.

Let's verify the API compatibility and consistency:

✅ Verification successful

API compatibility verified - no issues found.

The code's usage of metadata.Metadata and time.Time from go-libs v2 is consistent with standard patterns and shows no signs of breaking changes. All imports have been correctly updated to v2 throughout the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if all go-libs imports are consistently updated to v2
rg --type go "github.com/formancehq/go-libs/(?!v2)" -l

# Check for any potential API changes by looking for type/method usage
rg --type go "metadata\.Metadata|time\.Time" -C 2

Length of output: 22578

pkg/api/handler_holds_get_test.go (2)

12-12: LGTM! Import path updated correctly for v2.

The import path change follows the Go modules versioning convention and aligns with the PR objective of upgrading go-libs.


12-12: Verify metadata package compatibility.

Since this is a major version upgrade (v1 to v2), let's verify that the metadata package API remains compatible, particularly the Metadata type usage in this test.

✅ Verification successful

The metadata package upgrade appears safe to proceed

The codebase uses only basic operations of the Metadata type (initialization, key-value assignment, and Merge method), which are fundamental features unlikely to change in a breaking way. No complex interactions or custom extensions were found that could be affected by the v1 to v2 upgrade.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential breaking changes in the metadata package between v1 and v2

# Search for all metadata package usages
echo "Searching for metadata package usage patterns..."
ast-grep --pattern 'metadata.Metadata{$$$}'

# Look for any type definitions or method signatures in the old version
echo "Checking old version metadata package..."
gh api repos/formancehq/go-libs/contents/metadata/metadata.go?ref=v1 | jq -r '.content' | base64 -d

# Compare with new version
echo "Checking new version metadata package..."
gh api repos/formancehq/go-libs/contents/metadata/metadata.go?ref=v2 | jq -r '.content' | base64 -d

Length of output: 10019


Script:

#!/bin/bash
# Check go.mod for package versions and search for metadata package method usage

# Check go.mod for package versions
echo "Checking go.mod for package versions..."
cat go.mod | grep "go-libs"

# Search for method calls on Metadata type
echo -e "\nSearching for Metadata method calls..."
ast-grep --pattern 'metadata.$_($$$)'

# Look for method declarations in current codebase
echo -e "\nSearching for local Metadata type extensions..."
ast-grep --pattern 'func ($_ metadata.Metadata) $_($$$) {
  $$$
}'

Length of output: 500

pkg/api/router.go (1)

8-8: Verify API compatibility with go-libs v2.

The import paths have been correctly updated to v2. However, we should verify that the v2 packages maintain API compatibility for the following critical components:

  • service.OTLPMiddleware
  • sharedapi.InfoHandler and ServiceInfo
  • auth.Middleware and Authenticator
  • sharedhealth.HealthController

Let's check for any breaking changes in the v2 APIs:

Also applies to: 10-12

✅ Verification successful

✓ go-libs v2 imports are correctly used and consistent

The codebase shows proper migration to v2 with:

  • Consistent usage of v2 packages across all files
  • No mixed versions detected
  • All required packages available in v2
  • Test files properly updated
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential breaking changes in v2 APIs

# Search for type/function definitions in both v1 and v2
echo "Searching for critical component definitions..."
rg --type go "type (ServiceInfo|Authenticator|HealthController)" 
rg --type go "func (InfoHandler|Middleware|OTLPMiddleware)"

# Look for any migration guides or breaking changes
echo "Checking for migration guides..."
fd -t f "MIGRATION|UPGRADE|CHANGELOG|README" -X cat {}

Length of output: 367


Script:

#!/bin/bash
# Check package structure and usage

# Check imports and their usage
echo "Checking imports and their usage..."
rg --type go "github.com/formancehq/go-libs/v2/(service|sharedapi|auth|sharedhealth)" -A 3

# Search for type definitions with broader patterns
echo "Searching for type definitions..."
ast-grep --pattern 'type ServiceInfo struct { $$$ }'
ast-grep --pattern 'type Authenticator interface { $$$ }'
ast-grep --pattern 'type HealthController struct { $$$ }'

# Search for function definitions
echo "Searching for function definitions..."
ast-grep --pattern 'func $$$Handler($$$) $$$'
ast-grep --pattern 'func $$$Middleware($$$) $$$'

Length of output: 1845

cmd/serve.go (2)

7-12: Verify FX module and flag handling compatibility.

The import paths have been correctly updated to v2. However, we should verify compatibility for:

  1. FX modules: otlptraces.FXModuleFromFlags, auth.FXModuleFromFlags, licence.FXModuleFromFlags
  2. Flag handling: AddFlags functions from multiple packages
  3. HTTP client setup: otlp.NewRoundTripper

Let's check for any breaking changes in these components:

✅ Verification successful

All module and flag handling patterns are consistent with v2

The codebase shows consistent usage of v2 imports and standard initialization patterns for:

  • FX modules (otlptraces, auth, licence)
  • Flag registration
  • HTTP client configuration with otlp.NewRoundTripper
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential breaking changes in FX modules and flag handling

# Search for FX module and flag handling implementations
echo "Searching for FX module implementations..."
rg --type go "func FXModuleFromFlags|func AddFlags"

# Search for RoundTripper implementation
echo "Searching for RoundTripper implementation..."
rg --type go "func NewRoundTripper"

# Look for any migration guides or breaking changes
echo "Checking for migration guides..."
fd -t f "MIGRATION|UPGRADE|CHANGELOG|README" -X cat {}

Length of output: 419


Script:

#!/bin/bash
# Description: Broader search for FX modules and related functionality

# Search for FX module usage patterns
echo "Searching for FX module usage..."
rg --type go -A 5 "otlptraces\.|auth\.|licence\."

# Search for flag-related code
echo "Searching for flag handling..."
rg --type go -A 3 "AddFlags|RegisterFlags"

# Search for HTTP client configuration
echo "Searching for HTTP client setup..."
rg --type go -A 5 "NewRoundTripper|RoundTripper"

# Check imports
echo "Checking import patterns..."
rg --type go "github.com/formancehq/go-libs"

Length of output: 7316


7-12: Consider updating the oauth2 scopes for v2 compatibility.

The HTTP client setup uses oauth2 with specific scopes. Verify if the scopes "openid ledger:read ledger:write" are still valid and sufficient for v2.

Let's check the scope requirements:

✅ Verification successful

The oauth2 scopes are correctly configured for v2 compatibility

The scopes "openid ledger:read ledger:write" are valid and properly integrated with the v2 auth package. The implementation shows correct usage of auth middleware and protected routes that align with these scope permissions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for scope requirements in v2

# Search for scope definitions or requirements
echo "Searching for scope definitions..."
rg --type go "Scopes.*ledger:"

Length of output: 185


Script:

#!/bin/bash
# Search for auth-related configuration and documentation
echo "Searching for auth configuration..."
rg -A 5 -B 5 "type AuthConfig" --type go

echo "\nSearching for auth scope usage..."
rg -A 3 "WithScopes|RequireScopes" --type go

echo "\nChecking README and docs..."
fd -e md -x cat {} \; | rg -i "scope|auth"

Length of output: 368


Script:

#!/bin/bash
# Search for auth-related patterns
echo "Checking auth package usage..."
rg --type go -A 5 "\"github.com/formancehq/go-libs/v2/auth\""

echo "\nChecking OAuth/OIDC configurations..."
rg --type go -A 3 "OAuth2|OIDC|OpenID"

echo "\nChecking auth middleware..."
ast-grep --pattern 'auth.NewMiddleware($$$)'

Length of output: 1334


Script:

#!/bin/bash
# Check router implementation
echo "Checking router implementation..."
rg -A 10 "func.*Router" pkg/api/router.go

echo "\nChecking auth configuration in serve.go..."
rg -A 10 "auth\." cmd/serve.go

Length of output: 2511

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@gfyrag gfyrag requested a review from paul-nicolas January 20, 2025 08:09
@gfyrag gfyrag merged commit ef61293 into main Jan 20, 2025
7 checks passed
@gfyrag gfyrag deleted the chore/upgrade-go-libs branch January 20, 2025 08:32
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.

2 participants