feat: Allow custom user agent for Gitea/Forgejo#2494
Conversation
Summary of ChangesHello @chmouel, 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 the capability to define a custom User-Agent for Gitea and Forgejo API requests. This enhancement is crucial for environments where instances are protected by AI scraping proxies that might otherwise block automated requests. The change allows for flexible configuration at the repository level, ensuring compatibility and reliable communication with various Gitea/Forgejo setups. Highlights
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request adds a useful feature to allow custom User-Agent headers for Gitea/Forgejo, which is great for environments with proxy protections. The changes are well-structured, including updates to the CRD, documentation, and tests. The implementation in gitea.go is correct. The suggestion to refactor the client initialization logic to reduce code duplication and improve maintainability is valid and aligns with general best practices. Otherwise, the changes look good.
There was a problem hiding this comment.
Pull request overview
This PR adds the ability to specify a custom User-Agent header for API requests to Gitea/Forgejo instances. This feature addresses the use case where Gitea/Forgejo instances are behind AI scraping protection proxies that block requests without recognized User-Agent headers.
Changes:
- Added
GiteaSettingsstruct withUserAgentfield to repository CRD settings - Updated Gitea provider to use custom user agent when initializing the client, defaulting to "pipelines-as-code/"
- Added merge logic for Gitea settings to support global and local repository configurations
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pkg/provider/gitea/gitea.go | Implements user agent configuration logic in SetClient method, applying custom value from repo settings or using default |
| pkg/apis/pipelinesascode/v1alpha1/types.go | Adds GiteaSettings struct and merge logic to support global/local configuration inheritance |
| pkg/apis/pipelinesascode/v1alpha1/types_test.go | Adds unit tests for Gitea settings merge behavior with global and local configurations |
| docs/content/docs/guide/repositorycrd.md | Documents the new user_agent configuration option with example usage |
| config/300-repositories.yaml | Updates CRD schema to include the new gitea.user_agent field |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
61d6ae7 to
edc5d5e
Compare
|
|
||
| // Gitea contains Gitea/Forgejo-specific settings. | ||
| // +optional | ||
| Gitea *GiteaSettings `json:"gitea,omitempty"` |
There was a problem hiding this comment.
Since we have made Forgejo a "first-class citizen", should we not have forgejo as the key? Since it is a new field, would not break any pre-existing deployments. WDYT?
There was a problem hiding this comment.
I don't think we need to mix yet... one day we will just refactor everything Forgejo including the package
config/300-repositories.yaml
Outdated
| - roles | ||
| - secret_ref | ||
| type: object | ||
| gitea: |
There was a problem hiding this comment.
you right @theakshaypant i misunderstood your comment (thinking you were talking about internal struct), i'll rename this
Added the ability to specify a custom User-Agent header for API requests to Gitea/Forgejo instances. This is useful for instances protected by AI scraping protection proxies that may block requests lacking a recognized User-Agent. The User-Agent can be configured per repository in the `Repository` CRD under `spec.settings.gitea.user_agent`. If not specified, it defaults to "pipelines-as-code/<version>". This functionality was implemented by adding a new field to the `GiteaSettings` struct and updating the `gitea.go` provider to utilize this new setting when initializing the Gitea client. Documentation and tests were also updated to reflect this change. Jira: https://issues.redhat.com/browse/SRVKP-10579 AI-assisted-by: Google Gemini Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
edc5d5e to
37cc7c1
Compare
📝 Description of the Change
This PR adds support for configuring a custom
User-Agentheader for API requests to Gitea/Forgejo instances. This enhancement addresses scenarios where Gitea/Forgejo instances are protected by AI scraping prevention proxies (such as Anubis) that block requests without a recognized User-Agent header.Key changes:
UserAgentfield toGiteaSettingsstruct in the Repository CRDspec.settings.gitea.user_agentpipelines-as-code/<version>when not specifiedUse case:
Fedora's Forgejo instance uses an AI scraping protection proxy that requires a specific User-Agent. This feature allows administrators to configure PAC to work with such protected instances without code changes.
👨🏻 Linked Jira
Jira: https://issues.redhat.com/browse/SRVKP-10579
🔗 Linked GitHub Issue
Fixes #
🚀 Type of Change
fix:)feat:)feat!:,fix!:)docs:)chore:)refactor:)enhance:)deps:)🧪 Testing Strategy
Unit tests added:
Manual testing:
🤖 AI Assistance
Which LLM was used?
Extent of AI Assistance:
✅ Submitter Checklist
fix:,feat:) matches the "Type of Change" I selected above.make testandmake lintlocally to check for and fix any issues. For an efficient workflow, I have considered installing pre-commit and runningpre-commit installto automate these checks.