fix(forgejo): share complete Gitea PR scans across branch lookups#24853

open2
main
GitHub fork: fix/23551-gitea-pr-lookup
opened4d agobyZZheruel
View on GitHubTwo-way sync enabledPR last imported 3d ago

Gitea branch-status lookups now share complete repository scans across branches and worktrees. Gitea 28.2.0 ignores head, so each branch previously paged through every PR.

A snapshot is reusable for one minute, scoped to the resolved server, account, CLI and repository. Explicit refreshes and creation checks bypass it. Pagination completes before results are cached; source identity, arbitrary bases and open/closed/merged selection stay intact. Forgejo servers honoring head keep their existing path.

The direct base/head endpoint cannot replace discovery: local Gitea returned closed PR #1 even while open PR #63 existed for the same base/head.

vp run check:changed passes: 143 tests plus format, lint, knip, affected-package typechecks and generated GraphQL checks. The regression failed on unchanged main; another regression verifies that an explicit refresh finds a newly opened PR after warming the cache.

Measured local QA

Runtime evidence and synthetic fixture.

  • Real Gitea 28.2.0, isolated Docker container with 62 API-created PRs: 3 requests for a fresh missing-head lookup; 4 for a cold cached lookup; 0 for 97 warm missing-head lookups plus a reused-branch lookup. Returned open PR #62 on release/arbitrary and closed PR #1 on main.
  • Synthetic HTTP fixture, 3,089 PRs: two fresh lookups made 126 requests; 97 background lookups shared 64 requests total. A warm lookup found merged PR #2501 with zero requests.

Both exercised the production provider and CLI HTTP adapter. Installed tea/fj commands and WSL were not tested. No production forge, credentials or T3 state was used. The temporary Gitea container was removed after testing.

Important

Cold/expired lookups still require a complete scan. Sharing removes repeated scans across branches. A snapshot can add up to one minute of staleness to the existing branch cache; explicit refreshes remain authoritative.

Closes #23551.

Implemented with GPT-6.1-Sol through the Codex harness in T3 Code.

Checks

6 successful · 1 skipped
All checks passed
0f65b27

Added 2 commits

  • fix(forgejo): share complete Gitea PR scans across branch lookups374a616
  • fix(git): preserve fresh PR lookups through provider caches0f65b27
Synced from GitHub

Review in Change Stack →

No actionable comments were generated in the recent review.

External image Recent review info
External image Run configuration
External image Commits

Reviewing files that changed from the base of the PR and between e57c093cdd9032355c6251dd7192280b915b7a23 and 0f65b2722e9da8c258221309c945d6af2ac4fb81.

External image Files selected for processing: 5
  • apps/server/src/git/GitManager.test.ts
  • apps/server/src/git/GitManager.ts
  • packages/source-control-core/src/server/SourceControlProvider.ts
  • packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.test.ts
  • packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

Walkthrough

Forgejo now caches complete repository pull-request scans for one minute and filters cached results for branch lookups. GitManager passes cache permission to providers and disables provider-cached results on refresh paths.

Changes: Forgejo pull-request lookups

Layer / File(s)Summary
Repository scan cache and filtering
packages/source-control-core/src/server/SourceControlProvider.ts, packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.ts, packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.test.ts
The provider accepts an allowCached option and caches successful complete scans for one minute, with capacity for 16 entries. It filters results by branch, optional source repository and owner, and state. Tests cover cache expiry and bypass, cache identity, pagination, failures, and concurrent lookups.
GitManager cache policy
apps/server/src/git/GitManager.ts, apps/server/src/git/GitManager.test.ts
GitManager passes cache permission through pull-request lookups and disables provider-cached results when refreshing or retrying after a repository identity change. A Gitea test covers paginated branch lookup and refreshed results.

Priority: External image Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

mermaid
1sequenceDiagram
2 participant GitManager
3 participant ForgejoSourceControlProvider
4 participant ForgejoAPI
5 GitManager->>ForgejoSourceControlProvider: Request pull requests with allowCached
6 ForgejoSourceControlProvider->>ForgejoSourceControlProvider: Check cached scan and filter results
7 ForgejoSourceControlProvider->>ForgejoAPI: Fetch pull-request pages when a scan is needed
8 ForgejoAPI-->>ForgejoSourceControlProvider: Return pull-request pages
9 ForgejoSourceControlProvider-->>GitManager: Return matching pull requests

Suggested reviewers: juliusmarminge, saphid

Merge Risk: External image Minimal · up to 0f65b

No merge-blocking issue is established; branch lookups can share a scan, while explicit refreshes can request fresh results.

Pre-merge checks: Passed 4
Check nameStatusExplanation
Description checkPassedThe description explains the problem, the caching approach, scope, issue reference, verification results, limitations, and agent usage. It does not use the template headings, but it provides the requi…
Title checkPassedThe title is concise, specific, and accurately describes the main change: sharing complete Gitea pull-request scans across branch lookups in the Forgejo provider.
Linked Issues checkPassedIssue #23551 requires lower request cost for Gitea branch pull-request lookups. The provider now shares a complete repository scan by resolved server, account, CLI, and repository. The scan completes …
Out of Scope Changes checkPassedThe changes stay within issue #23551. They add provider scan caching, cache-control propagation, and focused regression tests. The tests support the lookup-cost objective and verify preserved lookup b…
Full details: Description check

Explanation

The description explains the problem, the caching approach, scope, issue reference, verification results, limitations, and agent usage. It does not use the template headings, but it provides the required information in a clear, focused format.

Full details: Linked Issues check

Explanation

Issue #23551 requires lower request cost for Gitea branch pull-request lookups. The provider now shares a complete repository scan by resolved server, account, CLI, and repository. The scan completes before caching, joins in-flight scans, and does not retain failed scans. Filtered Forgejo requests keep their existing path. GitManager disables provider caching for refresh and missing-PR refresh paths. Tests cover pagination, branch and source filtering, arbitrary bases, PR states, cache isolation, expiry, refresh, failures, and concurrent scans.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue #23551. They add provider scan caching, cache-control propagation, and focused regression tests. The tests support the lookup-cost objective and verify preserved lookup behavior. No unrelated production feature or unrelated test change is demonstrated.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Note

Written by gpt-6.1-sol on behalf of Maria

thanks @Zheruel. your implementation correctly shares only complete scans, preserves source identity and arbitrary bases, and keeps explicit refreshes authoritative.

i rebuilt this as #25568 because maintainer edits are disabled on your fork. it covers the same branch/worktree scan sharing on current main and retains your release credit.

i compared your full original diff against the replacement. no production logic or regression cases were dropped or moved. the pagination fixture now uses 75 prs instead of 3,089, still finding a match beyond page one.

verification: both sharing regressions failed on current main; blacksmith vp run check:changed passed format, lint, knip, generated graphql, 17 affected package typechecks, and 143 tests. a real gitea 1.25.2 instance through installed tea 0.16.0 confirmed warm branch sharing and a fresh explicit refresh after closure. installed fj, wsl, and production credentials remain unverified. no ui changes apply.