Skip to content

feat: cache changed files in Gitea provider#2552

Merged
chmouel merged 1 commit intotektoncd:mainfrom
chmouel:srvkp-10944-gitea-getfiles-cache
Mar 11, 2026
Merged

feat: cache changed files in Gitea provider#2552
chmouel merged 1 commit intotektoncd:mainfrom
chmouel:srvkp-10944-gitea-getfiles-cache

Conversation

@chmouel
Copy link
Copy Markdown
Member

@chmouel chmouel commented Mar 9, 2026

📝 Description of the Change

Implemented a caching mechanism for changed files in the Gitea provider to prevent redundant API requests during the reconciliation process. The implementation mirrors the existing pattern from PR #2317 for other providers.

Changes Made:

  • Added cachedChangedFiles field to the Provider struct to cache the result of the first GetFiles() call
  • Implemented GetFiles() method that returns cached results on subsequent calls
  • Implemented fetchChangedFiles() helper that handles both pull request and push event scenarios with proper file status categorization
  • Added comprehensive test coverage including verification that subsequent calls use cached data without making additional API requests

Benefits:

  • Reduces API calls to the Gitea instance during pipeline reconciliation
  • Improves performance by avoiding redundant file change lookups
  • Maintains consistency with caching patterns used in other provider implementations

👨🏻‍ Linked Jira

Jira: https://issues.redhat.com/browse/SRVKP-10944

🔗 Linked GitHub Issue

Fixes #

🧪 Testing Strategy

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

Test Coverage:

  • TestProvider_GetFiles: Tests both pull request and push event scenarios
  • Cache verification: Confirms that the second call to GetFiles() returns cached results without making additional API requests
  • File categorization: Validates correct categorization of files as Added, Deleted, Modified, or Renamed

🤖 AI Assistance

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

If you have used AI assistance, please provide the following details:

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)

Important

If the majority of the code in this PR was generated by an AI, please add a Co-authored-by trailer to your commit message.
For example:

Co-authored-by: Gemini gemini@google.com
Co-authored-by: ChatGPT noreply@chatgpt.com
Co-authored-by: Claude noreply@anthropic.com
Co-authored-by: Cursor noreply@cursor.com
Co-authored-by: Copilot Copilot@users.noreply.github.com

**💡You can use the script ./hack/add-llm-coauthor.sh to automatically add
these co-author trailers to your commits.

✅ 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

@pipelines-as-code
Copy link
Copy Markdown

pipelines-as-code bot commented Mar 9, 2026

🔍 PR Lint Feedback

Note: This automated check helps ensure your PR follows our contribution guidelines.

⚠️ Items that need attention:

🤖 AI attribution

The following commits lack an explicit AI attribution footer:

  • 9e0ceb1 feat: cache changed files in Gitea provider

If no AI assistance was used for a commit, you can ignore this warning.
Otherwise add an Assisted-by: or Co-authored-by: footer referencing the AI used.


ℹ️ Next Steps

  • Review and address the items above
  • Push new commits to update this PR
  • This comment will be automatically updated when issues are resolved
🔧 Admin Tools (click to expand)

Automated Issue/Ticket Creation:

  • /issue-create - Generate a GitHub issue from this PR content using AI
  • /jira-create - Create a SRVKP Jira ticket from this PR content using AI

⚠️ Important: Always review and edit generated content before finalizing tickets/issues.
The AI-generated content should be used as a starting point and may need adjustments.

These commands are available to maintainers and will post the generated content as PR comments for review.

🤖 This feedback was generated automatically by the PR CI system

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, 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 enhances the Gitea provider by implementing a caching layer for changed files. This optimization aims to reduce the number of API requests made to the Gitea instance, thereby improving performance and reducing load, especially during reconciliation processes where file change information might be requested multiple times.

Highlights

  • Caching Mechanism for Changed Files: Introduced a caching mechanism within the Gitea provider to store the list of changed files, preventing redundant API calls to the Gitea instance during reconciliation.
  • Refactored GetFiles Method: The existing GetFiles method in the Gitea provider has been refactored. It now checks an internal cache first; if the cache is empty, it calls a new fetchChangedFiles method to retrieve the data and then populates the cache.
  • Enhanced Test Coverage for Caching: Added comprehensive unit tests to TestProvider_GetFiles to verify the caching functionality. These tests ensure that after the initial API call, subsequent requests for changed files retrieve data from the cache without making additional API calls.
Changelog
  • pkg/provider/gitea/gitea.go
    • Added a cachedChangedFiles field to the Provider struct to hold the cached list of changed files.
    • Renamed the original GetFiles function to fetchChangedFiles to encapsulate the actual API fetching logic.
    • Implemented a new GetFiles function that acts as a caching wrapper, checking cachedChangedFiles before calling fetchChangedFiles.
  • pkg/provider/gitea/gitea_test.go
    • Imported necessary metricstest and metricsutils packages for testing API request counts.
    • Modified the TestProvider_GetFiles test structure to include wantAPIRequestCount for verifying caching behavior.
    • Added metricsutils.ResetMetrics() to ensure a clean metric state for each test run.
    • Updated test cases to set expected API request counts and verify that subsequent calls to GetFiles do not increment the API request metric, confirming cache utilization.
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.

@chmouel
Copy link
Copy Markdown
Member Author

chmouel commented Mar 9, 2026

cc @aThorp96

@chmouel chmouel requested a review from aThorp96 March 9, 2026 12:47
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

The pull request introduces a caching mechanism for changed files in the Gitea provider, which is a valuable optimization to reduce redundant API calls. While the implementation correctly separates caching logic and includes effective tests, a potential security vulnerability exists due to missing cache invalidation: the cachedChangedFiles field is not reset when the provider is re-initialized for a new event, potentially leading to stale data across different events. Furthermore, a high-severity issue was identified where the context.Context is not propagated to an underlying API call within the fetchChangedFiles function, which could lead to issues with context cancellation or timeouts not being respected. The provided code suggestion for this issue has been updated to adhere to the repository's rule regarding the use of configured page size variables for paginated API calls. These issues should be addressed to ensure proper context handling and adherence to pagination best practices.

Copy link
Copy Markdown
Member

@aThorp96 aThorp96 left a comment

Choose a reason for hiding this comment

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

/lgtm

One non-blocking request for the unit test

Implemented a caching mechanism for changed files in the Gitea provider
to prevent redundant API requests during the reconciliation process.

This mirror the implementation on PR tektoncd#2317

Jira: https://issues.redhat.com/browse/SRVKP-10944
Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
@chmouel chmouel force-pushed the srvkp-10944-gitea-getfiles-cache branch from ff5b5da to 9e0ceb1 Compare March 11, 2026 17:29
@chmouel chmouel merged commit eff5928 into tektoncd:main Mar 11, 2026
13 checks passed
@chmouel chmouel deleted the srvkp-10944-gitea-getfiles-cache branch March 11, 2026 18:17
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