mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
feat(schedules): add workspace modes and worktree management
This commit is contained in:
1 parent
c06075651d
commit
6ec3f3bd91
90 files changed
+2084
-801
No files matched your search
@@ -2,7 +2,8 @@ import type { Repo } from './types'
|
||||
import { FetchError, fetchWrapper, fetchWrapperVoid, fetchWrapperBlob } from './fetchWrapper'
|
||||
import { API_BASE_URL } from '@/config'
|
||||
import { saveFile } from '@/lib/download'
|
||||
import type { DiscoverReposResponse, AssistantModeStatus, AssistantModeInitRequest, DeleteRepoRequest, DeleteRepoResult, RepoGitIdentity, WorktreeSetupResult } from '@opencode-manager/shared/types'
|
||||
import type { CreateRepoWorkspaceRequest, DiscoverReposResponse, AssistantModeStatus, AssistantModeInitRequest, DeleteRepoRequest, DeleteRepoResult, RepoGitIdentity, WorktreeSetupResult } from '@opencode-manager/shared/types'
|
||||
import type { RepoWorktreeSchedule, RepoWorktreeSource } from '@opencode-manager/shared/utils'
|
||||
|
||||
export interface CreateRepoOptions {
|
||||
repoUrl?: string
|
||||
@@ -40,11 +41,21 @@ export async function getRepo(id: number): Promise<Repo> {
|
||||
|
||||
export type RepoSibling = Repo & {
|
||||
currentBranch?: string
|
||||
worktreeSource?: RepoWorktreeSource
|
||||
worktreeStrategy?: string
|
||||
schedule?: RepoWorktreeSchedule
|
||||
}
|
||||
|
||||
export function workspaceLabel(workspace: RepoSibling): string {
|
||||
return workspace.currentBranch || workspace.branch || workspace.localPath || 'workspace'
|
||||
return workspace.currentBranch || workspace.branch || workspace.localPath || 'worktree'
|
||||
}
|
||||
|
||||
export function worktreeSourceLabel(worktree: RepoSibling): string | null {
|
||||
if (worktree.schedule) {
|
||||
return worktree.schedule.runId === null ? 'Schedule · shared' : `Schedule · run #${worktree.schedule.runId}`
|
||||
}
|
||||
if (worktree.worktreeSource === 'git') return 'Git'
|
||||
return worktree.worktreeSource === 'opencode' ? 'OpenCode' : null
|
||||
}
|
||||
|
||||
export interface RepoWorktree {
|
||||
@@ -63,9 +74,11 @@ export async function deleteRepoWorkspace(repoId: number, directory: string): Pr
|
||||
})
|
||||
}
|
||||
|
||||
export async function createRepoWorkspace(repoId: number): Promise<RepoWorktree & { worktreeSetup?: WorktreeSetupResult }> {
|
||||
export async function createRepoWorkspace(repoId: number, request: CreateRepoWorkspaceRequest = {}): Promise<RepoWorktree & { worktreeSetup?: WorktreeSetupResult }> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/workspaces`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(request),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import type {
|
||||
ScheduleJob,
|
||||
ScheduleRun,
|
||||
ScheduleRunStatus,
|
||||
ScheduleWorktree,
|
||||
UpdateScheduleJobRequest,
|
||||
} from '@opencode-manager/shared/types'
|
||||
|
||||
@@ -22,6 +23,7 @@ export interface ScheduleJobWithRepo extends ScheduleJob {
|
||||
repoPath: string
|
||||
repoUrl: string
|
||||
lastRun: ScheduleRunSummary | null
|
||||
retainedWorktreeCount: number
|
||||
}
|
||||
|
||||
export interface ScheduleRunWithContext extends ScheduleRun {
|
||||
@@ -162,6 +164,18 @@ export async function clearRepoScheduleRuns(repoId: number, jobId: number): Prom
|
||||
})
|
||||
}
|
||||
|
||||
export async function listScheduleWorktrees(repoId: number, jobId: number): Promise<{ worktrees: ScheduleWorktree[] }> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/schedules/${jobId}/worktrees`)
|
||||
}
|
||||
|
||||
export async function removeScheduleWorktrees(repoId: number, jobId: number, worktreePath?: string): Promise<{ removed: number }> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/schedules/${jobId}/worktrees`, {
|
||||
method: 'DELETE',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(worktreePath ? { worktreePath } : {}),
|
||||
})
|
||||
}
|
||||
|
||||
export async function deleteRepoScheduleRun(repoId: number, jobId: number, runId: number): Promise<void> {
|
||||
return fetchWrapperVoid(`${API_BASE_URL}/api/repos/${repoId}/schedules/${jobId}/runs/${runId}`, {
|
||||
method: 'DELETE',
|
||||
|
||||
Reference in new issue
Block a user