Support GitHub Enterprise diffs and mutations with host-scoped caches
Parse GitHub host identity from work-item URLs and carry it through PR/issue mutations, labels, and assignments. Bound rate-limit and scope-probe caches (1024 and 512 entries) to prevent unbounded growth when interacting with multiple GHES instances. Normalize repository identity keys to include host so github.com and GHES slugs don't collide in cache and equality checks.
This commit is contained in:
@@ -2577,10 +2577,6 @@ function parseTrackedUpstreamBranch(upstreamRef: string): TrackedUpstreamBranch
|
||||
return parsed
|
||||
}
|
||||
|
||||
function prOwnerRepoKey(ownerRepo: OwnerRepo): string {
|
||||
return `${ownerRepo.owner.toLowerCase()}/${ownerRepo.repo.toLowerCase()}`
|
||||
}
|
||||
|
||||
function shouldRetryTrackedUpstreamBranch(
|
||||
upstreamBranch: TrackedUpstreamBranch,
|
||||
branchName: string,
|
||||
@@ -2593,7 +2589,7 @@ function shouldRetryTrackedUpstreamBranch(
|
||||
if (!headRepo) {
|
||||
return true
|
||||
}
|
||||
return prOwnerRepoKey(upstreamHeadRepo) !== prOwnerRepoKey(headRepo)
|
||||
return githubRepoIdentityKey(upstreamHeadRepo) !== githubRepoIdentityKey(headRepo)
|
||||
}
|
||||
|
||||
async function getTrackedUpstreamBranch(
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
type GitHubRemoteIdentity
|
||||
} from './github-remote-identity-parsing'
|
||||
import { isStableMissingGitRemoteError } from './stable-missing-git-remote-error'
|
||||
import { githubRepoIdentityKey } from '../../shared/github-repository-identity-key'
|
||||
|
||||
export type OwnerRepo = GitHubOwnerRepo
|
||||
|
||||
@@ -234,7 +235,7 @@ export type PRRepositoryCandidates = {
|
||||
}
|
||||
|
||||
function ownerRepoKey(ownerRepo: OwnerRepo): string {
|
||||
return `${ownerRepo.owner.toLowerCase()}/${ownerRepo.repo.toLowerCase()}`
|
||||
return githubRepoIdentityKey(ownerRepo)
|
||||
}
|
||||
|
||||
export async function resolvePRRepositoryCandidates(
|
||||
|
||||
@@ -242,6 +242,24 @@ const DEFAULT_BREAKER_SCOPE = ghRateLimitScopeKey('native', 'github.com')
|
||||
// versa).
|
||||
const scopeRefinementInFlight = new Map<string, Promise<void>>()
|
||||
const scopeProbeFailureAtMs = new Map<string, number>()
|
||||
const SCOPE_PROBE_FAILURE_MAX_ENTRIES = 512
|
||||
|
||||
function rememberScopeProbeFailure(scope: string, failedAt: number): void {
|
||||
for (const [key, at] of scopeProbeFailureAtMs) {
|
||||
if (failedAt - at >= RATE_LIMIT_CACHE_TTL_MS) {
|
||||
scopeProbeFailureAtMs.delete(key)
|
||||
}
|
||||
}
|
||||
scopeProbeFailureAtMs.delete(scope)
|
||||
scopeProbeFailureAtMs.set(scope, failedAt)
|
||||
while (scopeProbeFailureAtMs.size > SCOPE_PROBE_FAILURE_MAX_ENTRIES) {
|
||||
const oldestKey = scopeProbeFailureAtMs.keys().next().value
|
||||
if (oldestKey === undefined) {
|
||||
break
|
||||
}
|
||||
scopeProbeFailureAtMs.delete(oldestKey)
|
||||
}
|
||||
}
|
||||
|
||||
function refineBreakerForScope(scope: string): void {
|
||||
// Default scope keeps the existing shared-snapshot refinement path.
|
||||
@@ -288,7 +306,9 @@ function refineBreakerForScope(scope: string): void {
|
||||
release()
|
||||
}
|
||||
} catch {
|
||||
scopeProbeFailureAtMs.set(scope, Date.now())
|
||||
// Why: GHES hosts can be supplied through pasted project URLs. Bound the
|
||||
// negative cache so repeated failing hosts cannot accumulate forever.
|
||||
rememberScopeProbeFailure(scope, Date.now())
|
||||
} finally {
|
||||
scopeRefinementInFlight.delete(scope)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user