Skip to content

feat: Allow custom user agent for Gitea/Forgejo#2494

Merged
chmouel merged 1 commit intotektoncd:mainfrom
chmouel:srvkp-10579-feat-fedora-forge-user-agent
Feb 24, 2026
Merged

feat: Allow custom user agent for Gitea/Forgejo#2494
chmouel merged 1 commit intotektoncd:mainfrom
chmouel:srvkp-10579-feat-fedora-forge-user-agent

Conversation

@chmouel
Copy link
Copy Markdown
Member

@chmouel chmouel commented Feb 19, 2026

📝 Description of the Change

This PR adds support for configuring a custom User-Agent header 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:

  • Added UserAgent field to GiteaSettings struct in the Repository CRD
  • Implemented per-repository User-Agent configuration via spec.settings.gitea.user_agent
  • Defaults to pipelines-as-code/<version> when not specified
  • Updated settings merge logic to properly inherit Gitea settings from global to local scope
  • Modified Gitea provider client initialization to use the configured User-Agent
  • Added comprehensive unit tests for settings inheritance behavior
  • Updated CRD schema and documentation

Use 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

  • 🐛 Bug fix (fix:)
  • ✨ New feature (feat:)
  • 💥 Breaking change (feat!:, fix!:)
  • 📚 Documentation update (docs:)
  • ⚙️ Chore (chore:)
  • 💅 Refactor (refactor:)
  • 🔧 Enhancement (enhance:)
  • 📦 Dependency update (deps:)

🧪 Testing Strategy

  • Unit tests
  • Integration tests
  • End-to-end tests
  • Manual testing
  • Not Applicable

Unit tests added:

  • Settings merge behavior when both global and local Gitea settings are present
  • Settings inheritance when only global settings exist
  • Verification that User-Agent is properly passed to Gitea client

Manual testing:

  • Tested against Fedora's Forgejo instance with Anubis proxy
  • Verified default User-Agent works with standard Gitea instances
  • Confirmed custom User-Agent overrides work correctly

🤖 AI Assistance

  • I have not used any AI assistance for this PR.
  • I have used AI assistance for this PR.

Which LLM was used?

  • GitHub Copilot
  • ChatGPT (OpenAI)
  • Claude (Anthropic)
  • Cursor
  • Gemini (Google)
  • Other: ____________

Extent of AI Assistance:

  • Documentation and research only
  • Unit tests or E2E tests only
  • Code generation (parts of the code)
  • Full code generation (most of the PR)
  • PR description and comments
  • Commit message(s)

✅ Submitter Checklist

  • 📝 My commit messages are clear, informative, and follow the project's How to write a git commit message guide. The Gitlint linter ensures in CI it's properly validated
  • ✨ I have ensured my commit message prefix (e.g., fix:, feat:) matches the "Type of Change" I selected above.
  • ♽ I have run make test and make lint locally to check for and fix any issues. For an efficient workflow, I have considered installing pre-commit and running pre-commit install to automate these checks.
  • 📖 I have added or updated documentation for any user-facing changes.
  • 🧪 I have added sufficient unit tests for my code changes.
  • 🎁 I have added end-to-end tests where feasible. See README for more details.
  • 🔎 I have addressed any CI test flakiness or provided a clear reason to bypass it.
  • If adding a provider feature, I have filled in the following and updated the provider documentation:
    • GitHub App
    • GitHub Webhook
    • Gitea/Forgejo
    • GitLab
    • Bitbucket Cloud
    • Bitbucket Data Center

Copilot AI review requested due to automatic review settings February 19, 2026 15:34
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @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

  • Custom User-Agent for Gitea/Forgejo: Users can now specify a custom User-Agent header for API requests to Gitea/Forgejo instances, which is configurable per repository.
  • CRD Configuration: The User-Agent is configurable via spec.settings.gitea.user_agent in the Repository Custom Resource Definition (CRD).
  • Default Behavior: If a custom User-Agent is not specified, it defaults to "pipelines-as-code/".
  • AI Scraping Protection: This feature helps bypass AI scraping protection proxies (e.g., Anubis) that may block requests lacking a recognized User-Agent.
  • Codebase Updates: The GiteaSettings struct, gitea.go provider, documentation, and tests have been updated to support this new functionality.
Changelog
  • config/300-repositories.yaml
    • Added the gitea.user_agent field to the Repository CRD schema, including its description and type.
  • docs/content/docs/guide/repositorycrd.md
    • Documented the new gitea.user_agent setting, explaining its purpose and providing a configuration example.
  • pkg/apis/pipelinesascode/v1alpha1/types.go
    • Defined the GiteaSettings struct with a UserAgent field.
    • Integrated GiteaSettings into the main Settings struct.
    • Updated the merge logic for Settings to include GiteaSettings.
  • pkg/apis/pipelinesascode/v1alpha1/types_test.go
    • Added new test cases to verify the correct merging behavior of Gitea settings, including User-Agent precedence.
  • pkg/provider/gitea/gitea.go
    • Modified the Gitea client initialization to incorporate the custom User-Agent from repository settings, falling back to a default if not specified.
    • Imported versiondata package to get the current version for the default User-Agent.
Activity
  • The pull request was created by chmouel to introduce a new feature.
  • The author indicated using Gemini for AI assistance in code generation (parts of the code) and PR description/comments.
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.

Copy link
Copy Markdown

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

@pipelines-as-code pipelines-as-code bot added documentation Improvements or additions to documentation feature New feature or request gitea labels Feb 19, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 GiteaSettings struct with UserAgent field 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.

@chmouel chmouel force-pushed the srvkp-10579-feat-fedora-forge-user-agent branch from 61d6ae7 to edc5d5e Compare February 19, 2026 16:06

// Gitea contains Gitea/Forgejo-specific settings.
// +optional
Gitea *GiteaSettings `json:"gitea,omitempty"`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't think we need to mix yet... one day we will just refactor everything Forgejo including the package

- roles
- secret_ref
type: object
gitea:
Copy link
Copy Markdown
Member Author

@chmouel chmouel Feb 24, 2026

Choose a reason for hiding this comment

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

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>
@chmouel chmouel force-pushed the srvkp-10579-feat-fedora-forge-user-agent branch from edc5d5e to 37cc7c1 Compare February 24, 2026 10:17
@chmouel chmouel merged commit 106b201 into tektoncd:main Feb 24, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation feature New feature or request gitea

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants