Skip to content

Conversation

@ReneWerner87
Copy link
Member

@ReneWerner87 ReneWerner87 commented Nov 3, 2025

Summary

  • add a migration that rewrites github.com/gofiber/contrib imports and go.mod entries to the v3 module path and cover it with tests
  • update contrib refresh logic and tests to use the new github.com/gofiber/contrib/v3 prefix
  • align the monitor import migration and integration tests with the contrib v3 packages

Testing

  • make lint
  • make test

https://chatgpt.com/codex/tasks/task_e_6907e5507e1c83269ab613f940ed562c

Summary by CodeRabbit

  • New Features

    • Added automatic migration support for GoFiber contrib packages, updating references from v2 to v3 module paths in source files and dependencies.
  • Tests

    • Added migration verification tests including idempotency checks to ensure repeated migrations work correctly.

@coderabbitai
Copy link

coderabbitai bot commented Nov 3, 2025

Walkthrough

The PR introduces a new v3 migration that systematically updates Go Fiber contrib package references from github.com/gofiber/contrib to github.com/gofiber/contrib/v3 by scanning Go source files and go.mod files, updating import statements and module paths, and ensuring existing version prefixes are not duplicated.

Changes

Cohort / File(s) Summary
Migration Registration
cmd/internal/migrations/lists.go
Inserts v3migrations.MigrateContribPackages into the V3 migration Functions list for version range >=2.0.0-0 to <4.0.0-0
Contrib Packages Migration Implementation
cmd/internal/migrations/v3/contrib_packages.go
Adds new MigrateContribPackages function to update imports and go.mod files from github.com/gofiber/contrib to github.com/gofiber/contrib/v3, with helper hasVersionPrefix to detect existing version prefixes and conditional output based on changes made
Contrib Packages Migration Tests
cmd/internal/migrations/v3/contrib_packages_test.go
Adds three test functions: basic migration, migration with replace directives, and idempotent verification to ensure migrations do not re-run on already-migrated code
Monitor Import Migration Update
cmd/internal/migrations/v3/monitor_import.go, cmd/internal/migrations/v3/monitor_import_test.go
Updates monitor middleware import replacement target from github.com/gofiber/contrib/monitor to github.com/gofiber/contrib/v3/monitor
Third-party Integration Updates
cmd/third_party.go, cmd/third_party_test.go
Introduces contribModulePrefix ("github.com/gofiber/contrib/v3/") and contribRepoPrefix ("gofiber/contrib/v3") constants; rewrites contrib module paths, URL construction, and version derivation to use new v3 prefixes
Main Test Update
cmd/migrate_test.go
Updates TestMain to expect the v3 monitor import path github.com/gofiber/contrib/v3/monitor

Sequence Diagram

sequenceDiagram
    participant User as Calling Code
    participant MCP as MigrateContribPackages
    participant FCH as ChangeFileContent
    participant FS as Filesystem Walk
    participant IO as File I/O

    User->>MCP: Invoke with cwd
    MCP->>FCH: Transform Go imports<br/>(contrib → contrib/v3)
    FCH->>FCH: Check hasVersionPrefix<br/>to skip if v3 exists
    FCH-->>MCP: Imports updated<br/>(changed flag)
    
    MCP->>FS: Walk directories<br/>for go.mod files
    FS->>IO: Read go.mod entries
    IO-->>FS: Module lines
    FS->>FS: Replace contrib paths<br/>(contrib/... → contrib/v3/...)
    FS->>IO: Write updated go.mod
    IO-->>FS: Write complete
    FS-->>MCP: Walk complete<br/>(changed flag)
    
    alt Any changes made
        MCP->>User: Print "Migrating<br/>contrib packages"
    else No changes
        MCP->>User: No output
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • New migration function with file I/O, regex-based replacements, and recursive filesystem traversal requires careful verification of path handling and error propagation
  • Three comprehensive test cases provide good coverage but require validation of edge cases (replace directives, idempotency)
  • Multiple files updated consistently (monitor_import.go, third_party.go, related tests) suggest refactoring pattern; verify consistency across all contrib path references
  • Helper function hasVersionPrefix logic should be verified to prevent double-migrations

Possibly related PRs

Suggested labels

✏️ Feature

Poem

🐰 Hopping through packages with v3 in sight,
Updating contrib paths, getting them right,
Monitor imports now march in formation,
A migration most thorough, no hesitation!
From old to the new, the rabbits rejoice,

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description is incomplete relative to the template requirements. While the description provides a summary of what was changed (new migration, updated contrib refresh logic, aligned monitor imports) and includes testing steps, it fails to address the critical template section: "Explain the details for making this change. What existing problem does the pull request solve?" The description lacks context about why the v3 migration is necessary, what problem it solves, or the motivation behind updating to the v3 module paths. The description reads as a list of changes rather than an explanation of the rationale and problem being solved.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title "Add contrib v3 migration and update contrib tooling" accurately reflects the main changes in the changeset. The title specifically references the addition of a new contrib v3 migration (the MigrateContribPackages function) and updates to contrib tooling (the third_party.go modifications and related constants), which are the primary changes evident across the file modifications. The title is concise, clear, and provides meaningful information about the primary changes without unnecessary detail.
✨ 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 codex/2025-11-03-07-44-56

📜 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 9819fc0 and 9a65406.

📒 Files selected for processing (8)
  • cmd/internal/migrations/lists.go (1 hunks)
  • cmd/internal/migrations/v3/contrib_packages.go (1 hunks)
  • cmd/internal/migrations/v3/contrib_packages_test.go (1 hunks)
  • cmd/internal/migrations/v3/monitor_import.go (1 hunks)
  • cmd/internal/migrations/v3/monitor_import_test.go (1 hunks)
  • cmd/migrate_test.go (1 hunks)
  • cmd/third_party.go (6 hunks)
  • cmd/third_party_test.go (2 hunks)
🧰 Additional context used
🧠 Learnings (9)
📓 Common learnings
Learnt from: ReneWerner87
Repo: gofiber/recipes PR: 0
File: :0-0
Timestamp: 2024-11-26T20:05:15.793Z
Learning: For future contributions to the `gofiber/recipes` repository, ensure that the tasks outlined in `.github/CONTRIBUTING.md` are incorporated, including creating a new directory without a "fiber" prefix, adding a `README.md` with Docusaurus metadata, and updating the overview by running `make generate`.
Learnt from: ReneWerner87
Repo: gofiber/fiber PR: 3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the `Test` method in `app.go`.
Learnt from: ReneWerner87
Repo: gofiber/contrib PR: 0
File: :0-0
Timestamp: 2024-10-16T10:04:06.328Z
Learning: The i18n functionality in the gofiber/contrib repository is being refactored from middleware to a global container to improve robustness and performance. The global container will be initialized once before setting up routes and will manage the i18n bundle and localizer map.
Learnt from: ReneWerner87
Repo: gofiber/contrib PR: 0
File: :0-0
Timestamp: 2024-07-03T11:59:00.303Z
Learning: The i18n functionality in the gofiber/contrib repository is being refactored from middleware to a global container to improve robustness and performance. The global container will be initialized once before setting up routes and will manage the i18n bundle and localizer map.
📚 Learning: 2024-11-15T07:56:21.623Z
Learnt from: ReneWerner87
Repo: gofiber/fiber PR: 3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the `Test` method in `app.go`.

Applied to files:

  • cmd/internal/migrations/v3/monitor_import_test.go
  • cmd/third_party_test.go
  • cmd/migrate_test.go
  • cmd/internal/migrations/v3/contrib_packages_test.go
📚 Learning: 2025-10-16T07:19:52.418Z
Learnt from: grivera64
Repo: gofiber/fiber PR: 3807
File: adapter_test.go:118-144
Timestamp: 2025-10-16T07:19:52.418Z
Learning: In the Fiber codebase, the linter does not allow `require` assertions from within HTTP handlers (including net/http-style handlers). Use `t.Fatalf`, `t.Errorf`, or similar `testing.T` methods for error handling inside handler functions instead.

Applied to files:

  • cmd/internal/migrations/v3/monitor_import_test.go
  • cmd/third_party_test.go
  • cmd/migrate_test.go
📚 Learning: 2024-12-13T08:14:22.851Z
Learnt from: efectn
Repo: gofiber/fiber PR: 3162
File: hooks_test.go:228-228
Timestamp: 2024-12-13T08:14:22.851Z
Learning: In Go test files, prefer using the `require` methods from the `testify` package for assertions instead of manual comparisons and calls to `t.Fatal` or `t.Fatalf`.

Applied to files:

  • cmd/internal/migrations/v3/monitor_import_test.go
  • cmd/third_party_test.go
  • cmd/migrate_test.go
  • cmd/internal/migrations/v3/contrib_packages_test.go
📚 Learning: 2024-07-26T21:00:12.902Z
Learnt from: sixcolors
Repo: gofiber/fiber PR: 2922
File: middleware/cors/utils.go:63-71
Timestamp: 2024-07-26T21:00:12.902Z
Learning: The project uses the testify/assert package for assertions in unit tests.

Applied to files:

  • cmd/internal/migrations/v3/monitor_import_test.go
  • cmd/third_party_test.go
  • cmd/migrate_test.go
  • cmd/internal/migrations/v3/contrib_packages_test.go
📚 Learning: 2024-10-08T19:06:06.583Z
Learnt from: sixcolors
Repo: gofiber/fiber PR: 3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests in this project use testify require.

Applied to files:

  • cmd/third_party_test.go
  • cmd/migrate_test.go
