mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +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
@@ -21,7 +21,7 @@ export function scheduleTargetFromRepo(repo: Repo): ScheduleTarget {
|
||||
return {
|
||||
repoId: repo.id,
|
||||
kind: 'repo',
|
||||
name: getRepoDisplayName(repo.repoUrl, repo.localPath, repo.sourcePath),
|
||||
name: getRepoDisplayName(repo),
|
||||
subtitle: repo.localPath,
|
||||
fullPath: repo.fullPath,
|
||||
backHref: `/repos/${repo.id}`,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { sanitizeForTTS } from './utils'
|
||||
import { getRepoDisplayName, sanitizeForTTS } from './utils'
|
||||
|
||||
describe('sanitizeForTTS', () => {
|
||||
it('should handle headers', () => {
|
||||
@@ -82,3 +82,33 @@ describe('sanitizeForTTS', () => {
|
||||
expect(sanitizeForTTS('Text with <tag>content</tag> here')).toBe('Text with content here')
|
||||
})
|
||||
})
|
||||
|
||||
describe('getRepoDisplayName', () => {
|
||||
it('prefers name when present', () => {
|
||||
expect(getRepoDisplayName({ name: 'Fork A', repoUrl: 'https://github.com/x/y.git' })).toBe('Fork A')
|
||||
})
|
||||
|
||||
it('trims and ignores empty name', () => {
|
||||
expect(getRepoDisplayName({ name: ' ', repoUrl: 'https://github.com/x/y.git' })).toBe('y')
|
||||
})
|
||||
|
||||
it('falls back to repoUrl basename stripping .git', () => {
|
||||
expect(getRepoDisplayName({ repoUrl: 'https://github.com/user/repo.git' })).toBe('repo')
|
||||
})
|
||||
|
||||
it('falls back to sourcePath basename', () => {
|
||||
expect(getRepoDisplayName({ sourcePath: '/home/user/projects/my-repo' })).toBe('my-repo')
|
||||
})
|
||||
|
||||
it('falls back to the localPath basename', () => {
|
||||
expect(getRepoDisplayName({ localPath: '/some/path' })).toBe('path')
|
||||
})
|
||||
|
||||
it('falls back to Repository when all are empty', () => {
|
||||
expect(getRepoDisplayName({})).toBe('Repository')
|
||||
})
|
||||
|
||||
it('handles null values properly', () => {
|
||||
expect(getRepoDisplayName({ repoUrl: null, localPath: null, sourcePath: null })).toBe('Repository')
|
||||
})
|
||||
})
|
||||
@@ -2,6 +2,8 @@ import { clsx, type ClassValue } from "clsx"
|
||||
import { twMerge } from "tailwind-merge"
|
||||
import type { CSSProperties } from "react"
|
||||
|
||||
export { getRepoDisplayName } from '@opencode-manager/shared/utils'
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
@@ -14,20 +16,6 @@ export const GPU_ACCELERATED_STYLE: CSSProperties = {
|
||||
|
||||
export const MODAL_TRANSITION_MS = 300
|
||||
|
||||
function getPathBaseName(filePath: string): string {
|
||||
return filePath.split(/[\\/]/).pop() || filePath
|
||||
}
|
||||
|
||||
export function getRepoDisplayName(repoUrl?: string | null, localPath?: string | null, sourcePath?: string | null): string {
|
||||
if (repoUrl) {
|
||||
return repoUrl.split("/").pop()?.replace(".git", "") || "Repository"
|
||||
}
|
||||
if (sourcePath) {
|
||||
return getPathBaseName(sourcePath) || localPath || 'Repository'
|
||||
}
|
||||
return localPath || "Repository"
|
||||
}
|
||||
|
||||
export function sanitizeForTTS(text: string): string {
|
||||
if (!text) return ''
|
||||
|
||||
|
||||
Reference in new issue
Block a user