mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
section 1: Phase 1: Shell environment owner and repo working-directory
This commit is contained in:
1 parent
52b6147ed3
commit
b494ee9f4a
11 files changed
+280
-17
No files matched your search
@@ -6,6 +6,7 @@ import {
|
||||
getSSHCredentialsForHost,
|
||||
createGitEnv,
|
||||
createGhCliEnv,
|
||||
createGitIdentityEnv,
|
||||
findGitHubCredential,
|
||||
type ResolvedGitCredential,
|
||||
} from '../utils/git-auth'
|
||||
@@ -14,6 +15,7 @@ import { logger } from '../utils/logger'
|
||||
import {
|
||||
getRepoByDirectory,
|
||||
getRepoGitCredentialId,
|
||||
getRepoGitIdentityId,
|
||||
getRepoSandboxGitCredentials,
|
||||
listRepos,
|
||||
} from '../db/queries'
|
||||
@@ -95,6 +97,21 @@ export class CredentialProvider {
|
||||
return this.getGhCliEnvForContext(this.resolveContext(options))
|
||||
}
|
||||
|
||||
getShellEnv(options: CredentialResolutionOptions = {}): Record<string, string> {
|
||||
return { ...this.getGhCliEnv(options), ...this.getAssignedGitIdentityEnv(options) }
|
||||
}
|
||||
|
||||
getAssignedGitIdentityEnv(options: CredentialResolutionOptions = {}): Record<string, string> {
|
||||
const repo = this.resolveRepo(options)
|
||||
if (!repo) return {}
|
||||
|
||||
const identityId = getRepoGitIdentityId(this.database, repo.id)
|
||||
if (!identityId) return {}
|
||||
|
||||
const profile = this.getPreferences().gitIdentities?.find((identity) => identity.id === identityId)
|
||||
return profile ? createGitIdentityEnv(profile) : {}
|
||||
}
|
||||
|
||||
private resolveContext(options: CredentialResolutionOptions, repo = this.resolveRepo(options)): CredentialResolutionContext {
|
||||
const preferences = this.getPreferences()
|
||||
return {
|
||||
|
||||
@@ -7,7 +7,7 @@ import type { Database } from 'bun:sqlite'
|
||||
import type { Repo, CreateRepoInput } from '../types/repo'
|
||||
import { logger } from '../utils/logger'
|
||||
import { getReposPath, getScheduleWorktreesPath } from '@opencode-manager/shared/config/env'
|
||||
import { normalizeRepoDirectoryName, sanitizeRepoDirectoryName, sanitizeBranchForDirectory, getRepoBaseDirectoryName, normalizeRepoUrlForCompare, isSSHUrl, normalizeSSHUrl, SCP_STYLE_URL_PATTERN } from '@opencode-manager/shared/utils'
|
||||
import { normalizeRepoDirectoryName, sanitizeRepoDirectoryName, sanitizeBranchForDirectory, getRepoBaseDirectoryName, normalizeRepoUrlForCompare, isSSHUrl, normalizeSSHUrl, SCP_STYLE_URL_PATTERN, ASSISTANT_REPO_ID } from '@opencode-manager/shared/utils'
|
||||
import type { GitAuthService } from './git-auth'
|
||||
import { isGitHubHttpsUrl } from '../utils/git-auth'
|
||||
import path from 'path'
|
||||
@@ -18,6 +18,7 @@ import { resolveProjectId, isGitMainCheckout } from './project-id-resolver'
|
||||
import { listRepos } from '../db/queries'
|
||||
import { listActiveScheduleRunWorktreePaths } from '../db/schedules'
|
||||
import { SettingsService } from './settings'
|
||||
import { buildAssistantRepo } from './assistant-mode'
|
||||
import type { OpenCodeClient } from './opencode/client'
|
||||
import { openCodeLocation } from '@opencode-manager/shared/opencode'
|
||||
import { canonicalPathSync, mkdirSafe } from '../utils/fs-safe'
|
||||
@@ -1168,6 +1169,26 @@ export async function resolveRepoProjectId(openCodeClient: OpenCodeClient, direc
|
||||
return project.id
|
||||
}
|
||||
|
||||
export function resolveRepoOrAssistant(database: Database, id: number): Repo | null {
|
||||
return getRepoById(database, id) ?? (id === ASSISTANT_REPO_ID ? buildAssistantRepo() : null)
|
||||
}
|
||||
|
||||
export function findSiblingByDirectory<T extends { fullPath: string }>(siblings: T[], directory: string): T | undefined {
|
||||
const requestedDirectory = canonicalPathSync(path.resolve(directory))
|
||||
return siblings.find((sibling) => canonicalPathSync(path.resolve(sibling.fullPath)) === requestedDirectory)
|
||||
}
|
||||
|
||||
export async function resolveRepoWorkingDirectory(
|
||||
repo: Repo,
|
||||
directory: string | undefined,
|
||||
loadSiblings: () => Promise<Array<{ fullPath: string }>>,
|
||||
): Promise<string | null> {
|
||||
if (directory === undefined) return repo.fullPath
|
||||
if (canonicalPathSync(path.resolve(directory)) === canonicalPathSync(path.resolve(repo.fullPath))) return repo.fullPath
|
||||
|
||||
return findSiblingByDirectory(await loadSiblings(), directory)?.fullPath ?? null
|
||||
}
|
||||
|
||||
export async function getSiblingRepos(
|
||||
database: Database,
|
||||
repoId: number,
|
||||
|
||||
Reference in new issue
Block a user