mirror of
https://github.com/stablyai/orca.git
synced 2026-11-04 02:57:36 +00:00
feat(sidebar): main produces per-workspace PR facts, checked against the window in dev and test (#30026)
* feat(sidebar): main produces per-workspace PR facts, checked against the window in dev and test Co-Authored-By: Claude <noreply@anthropic.com> * refactor(sidebar): share the PR cache key candidates instead of splitting an import Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
import type { GlobalSettings } from '../global-settings-types'
|
||||
import {
|
||||
LOCAL_EXECUTION_HOST_ID,
|
||||
normalizeExecutionHostId,
|
||||
toSshExecutionHostId
|
||||
} from '../execution-host'
|
||||
|
||||
type RuntimeFocusSettings = Pick<GlobalSettings, 'activeRuntimeEnvironmentId'> | null | undefined
|
||||
|
||||
export function getGitHubRepoCacheKey(
|
||||
repoPath: string,
|
||||
repoId: string | undefined,
|
||||
suffix: string,
|
||||
settings?: RuntimeFocusSettings,
|
||||
connectionId?: string | null,
|
||||
executionHostId?: string | null,
|
||||
hasRepoOwner = false
|
||||
): string {
|
||||
const owner = repoId ?? repoPath
|
||||
const scope = getGitHubCacheHostScope(settings, connectionId, executionHostId, hasRepoOwner)
|
||||
// Why: runtime/SSH lookups can observe different remotes than the local repo
|
||||
// path, so cache keys include the repo's owning execution boundary.
|
||||
if (scope) {
|
||||
return `${scope}::${owner}::${suffix}`
|
||||
}
|
||||
return `${owner}::${suffix}`
|
||||
}
|
||||
|
||||
function getGitHubCacheHostScope(
|
||||
settings?: RuntimeFocusSettings,
|
||||
connectionId?: string | null,
|
||||
executionHostId?: string | null,
|
||||
hasRepoOwner = false
|
||||
): string | null {
|
||||
const hostId = normalizeExecutionHostId(executionHostId)
|
||||
if (hostId) {
|
||||
return hostId === LOCAL_EXECUTION_HOST_ID ? null : hostId
|
||||
}
|
||||
const sshConnectionId = connectionId?.trim()
|
||||
if (sshConnectionId) {
|
||||
return toSshExecutionHostId(sshConnectionId)
|
||||
}
|
||||
// Why: an existing repo with no remote/runtime owner is local; only missing
|
||||
// owner context should inherit the focused runtime fallback.
|
||||
if (hasRepoOwner) {
|
||||
return null
|
||||
}
|
||||
const runtimeEnvironmentId = settings?.activeRuntimeEnvironmentId?.trim()
|
||||
if (runtimeEnvironmentId) {
|
||||
return `runtime:${encodeURIComponent(runtimeEnvironmentId)}`
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export function getLegacyGitHubRepoCacheKey(
|
||||
repoPath: string,
|
||||
repoId: string | undefined,
|
||||
suffix: string
|
||||
): string {
|
||||
return `${repoId ?? repoPath}::${suffix}`
|
||||
}
|
||||
|
||||
export function getGitHubPRCacheKey(
|
||||
repoPath: string,
|
||||
repoId: string | undefined,
|
||||
branch: string,
|
||||
settings?: RuntimeFocusSettings,
|
||||
connectionId?: string | null,
|
||||
executionHostId?: string | null,
|
||||
hasRepoOwner = false
|
||||
): string {
|
||||
return getGitHubRepoCacheKey(
|
||||
repoPath,
|
||||
repoId,
|
||||
branch,
|
||||
settings,
|
||||
connectionId,
|
||||
executionHostId,
|
||||
hasRepoOwner
|
||||
)
|
||||
}
|
||||
|
||||
export function getLegacyGitHubPRCacheKey(
|
||||
repoPath: string,
|
||||
repoId: string | undefined,
|
||||
branch: string
|
||||
): string {
|
||||
return getLegacyGitHubRepoCacheKey(repoPath, repoId, branch)
|
||||
}
|
||||
|
||||
/** Every key a repo's branch PR may sit under in the cache, the repo-scoped one first. */
|
||||
export function getGitHubPRCacheKeyCandidates(
|
||||
repo: { path: string; id: string; connectionId?: string | null; executionHostId?: string | null },
|
||||
branch: string
|
||||
): string[] {
|
||||
return [
|
||||
getGitHubPRCacheKey(
|
||||
repo.path,
|
||||
repo.id,
|
||||
branch,
|
||||
null,
|
||||
repo.connectionId,
|
||||
repo.executionHostId,
|
||||
true
|
||||
),
|
||||
getLegacyGitHubPRCacheKey(repo.path, repo.id, branch),
|
||||
getLegacyGitHubPRCacheKey(repo.path, undefined, branch)
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user