📚 Learning: 2025-02-12T11:24:31.153Z
Learnt from: ReneWerner87
Repo: gofiber/storage PR: 0
File: :0-0
Timestamp: 2025-02-12T11:24:31.153Z
Learning: The storage package in gofiber/storage repository can be used independently of the Fiber web framework.

Applied to files:

  • cmd/third_party_test.go
📚 Learning: 2024-10-08T19:06:06.583Z
Learnt from: luk3skyw4lker
Repo: gofiber/storage PR: 1342
File: clickhouse/clickhouse_test.go:138-160
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The `Test_Reset` function in `clickhouse/clickhouse_test.go` already includes a verification step to ensure the storage is empty after a reset operation by checking that a previously set key returns an empty byte slice.

Applied to files:

  • cmd/third_party_test.go
📚 Learning: 2024-11-26T20:05:15.793Z
Learnt from: ReneWerner87
Repo: gofiber/recipes PR: 0
File: :0-0
Timestamp: 2024-11-26T20:05:15.793Z
Learning: For future contributions to the `gofiber/recipes` repository, ensure that the tasks outlined in `.github/CONTRIBUTING.md` are incorporated, including creating a new directory without a "fiber" prefix, adding a `README.md` with Docusaurus metadata, and updating the overview by running `make generate`.

Applied to files:

  • cmd/third_party.go
🧬 Code graph analysis (3)
cmd/internal/migrations/v3/contrib_packages_test.go (1)
cmd/internal/migrations/v3/contrib_packages.go (1)
  • MigrateContribPackages (29-96)
cmd/internal/migrations/lists.go (1)
cmd/internal/migrations/v3/contrib_packages.go (1)
  • MigrateContribPackages (29-96)
cmd/internal/migrations/v3/contrib_packages.go (1)
cmd/internal/helpers.go (1)
  • ChangeFileContent (54-110)
🔇 Additional comments (15)
cmd/internal/migrations/v3/monitor_import.go (1)

16-16: LGTM! Monitor import migration updated to v3 path.

The change correctly updates the monitor middleware import target to use the new github.com/gofiber/contrib/v3/monitor path, aligning with the broader v3 contrib package migration.

cmd/third_party.go (2)

30-33: Excellent refactoring with centralized v3 path constants.

The introduction of contribModulePrefix and contribRepoPrefix constants improves maintainability and ensures consistent v3 path usage throughout the contrib refresh logic.


49-49: Consistent application of v3 prefix constants.

All references to contrib module paths now correctly use the centralized constants, ensuring uniform v3 path usage in prompts, pseudo-version derivation, import replacement, go.mod updates, and URL construction.

Also applies to: 73-73, 95-95, 113-113, 173-173

cmd/internal/migrations/v3/monitor_import_test.go (1)

30-30: Test assertion correctly updated for v3 migration.

The expectation now validates that the monitor import is migrated to the v3 path, consistent with the implementation changes.

cmd/migrate_test.go (1)

132-132: Integration test correctly validates v3 migration.

The assertion confirms that the end-to-end migration process correctly updates the monitor import to the v3 contrib path.

cmd/third_party_test.go (1)

18-18: Test fixtures and assertions correctly updated for v3.

All test data and expectations now use the v3 contrib path, validating that the refresh logic correctly handles the new module structure.

Also applies to: 24-24, 43-43, 47-47

cmd/internal/migrations/lists.go (1)

58-58: Migration correctly registered in the v3 migration sequence.

MigrateContribPackages is properly positioned after MigrateMonitorImport. These migrations are complementary: the monitor migration handles the fiber middleware → contrib v3 path, while this migration handles existing contrib (non-v3) → contrib v3 paths.

cmd/internal/migrations/v3/contrib_packages_test.go (3)

15-52: Excellent test coverage for basic migration scenario.

The test validates both import statement migration and go.mod updates, ensuring the migration correctly transforms github.com/gofiber/contrib/session to github.com/gofiber/contrib/v3/session in both contexts.


54-87: Important edge case: replace directive handling.

This test ensures that replace directives in go.mod are correctly updated to reference the v3 path, which is crucial for projects using local or forked contrib modules.


89-123: Idempotency validation ensures migration safety.

The test confirms that running the migration multiple times on already-migrated code produces no changes and no output, which is essential for safe re-runs and preventing double-migration issues.

cmd/internal/migrations/v3/contrib_packages.go (5)

17-20: Well-designed regex patterns for migration.

The patterns correctly capture:

  • contribImportRe: Import statements with double quotes or backticks, capturing the delimiter and the path after contrib/
  • contribModRe: Module references in go.mod files

Both patterns are appropriate for their respective contexts.


30-45: Import migration logic is sound.

The function correctly:

  • Uses ChangeFileContent to process all Go source files
  • Validates regex match length before proceeding
  • Checks for existing version prefixes to avoid double-migration
  • Constructs the new v3 path using the captured delimiter and rest of the path
  • Returns proper error wrapping

47-88: go.mod migration handles all necessary cases.

The logic correctly:

  • Walks the directory tree, skipping vendor directories
  • Processes only go.mod files
  • Checks if the file contains contrib references before processing
  • Preserves existing version prefixes to ensure idempotency
  • Uses secure file permissions (0o600) for writes
  • Tracks whether any modifications were made

98-110: Version prefix detection is correct for Go modules.

The hasVersionPrefix function correctly identifies version-prefixed paths like v2/, v3/, v10/, etc. by:

  • Checking for v followed by digits
  • Accepting either end-of-string or / after the digits

This correctly handles Go's major version suffix convention and prevents false positives like validator.


90-95: Appropriate migration feedback.

The function only prints the migration message when changes were actually made, providing clear feedback to users without noise on no-op runs.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ReneWerner87, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces essential updates to the project's migration and tooling infrastructure to support the transition of github.com/gofiber/contrib packages to their v3 module path. The changes ensure that both Go import statements within source files and module requirements in go.mod files are correctly updated, facilitating a smooth upgrade path for users of the gofiber/cli tool. This effort maintains compatibility and streamlines the process of adopting the new v3 versions of contrib packages.

Highlights

  • New Contrib V3 Migration: A new migration has been added to automatically rewrite github.com/gofiber/contrib imports and go.mod entries to use the v3 module path, complete with comprehensive tests.
  • Updated Contrib Tooling: The existing contrib refresh logic and associated tests have been updated to correctly utilize the new github.com/gofiber/contrib/v3 prefix, ensuring compatibility with the latest module structure.
  • Monitor Import Alignment: The monitor import migration and its integration tests have been aligned to correctly reference the v3 packages for github.com/gofiber/contrib/monitor.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions github-actions bot added ✏️ Feature New feature or request 🧹 Updates labels Nov 3, 2025
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +30 to +33
const (
contribModulePrefix = "github.com/gofiber/contrib/v3/"
contribRepoPrefix = "gofiber/contrib/v3"
)

Choose a reason for hiding this comment

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

P1 Badge Use correct repo path when generating contrib pseudo versions

The new contribRepoPrefix constant now includes /v3, but refreshContrib passes this value to pseudoVersionFromHash when a hash is provided. pseudoVersionFromHash constructs the GitHub API URL from that prefix, so the request targets https://api.github.com/repos/gofiber/contrib/v3/..., which does not exist—the repository is still gofiber/contrib. As a result, running the contrib refresh command with --hash will fail to fetch commit metadata and cannot compute pseudo versions. Keep the repository prefix as gofiber/contrib while using the /v3 suffix only for import paths.

Useful? React with 👍 / 👎.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a migration for gofiber/contrib packages to the v3 module path and updates the related tooling. The changes are well-structured, and the new migration logic is covered by a good set of tests, including checks for idempotency. The updates to the contrib refresh logic and monitor middleware are consistent with the migration. I've found one issue regarding file permission preservation which I've commented on. Overall, this is a solid contribution.

Comment on lines +62 to +82
b, err := os.ReadFile(path) // #nosec G304 -- reading module file
if err != nil {
return fmt.Errorf("read %s: %w", path, err)
}
content := string(b)
if !contribModRe.MatchString(content) {
return nil
}
updated := contribModRe.ReplaceAllStringFunc(content, func(match string) string {
rest := strings.TrimPrefix(match, contribPrefix)
if rest == match || hasVersionPrefix(rest) {
return match
}
return contribV3Prefix + rest
})
if updated == content {
return nil
}
if err := os.WriteFile(path, []byte(updated), 0o600); err != nil {
return fmt.Errorf("write %s: %w", path, err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

When updating the go.mod file, the original file permissions are not preserved because os.WriteFile is called with a hardcoded mode 0o600. This could cause unexpected permission changes in the user's project. It's better to read the original file's permissions and use them when writing the updated file.

                info, err := d.Info()
                if err != nil {
                        return fmt.Errorf("stat %s: %w", path, err)
                }
		b, err := os.ReadFile(path) // #nosec G304 -- reading module file
		if err != nil {
			return fmt.Errorf("read %s: %w", path, err)
		}
		content := string(b)
		if !contribModRe.MatchString(content) {
			return nil
		}
		updated := contribModRe.ReplaceAllStringFunc(content, func(match string) string {
			rest := strings.TrimPrefix(match, contribPrefix)
			if rest == match || hasVersionPrefix(rest) {
				return match
			}
			return contribV3Prefix + rest
		})
		if updated == content {
			return nil
		}
		if err := os.WriteFile(path, []byte(updated), info.Mode()); err != nil {
			return fmt.Errorf("write %s: %w", path, err)
		}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants