mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
feat: add repo rename capability with custom name field (#294)
* feat: add repo rename capability with custom name field Add a custom name field to repos, allowing users to set a display name independent of the repo URL or path. Includes a migration, PATCH endpoint, rename dialog, and display name consolidation. - DB migration 014 adds name column to repos table - PATCH /api/repos/:id endpoint with Zod validation - RenameRepoDialog component with clear/reset support - RepoRowActions gains Rename action in both dropdown and inline modes - getRepoDisplayName() consolidated to accept a repo object and prefer name - All repo name display call sites updated to use the new API * fix: add DialogTitle to RenameRepoDialog for a11y compliance * refactor: extract getRepoDisplayName to shared utils, fix schedule cache invalidation on rename
This commit is contained in:
1 parent
01e50a7019
commit
6a4e8734f9
33 files changed
+535
-84
No files matched your search
@@ -0,0 +1,25 @@
|
||||
import type { Migration } from '../migration-runner'
|
||||
|
||||
interface ColumnInfo {
|
||||
name: string
|
||||
}
|
||||
|
||||
const migration: Migration = {
|
||||
version: 14,
|
||||
name: 'repos-add-name',
|
||||
|
||||
up(db) {
|
||||
const tableInfo = db.prepare('PRAGMA table_info(repos)').all() as ColumnInfo[]
|
||||
const existing = new Set(tableInfo.map((column) => column.name))
|
||||
|
||||
if (!existing.has('name')) {
|
||||
db.run('ALTER TABLE repos ADD COLUMN name TEXT')
|
||||
}
|
||||
},
|
||||
|
||||
down(db) {
|
||||
void db
|
||||
},
|
||||
}
|
||||
|
||||
export default migration
|
||||
@@ -12,6 +12,7 @@ import migration010 from './009-prompt-templates'
|
||||
import migration011 from './011-repo-last-accessed'
|
||||
import migration012 from './012-opencode-model-state'
|
||||
import migration013 from './013-app-secrets'
|
||||
import migration014 from './014-repos-add-name'
|
||||
|
||||
export const allMigrations: Migration[] = [
|
||||
migration001,
|
||||
@@ -27,4 +28,5 @@ export const allMigrations: Migration[] = [
|
||||
migration011,
|
||||
migration012,
|
||||
migration013,
|
||||
migration014,
|
||||
]
|
||||
@@ -1,12 +1,13 @@
|
||||
import type { Database } from 'bun:sqlite'
|
||||
import type { Repo, CreateRepoInput } from '../types/repo'
|
||||
import { getReposPath } from '@opencode-manager/shared/config/env'
|
||||
import { ASSISTANT_REPO_ID, ASSISTANT_REPO_PATH } from '@opencode-manager/shared/utils'
|
||||
import { ASSISTANT_REPO_ID, ASSISTANT_REPO_PATH, getRepoDisplayName } from '@opencode-manager/shared/utils'
|
||||
import { getErrorMessage } from '../utils/error-utils'
|
||||
import path from 'path'
|
||||
|
||||
interface RepoRow {
|
||||
id: number
|
||||
name?: string
|
||||
repo_url?: string
|
||||
local_path: string
|
||||
source_path?: string
|
||||
@@ -28,6 +29,7 @@ function rowToRepo(row: RepoRow): Repo {
|
||||
|
||||
return {
|
||||
id: row.id,
|
||||
name: row.name ?? undefined,
|
||||
repoUrl: row.repo_url,
|
||||
localPath: row.local_path,
|
||||
fullPath,
|
||||
@@ -285,10 +287,8 @@ export function listRepos(db: Database, repoOrder?: number[]): Repo[] {
|
||||
return [...orderedRepos, ...remainingRepos]
|
||||
}
|
||||
|
||||
function getRepoName(repo: Repo): string {
|
||||
return repo.repoUrl
|
||||
? repo.repoUrl.split('/').slice(-1)[0]?.replace('.git', '') || repo.localPath
|
||||
: repo.sourcePath ? path.basename(repo.sourcePath) : repo.localPath
|
||||
export function getRepoName(repo: Repo): string {
|
||||
return getRepoDisplayName(repo)
|
||||
}
|
||||
|
||||
export function updateRepoStatus(db: Database, id: number, cloneStatus: Repo['cloneStatus']): void {
|
||||
@@ -331,6 +331,14 @@ export function updateRepoBranch(db: Database, id: number, branch: string): void
|
||||
}
|
||||
}
|
||||
|
||||
export function updateRepoName(db: Database, id: number, name: string | null): void {
|
||||
const stmt = db.prepare('UPDATE repos SET name = ? WHERE id = ?')
|
||||
const result = stmt.run(name, id)
|
||||
if (result.changes === 0) {
|
||||
throw new Error(`Repository with id ${id} not found`)
|
||||
}
|
||||
}
|
||||
|
||||
export function deleteRepo(db: Database, id: number): void {
|
||||
if (id === ASSISTANT_REPO_ID) {
|
||||
return
|
||||
|
||||
+26
-11
@@ -9,7 +9,7 @@ import {
|
||||
type ScheduleRunStatus,
|
||||
type ScheduleRunTriggerSource,
|
||||
} from '@opencode-manager/shared/schemas'
|
||||
import { ASSISTANT_REPO_ID, ASSISTANT_REPO_NAME, ASSISTANT_REPO_PATH } from '@opencode-manager/shared/utils'
|
||||
import { ASSISTANT_REPO_ID, ASSISTANT_REPO_NAME, ASSISTANT_REPO_PATH, getRepoDisplayName } from '@opencode-manager/shared/utils'
|
||||
import type { ScheduleJobPersistenceInput } from '../services/schedule-config'
|
||||
|
||||
interface ScheduleJobRow {
|
||||
@@ -403,31 +403,42 @@ export interface ScheduleJobWithRepo extends ScheduleJob {
|
||||
interface ScheduleJobWithRepoRow extends ScheduleJobRow {
|
||||
repo_url: string | null
|
||||
repo_path: string | null
|
||||
repo_name: string | null
|
||||
repo_source_path: string | null
|
||||
}
|
||||
|
||||
function repoNameFromPath(repoPath: string): string {
|
||||
if (!repoPath || repoPath === '/') return 'Unknown'
|
||||
return repoPath.split(/[\\/]/).pop() ?? repoPath
|
||||
interface RepoDisplayRow {
|
||||
repo_id: number
|
||||
repo_path: string | null
|
||||
repo_name: string | null
|
||||
repo_url?: string | null
|
||||
repo_source_path?: string | null
|
||||
}
|
||||
|
||||
function resolveRepoDisplay(repoId: number, repoPath: string | null): { repoName: string; repoPath: string } {
|
||||
if (repoId === ASSISTANT_REPO_ID) {
|
||||
function resolveRepoDisplay(row: RepoDisplayRow): { repoName: string; repoPath: string } {
|
||||
if (row.repo_id === ASSISTANT_REPO_ID) {
|
||||
return { repoName: ASSISTANT_REPO_NAME, repoPath: ASSISTANT_REPO_PATH }
|
||||
}
|
||||
return { repoName: repoNameFromPath(repoPath ?? ''), repoPath: repoPath ?? '' }
|
||||
const displayName = getRepoDisplayName({
|
||||
name: row.repo_name,
|
||||
repoUrl: row.repo_url,
|
||||
sourcePath: row.repo_source_path,
|
||||
localPath: row.repo_path,
|
||||
})
|
||||
return { repoName: displayName, repoPath: row.repo_path ?? '' }
|
||||
}
|
||||
|
||||
function rowToScheduleJobWithRepo(row: ScheduleJobWithRepoRow): ScheduleJobWithRepo {
|
||||
return {
|
||||
...rowToScheduleJob(row),
|
||||
...resolveRepoDisplay(row.repo_id, row.repo_path),
|
||||
...resolveRepoDisplay(row),
|
||||
repoUrl: row.repo_url ?? '',
|
||||
}
|
||||
}
|
||||
|
||||
export function listAllScheduleJobsWithRepos(db: Database): ScheduleJobWithRepo[] {
|
||||
const stmt = db.prepare(`
|
||||
SELECT sj.*, r.repo_url, r.local_path as repo_path
|
||||
SELECT sj.*, r.repo_url, r.local_path as repo_path, r.name as repo_name, r.source_path as repo_source_path
|
||||
FROM schedule_jobs sj
|
||||
LEFT JOIN repos r ON sj.repo_id = r.id
|
||||
ORDER BY COALESCE(r.local_path, ''), sj.name
|
||||
@@ -445,13 +456,16 @@ export interface ScheduleRunWithContext extends ScheduleRun {
|
||||
interface ScheduleRunWithContextRow extends ScheduleRunRow {
|
||||
job_name: string
|
||||
repo_path: string | null
|
||||
repo_name: string | null
|
||||
repo_url: string | null
|
||||
repo_source_path: string | null
|
||||
}
|
||||
|
||||
function rowToScheduleRunWithContext(row: ScheduleRunWithContextRow): ScheduleRunWithContext {
|
||||
return {
|
||||
...rowToScheduleRun(row),
|
||||
jobName: row.job_name,
|
||||
...resolveRepoDisplay(row.repo_id, row.repo_path),
|
||||
...resolveRepoDisplay(row),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -494,7 +508,8 @@ export function listAllScheduleRuns(db: Database, options: ListAllRunsOptions =
|
||||
sr.started_at, sr.finished_at, sr.created_at,
|
||||
sr.session_id, sr.session_title,
|
||||
NULL AS log_text, NULL AS response_text, sr.error_text,
|
||||
sj.name AS job_name, r.local_path AS repo_path
|
||||
sj.name AS job_name, r.local_path AS repo_path, r.name AS repo_name,
|
||||
r.repo_url AS repo_url, r.source_path AS repo_source_path
|
||||
FROM schedule_runs sr
|
||||
JOIN schedule_jobs sj ON sr.job_id = sj.id
|
||||
LEFT JOIN repos r ON sr.repo_id = r.id
|
||||
|
||||
Reference in new issue
Block a user