Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@ReneWerner87
Copy link
Member

Summary

  • preserve struct formatting when removing config fields
  • only strip ContextKey from configs belonging to Fiber middlewares
  • add regression tests for ContextKey migration
  • detect any fiber middleware import for ContextKey removal

Testing

  • make lint
  • make test

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

@coderabbitai
Copy link

coderabbitai bot commented Aug 24, 2025

Warning

Rate limit exceeded

@ReneWerner87 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 7 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 14a7e87 and 70c585a.

📒 Files selected for processing (3)
  • cmd/internal/migrations/v3/common.go (1 hunks)
  • cmd/internal/migrations/v3/middleware_locals.go (2 hunks)
  • cmd/internal/migrations/v3/middleware_locals_test.go (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/2025-08-24-14-48-33

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
🪧 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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 or @coderabbitai title 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@github-actions github-actions bot added the ☢️ Bug Something isn't working label Aug 24, 2025
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.

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 refines the v3 migration process by focusing on the intelligent removal of ContextKey fields. The changes ensure that ContextKey is only stripped from relevant Fiber middleware configurations, while meticulously preserving the original struct formatting. This is achieved through enhancements to the removeConfigField utility and the introduction of import detection to precisely target Fiber middleware configurations, along with new tests to validate these behaviors.

Highlights

  • Targeted ContextKey Removal: The migration process for ContextKey has been refined to ensure it is only removed from configurations specifically associated with Fiber middleware, preventing unintended modifications to other Config structs.
  • Enhanced Formatting Preservation: Improvements have been made to the removeConfigField utility to preserve the original formatting of Go struct literals, ensuring that the removal of fields does not introduce unwanted whitespace or newline changes.
  • Improved Fiber Middleware Detection: The migration logic now includes robust detection of Fiber middleware imports and their aliases, allowing for precise application of ContextKey removal only within those specific contexts.
  • Comprehensive Regression Tests: New regression tests have been added to validate the correct behavior of ContextKey removal, including specific tests for formatting preservation and ensuring non-Fiber configurations remain untouched.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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.

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 effectively addresses an issue where a migration script was too broad in its removal of configuration fields. The changes correctly limit the scope to only Fiber middleware configurations by intelligently detecting imports and their aliases. The addition of regression tests for formatting and for non-fiber configs is a great improvement. I've identified a potential issue with how package aliases are handled in regular expressions, particularly for dot imports and aliases containing special characters, and have provided suggestions to make the migration script more robust.

Comment on lines +48 to 59
for alias, pkg := range imports {
for _, e := range extractors {
if e.pkg != pkg {
continue
}
re := regexp.MustCompile(alias + `\.Config{[^}]*` + e.field + `:\s*"([^"]+)"`)
matches := re.FindAllStringSubmatch(content, -1)
for _, m := range matches {
ctxMap[m[1]] = e.replFmt
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The current regular expression construction does not handle package aliases with special characters correctly, and fails for dot imports (import . "..."). The alias should be escaped using regexp.QuoteMeta to prevent misinterpretation of special characters, and dot imports (where the alias is '.') should result in no package prefix for the regex.

This can lead to incorrect or failed migrations for projects using these import styles.

for alias, pkg := range imports {
			for _, e := range extractors {
				if e.pkg != pkg {
					continue
				}
				var prefix string
				if alias == "." {
					prefix = ""
				} else {
					prefix = regexp.QuoteMeta(alias) + "\\."
				}
				re := regexp.MustCompile(prefix + "Config{[^}]*" + e.field + ":\\s*\"([^\"]+)\"")
				matches := re.FindAllStringSubmatch(content, -1)
				for _, m := range matches {
					ctxMap[m[1]] = e.replFmt
				}
			}
		}

Comment on lines +78 to +86
for alias := range imports {
reCfg := regexp.MustCompile(alias + `\.Config{[^}]*}`)
content = reCfg.ReplaceAllStringFunc(content, func(cfg string) string {
cfg = removeConfigField(cfg, "ContextKey")
cfg = removeConfigField(cfg, "ContextUsername")
cfg = removeConfigField(cfg, "ContextPassword")
return cfg
})
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Similar to the logic above, this regular expression construction does not handle package aliases with special characters or dot imports correctly. The alias should be escaped and dot imports should be handled to ensure the config struct is correctly identified and modified.

Without this change, the field removal might not apply to configs from packages imported with a dot (.) or an alias containing special characters.

Suggested change
for alias := range imports {
reCfg := regexp.MustCompile(alias + `\.Config{[^}]*}`)
content = reCfg.ReplaceAllStringFunc(content, func(cfg string) string {
cfg = removeConfigField(cfg, "ContextKey")
cfg = removeConfigField(cfg, "ContextUsername")
cfg = removeConfigField(cfg, "ContextPassword")
return cfg
})
}
for alias := range imports {
var prefix string
if alias == "." {
prefix = ""
} else {
prefix = regexp.QuoteMeta(alias) + "\\."
}
reCfg := regexp.MustCompile(prefix + "Config{[^}]*}")
content = reCfg.ReplaceAllStringFunc(content, func(cfg string) string {
cfg = removeConfigField(cfg, "ContextKey")
cfg = removeConfigField(cfg, "ContextUsername")
cfg = removeConfigField(cfg, "ContextPassword")
return cfg
})
}

@ReneWerner87 ReneWerner87 merged commit 8d21c0e into master Aug 24, 2025
13 checks passed
@ReneWerner87 ReneWerner87 deleted the codex/2025-08-24-14-48-33 branch August 24, 2025 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

☢️ Bug Something isn't working codex

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants