Skip to content

feat: upgrade go libs#99

Open
Dav-14 wants to merge 2 commits intomainfrom
feat/upgrade-go-libs
Open

feat: upgrade go libs#99
Dav-14 wants to merge 2 commits intomainfrom
feat/upgrade-go-libs

Conversation

@Dav-14
Copy link
Contributor

@Dav-14 Dav-14 commented Dec 11, 2025

Summary by cubic

Upgrade go-libs to v3 and refresh dependencies for compatibility. Updated imports and fixed logger initialization to keep the CLI running smoothly.

  • Dependencies

    • Switched to github.com/formancehq/go-libs/v3 (v3.6.0).
    • Bumped Go to 1.24.4 (toolchain 1.25.4), cobra to 1.9.1, oauth2 to 0.31.0, and other indirect deps.
  • Migration

    • Updated imports to github.com/formancehq/go-libs/v3/* across commands and packages.
    • Migrated usage of api, logging, pointer, time, metadata, collectionutils, and service to v3 paths.

Written for commit c4a463c. Summary will update automatically on new commits.

@Dav-14 Dav-14 requested a review from a team as a code owner December 11, 2025 10:08
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 11, 2025

Walkthrough

Mostly import-path updates switching internal libs to their v3 module paths; one functional change in cmd/root.go alters logger initialization to use service.IsDebug(cmd) and an output-format check for JSON.

Changes

Cohort / File(s) Summary
Pointer imports
cmd/cloud/apps/list.go, cmd/cloud/apps/runs/list.go, cmd/cloud/apps/variables/list.go, cmd/cloud/apps/versions/list.go, cmd/cloud/organizations/authentication-provider/configure.go, cmd/cloud/organizations/create.go, cmd/cloud/organizations/oauth-clients/create.go, cmd/cloud/organizations/oauth-clients/update.go, cmd/ledger/create.go, cmd/ledger/import.go, cmd/ledger/transactions/revert.go, cmd/orchestration/triggers/create.go, cmd/stack/create.go, cmd/stack/update.go, cmd/stack/upgrade.go
Updated import from github.com/formancehq/go-libs/pointergithub.com/formancehq/go-libs/v3/pointer; no code/behavior changes.
CollectionUtils imports
cmd/ledger/accounts/set_metadata.go, cmd/ledger/accounts/show.go, cmd/ledger/internal/print.go, cmd/ledger/send.go, cmd/ledger/transactions/list.go, cmd/ledger/transactions/num.go, cmd/ledger/transactions/set_metadata.go, cmd/payments/connectors/configs/getconfig.go, cmd/profiles/setdefaultorganization.go, cmd/profiles/setdefaultstack.go, pkg/organization.go, pkg/stack.go, pkg/versions.go
Updated import from github.com/formancehq/go-libs/collectionutilsgithub.com/formancehq/go-libs/v3/collectionutils; no code/behavior changes.
Time imports
cmd/stack/modules/list.go, pkg/printer/log.go
Updated import from github.com/formancehq/go-libs/timegithub.com/formancehq/go-libs/v3/time; no code/behavior changes.
Logging imports
pkg/clients.go, pkg/profile.go
Updated import from github.com/formancehq/go-libs/logginggithub.com/formancehq/go-libs/v3/logging; no code/behavior changes.
Metadata imports
pkg/metadata.go
Updated import from github.com/formancehq/go-libs/metadatagithub.com/formancehq/go-libs/v3/metadata; no code/behavior changes.
API / root changes
cmd/root.go
Updated imports to v3 (.../v3/api, .../v3/logging, added .../v3/service) and replaced logger initialization with service.IsDebug(cmd) plus output-format check (OutputFlag == "json"); this affects pre-run initialization logic.
Misc. updates
pkg/clients.go, pkg/profile.go, pkg/organization.go, pkg/stack.go, pkg/versions.go
Various v3 import path updates (logging, collectionutils, metadata); import-only edits except cmd/root.go above.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Pay extra attention to:
    • cmd/root.go (logger/service initialization and new imports).
    • go.mod (module replacements / v3 module entries).
    • A quick build to ensure no import or API breaks from v3 packages.

Poem

🐇 I hopped through imports, swift and spry,

Paths refreshed beneath the sky.
V3 threads woven, neat and bright,
A carrot crunch — the code compiles right.
— signed, the little repo rabbit 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: upgrade go libs' accurately describes the primary change: upgrading dependencies to go-libs v3 across the codebase.
Description check ✅ Passed The description provides relevant context about upgrading go-libs to v3, updated imports, dependency versions, and logger initialization changes.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/upgrade-go-libs

Comment @coderabbitai help to get the list of available commands and usage tips.

@Dav-14 Dav-14 enabled auto-merge (squash) December 11, 2025 10:09
@Dav-14 Dav-14 force-pushed the feat/upgrade-go-libs branch from 8dae28d to c7535da Compare December 11, 2025 10:10
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
pkg/organization.go (1)

50-53: Harden the capabilities type assertion to avoid potential panics

value.([]interface{}) will panic if the capability’s underlying type ever changes (or is nil), which makes this path brittle for server‑side changes.

Consider guarding the assertion and surfacing a clearer error instead of panicking:

-        if value, ok := capabilities[key]; ok {
-            if values := value.([]interface{}); len(values) > 0 {
-                if !checker(values) {
-                    return fmt.Errorf("unsupported membership server version: %s", value)
-                }
-            }
-        }
+        if value, ok := capabilities[key]; ok {
+            values, ok := value.([]interface{})
+            if !ok {
+                return fmt.Errorf("unexpected capability type for %q: %T", key, value)
+            }
+            if len(values) > 0 && !checker(values) {
+                return fmt.Errorf("unsupported membership server version: %v", value)
+            }
+        }

Please verify this matches the actual shape of region.Data.Capabilities and adjust the error handling if you prefer a softer failure (e.g., just skipping unknown/invalid types).

cmd/ledger/import.go (1)

121-148: Optional: simplify bufio.Scanner error/EOF handling

Inside the scan loop you call scanner.Err() on every iteration and check it against io.EOF, but bufio.Scanner never reports io.EOF via Err()—EOF is signaled by Scan() returning false. A more idiomatic pattern is:

scanner := bufio.NewScanner(f)
for scanner.Scan() {
    // use scanner.Bytes()
}
if err := scanner.Err(); err != nil {
    return nil, fmt.Errorf("error reading file: %w", err)
}

This would remove the redundant io.EOF check and the per-iteration scannerErr logic while preserving behavior.

cmd/ledger/internal/print.go (1)

191-195: Use the provided writer instead of stdout in PrintMetadata

PrintMetadata takes an io.Writer, but in the len(metadata) == 0 branch it calls fmt.Println("No metadata."), which bypasses the supplied writer and always writes to stdout. This is inconsistent with the rest of the function.

Consider:

-    fmt.Println("No metadata.")
+    fmt.Fprintln(out, "No metadata.")

to keep all output routed through out.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 0daa404 and 8dae28d.

⛔ Files ignored due to path filters (2)
  • go.mod is excluded by !**/*.mod
  • go.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (34)
  • cmd/cloud/apps/list.go (1 hunks)
  • cmd/cloud/apps/runs/list.go (1 hunks)
  • cmd/cloud/apps/variables/list.go (1 hunks)
  • cmd/cloud/apps/versions/list.go (1 hunks)
  • cmd/cloud/organizations/authentication-provider/configure.go (1 hunks)
  • cmd/cloud/organizations/create.go (1 hunks)
  • cmd/cloud/organizations/oauth-clients/create.go (1 hunks)
  • cmd/cloud/organizations/oauth-clients/update.go (1 hunks)
  • cmd/ledger/accounts/set_metadata.go (1 hunks)
  • cmd/ledger/accounts/show.go (1 hunks)
  • cmd/ledger/create.go (1 hunks)
  • cmd/ledger/import.go (1 hunks)
  • cmd/ledger/internal/print.go (1 hunks)
  • cmd/ledger/send.go (1 hunks)
  • cmd/ledger/transactions/list.go (1 hunks)
  • cmd/ledger/transactions/num.go (1 hunks)
  • cmd/ledger/transactions/revert.go (1 hunks)
  • cmd/ledger/transactions/set_metadata.go (1 hunks)
  • cmd/orchestration/triggers/create.go (1 hunks)
  • cmd/payments/connectors/configs/getconfig.go (1 hunks)
  • cmd/profiles/setdefaultorganization.go (1 hunks)
  • cmd/profiles/setdefaultstack.go (1 hunks)
  • cmd/root.go (2 hunks)
  • cmd/stack/create.go (1 hunks)
  • cmd/stack/modules/list.go (1 hunks)
  • cmd/stack/update.go (1 hunks)
  • cmd/stack/upgrade.go (1 hunks)
  • pkg/clients.go (1 hunks)
  • pkg/metadata.go (1 hunks)
  • pkg/organization.go (1 hunks)
  • pkg/printer/log.go (1 hunks)
  • pkg/profile.go (1 hunks)
  • pkg/stack.go (1 hunks)
  • pkg/versions.go (1 hunks)
🔇 Additional comments (35)
pkg/profile.go (1)

23-23: Logging import path bump looks correct; ensure v3 API compatibility and module update

The switch to github.com/formancehq/go-libs/v3/logging is consistent with the PR’s goal and matches how logging is used in this file (logging.FromContext(ctx).Debug/Debugf). Assuming FromContext and the returned logger’s interface are unchanged in v3, this should be a drop‑in upgrade. Please double‑check that:

  • go.mod requires the appropriate github.com/formancehq/go-libs/v3 version, and
  • go test ./... (and any relevant integration checks) pass, confirming there are no subtle behavior changes in the logging package.
pkg/printer/log.go (1)

9-9: Import path update to v3 is correct and consistent across the codebase.

The change from github.com/formancehq/go-libs/time to github.com/formancehq/go-libs/v3/time at line 9 is correct. Verification confirms all 36 go-libs imports across the codebase (api, collectionutils, logging, metadata, pointer, time) have been consistently upgraded to v3, with no unversioned imports remaining.

pkg/clients.go (1)

13-13: Verify go-libs v3 logging API compatibility before merging.

The import path update from github.com/formancehq/go-libs/logging to github.com/formancehq/go-libs/v3/logging involves a major version bump. While the current usage (logging.Debug() at line 38) is simple, v3 as a major release can introduce breaking changes. Confirm that the v3 logging package maintains the Debug() method signature used in this file by checking the go-libs v3 release notes or release diff.

pkg/metadata.go (1)

11-11: Import upgrade to v3 metadata package is correct.

The import path has been properly updated to use the v3 module version. The metadata.Metadata type maintains full API compatibility, supporting map-like operations (initialization, indexing, length checks, and range iteration) as used throughout the file.

pkg/organization.go (1)

8-8: Import upgrade to go-libs/v3/collectionutils looks correct; verify module usage is consistent

The path change to github.com/formancehq/go-libs/v3/collectionutils matches the v3 module layout and keeps the existing Reduce call intact. Before merging, confirm that:

  • go.mod requires github.com/formancehq/go-libs/v3 (not v2 or legacy versions)
  • No remaining imports of the v2 github.com/formancehq/go-libs/collectionutils exist elsewhere in the codebase
  • All other files that use collectionutils are updated consistently to v3
cmd/profiles/setdefaultstack.go (1)

10-10: Import path migration to collectionutils v3 looks correct

Only the import path was changed; collectionutils.Reduce usage in stackCompletion remains consistent, and no other issues are apparent in this file.

Please confirm CI / go test ./... passes with github.com/formancehq/go-libs/v3/collectionutils declared in go.mod.

cmd/stack/upgrade.go (1)

11-11: Pointer helper import updated to v3 consistently

The import now targets github.com/formancehq/go-libs/v3/pointer, and pointer.For(specifiedVersion) is still used correctly to populate req.Version; no additional issues spotted in this file.

Please ensure the v3 pointer module is present in go.mod and that the membership client still expects a *string for StackVersion.Version.

cmd/stack/modules/list.go (1)

7-7: Time wrapper import migrated to v3 without logic changes

Importing github.com/formancehq/go-libs/v3/time and using time.Time{Time: module.LastStateUpdate} in Render remains consistent with the existing pattern; no new issues identified.

Please confirm the generated membership client’s LastStateUpdate / LastStatusUpdate types are still compatible with the v3 time.Time wrapper.

cmd/profiles/setdefaultorganization.go (1)

10-10: Collectionutils import upgrade appears safe

The switch to github.com/formancehq/go-libs/v3/collectionutils keeps the Reduce call in organizationCompletion identical in structure; no other changes in this file.

Please verify the project builds cleanly with the v3 collectionutils dependency (e.g., via CI or go build ./...).

cmd/cloud/organizations/create.go (1)

6-6: Pointer import migrated to v3 for organization creation

pointer.For(domain) still correctly supplies a *string for orgData.Domain; the only change is the import path to go-libs/v3/pointer.

Please confirm the membership client’s OrganizationData.Domain field type still matches the pointer helper’s return type after the v3 upgrade.

cmd/cloud/apps/list.go (1)

7-7: Apps listing now uses v3 pointer helper

The pagination parameters still use pointer.For(int64(page)) and pointer.For(int64(pageSize)); only the import was updated to go-libs/v3/pointer.

Please ensure the deploy server client still expects *int64 for these arguments and that builds/tests pass with the v3 pointer dependency.

cmd/ledger/create.go (1)

12-12: Ledger create command correctly switched to v3 pointer

The Bucket field is still populated via pointer.For(...); the import now points to github.com/formancehq/go-libs/v3/pointer, with no surrounding logic changes.

Please confirm the Formance SDK V2CreateLedgerRequest.Bucket type is still compatible with the v3 pointer helper return type.

pkg/stack.go (1)

8-8: Collectionutils import in stack helpers updated cleanly to v3

collectionutils.Reduce usage in StackCompletion is unchanged apart from the import path, and the rest of the file is unaffected.

Please make sure the v3 collectionutils module is referenced in go.mod and that auto-completion behavior is validated via existing tests or manual checks.

cmd/cloud/organizations/oauth-clients/update.go (1)

9-9: Import path bump to go-libs/v3/pointer looks correct

The switch to github.com/formancehq/go-libs/v3/pointer is consistent with the rest of the PR and keeps pointer.For usage intact, so behavior should be unchanged as long as go.mod references the v3 module.

Please ensure go mod tidy and go test ./cmd/cloud/organizations/oauth-clients/... pass after the module upgrade.

cmd/ledger/transactions/num.go (1)

13-13: Collectionutils v3 import aligns with existing usage

Updating to github.com/formancehq/go-libs/v3/collectionutils while keeping ConvertMap(..., collectionutils.ToAny[string]) as-is should be a no-op behavior-wise, assuming the v3 API is compatible.

After updating go.mod to the v3 module, please run go test ./cmd/ledger/transactions/... to confirm there are no type or import resolution issues.

cmd/ledger/import.go (1)

18-18: Pointer import upgraded to v3 without behavior change

Using github.com/formancehq/go-libs/v3/pointer with pointer.For[int64](1) for PageSize keeps the request semantics the same; this looks consistent with the rest of the migration.

Confirm go.mod includes the v3 module and that go test ./cmd/ledger/... passes so the generic pointer.For usage still type-checks as expected.

cmd/ledger/transactions/revert.go (1)

7-7: Revert command pointer import migration looks sound

Switching to github.com/formancehq/go-libs/v3/pointer while keeping pointer.For(true) for AtEffectiveDate preserves the request shape; no behavioral changes expected.

Please verify that the new go-libs v3 dependency is present in go.mod and that go test ./cmd/ledger/transactions/... passes.

cmd/orchestration/triggers/create.go (1)

11-11: Pointer v3 import in trigger creation is consistent

Using github.com/formancehq/go-libs/v3/pointer for pointer.For(filter) keeps the optional Filter behavior intact; the change is limited to the module path.

After updating dependencies, rerun go test ./cmd/orchestration/triggers/... to ensure the v3 pointer API remains compatible.

cmd/ledger/internal/print.go (1)

13-13: Collectionutils v3 import matches existing usage

The move to github.com/formancehq/go-libs/v3/collectionutils keeps Map and ConvertMap(..., ToFmtString) usage the same, so behavior should be unchanged with a compatible v3.

Please confirm go test ./cmd/ledger/internal/... passes with the upgraded dependency.

cmd/ledger/accounts/show.go (1)

11-11: Accounts show: collectionutils v3 import looks good

Updating to github.com/formancehq/go-libs/v3/collectionutils while keeping ConvertMap(c.store.Account.Metadata, collectionutils.ToFmtString) should be behaviorally identical with a compatible v3.

Once go.mod references the v3 module, please run go test ./cmd/ledger/accounts/... to double-check for any API drift.

cmd/cloud/apps/variables/list.go (1)

9-9: Variables list: pointer v3 import is consistent with usage

The change to github.com/formancehq/go-libs/v3/pointer keeps the paging parameters wrapped via pointer.For(int64(...)), so the request contract remains the same.

After updating dependencies, please verify with go test ./cmd/cloud/apps/variables/... (and/or a quick manual run) that paging still behaves as expected.

cmd/ledger/transactions/set_metadata.go (1)

8-8: LGTM!

The import path has been correctly updated to use the v3 module, and the usage of collectionutils.ConvertMap and collectionutils.ToAny remains unchanged.

cmd/cloud/apps/runs/list.go (1)

9-9: LGTM!

The import path has been correctly updated to use the v3 module, and the usage of pointer.For remains unchanged.

cmd/cloud/organizations/oauth-clients/create.go (1)

6-6: LGTM!

The import path has been correctly updated to use the v3 module, and the usage of pointer.For remains unchanged.

cmd/cloud/organizations/authentication-provider/configure.go (1)

9-9: LGTM!

The import path has been correctly updated to use the v3 module, and the usage of pointer.For remains unchanged.

cmd/ledger/accounts/set_metadata.go (1)

8-8: LGTM!

The import path has been correctly updated to use the v3 module, and the usage of collectionutils.ConvertMap and collectionutils.ToAny remains unchanged.

cmd/cloud/apps/versions/list.go (1)

10-10: LGTM!

The import path has been correctly updated to use the v3 module, and the usage of pointer.For remains unchanged.

cmd/payments/connectors/configs/getconfig.go (1)

12-12: Import path is correct and API is compatible.

The v3 collectionutils module is already used throughout the codebase with multiple functions (Filter, Reduce, Map, ConvertMap, Contains) in active use, confirming API compatibility. This import path upgrade aligns with the broader v3 libs upgrade effort across the project.

cmd/stack/update.go (1)

7-7: Import path upgrade looks good.

The import path has been correctly updated to the v3 module. However, the pointer package API compatibility cannot be definitively verified due to conflicting information—while the code consistently uses pointer.For() throughout the codebase, automated searches could not confirm the package's existence or its API stability in v3. Manual verification of the formancehq/go-libs v3 documentation or release notes may be needed to ensure the For function is compatible with the v3 release.

cmd/stack/create.go (1)

12-12: LGTM! Import path updated to v3.

The migration from unversioned to v3 pointer package is correct, and usage remains consistent throughout the file.

cmd/ledger/transactions/list.go (1)

13-14: LGTM! Import paths updated to v3.

Both collectionutils and pointer packages have been correctly migrated to v3 with consistent usage throughout the file.

cmd/ledger/send.go (1)

11-11: LGTM! Import path updated to v3.

The collectionutils package has been correctly migrated to v3 with consistent usage.

cmd/root.go (2)

16-18: LGTM! Import paths updated to v3.

The api, logging, and service packages have been correctly migrated to v3.


109-109: The code reviewed does not match the description. Line 109 in cmd/root.go contains cmd := NewRootCommand(), not service.Execute(). No service.Execute() call exists in the file. The review is addressing non-existent code.

Likely an incorrect or invalid review comment.

pkg/versions.go (1)

9-9: LGTM! Import upgrade to v3 is syntactically correct.

The import path upgrade to github.com/formancehq/go-libs/v3/collectionutils is valid and consistent with the PR objectives. The usage at line 42 (collectionutils.Contains(serverInfo.Capabilities, capability)) follows the standard two-argument pattern for this utility function.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 36 files

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
cmd/root.go (1)

74-77: Logger initialization wiring is reasonable; consider env and case handling for JSON mode

logging.NewDefaultLogger(cmd.OutOrStdout(), service.IsDebug(cmd), fctl.GetString(cmd, fctl.OutputFlag) == "json", false) correctly ties:

  • debug mode to service.IsDebug(cmd), and
  • JSON logging to the output flag value "json".

Two minor behavioral nuances to be aware of:

  • fctl.GetString only falls back to the OUTPUT env var when the flag value is empty, but the flag’s default is "plain", so the env var won’t affect JSON mode unless you change the defaulting strategy.
  • The equality check is case-sensitive, so --output JSON or OUTPUT=JSON would not enable JSON logging.

If you want env/flag values like "JSON" or mixed-case to work, or you want OUTPUT to override the default, you could normalize the value (e.g., strings.ToLower(...)) and/or handle the default separately.

Please confirm that the intended UX is: JSON logging only when --output json (exact lowercase) is passed, and that you don’t need OUTPUT env or case-insensitive handling here. If needed, we can adjust the expression accordingly.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between c7535da and c4a463c.

📒 Files selected for processing (1)
  • cmd/root.go (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
cmd/root.go (1)
pkg/flags.go (2)
  • GetString (35-41)
  • OutputFlag (17-17)
🔇 Additional comments (1)
cmd/root.go (1)

16-18: go-libs/v3 import updates look consistent with usage

The updated imports for api, logging, and service align with how they’re used later in this file (e.g., api.ErrorResponse, logging.ContextWithLogger, service.IsDebug). Assuming go.mod is pinned to github.com/formancehq/go-libs/v3 at the intended version, this looks good.

Please double-check that go.mod and go.sum are updated to the same go-libs v3 version you expect and run go test ./... to confirm there are no hidden API mismatches.

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.

1 participant