Files
boocode/apps/server/src/services/gitea.ts
indifferentketchup 48a972e139 project-ux: archive/rename/Open-in-Gitea sidebar context menu, archived projects landing, create-project bootstrap with Gitea remote
Server:
- projects.status + projects.gitea_remote (additive) with CHECK ('open','archived')
- GET /api/projects?status=archived; PATCH /api/projects/:id (rename);
  POST /api/projects/:id/archive | unarchive; POST /api/projects/create
- POST /api/projects ON CONFLICT (path) DO UPDATE SET status='open': re-add
  of archived path restores existing row (preserves id + FKs); already-open
  path returns 409. Detected-repos picker now excludes only status='open'.
- New gitea.ts (createGiteaRepo + GiteaRepoExistsError) and
  project_bootstrap.ts (sanitize name, mkdir under PROJECT_ROOT_WHITELIST,
  git init -b main + first commit with -c user.name/email per-command, optional
  Gitea repo create + remote add + push; all via execFile, no shell).
- 3 new user-stream frames: project_archived, project_unarchived, project_updated.
- sidebar.ts now selects path + gitea_remote and filters status='open'.
- Gitea env added to config.ts (GITEA_BASE_URL, GITEA_USER, GITEA_TOKEN,
  GITEA_SSH_HOST).
- docker-compose.yml /opt mount flipped to rw so create-project can mkdir.
- auto_name.ts gate relaxed from `!== 1` to `< 1` (fires on every turn while
  chat name is empty, not only the first).

Web:
- ProjectSidebar: project rows use proper Radix ContextMenu; items Rename /
  Archive / Open in Gitea. Inline rename, archive confirm dialog.
  Removed obsolete handleRemove + DropdownMenu hack.
- Home: Add-existing + Create-new buttons; collapsible Archived Projects
  section with Restore.
- New CreateProjectModal: name + live folder preview, commit msg, Private/
  Public radio, create-Gitea-remote checkbox, toast on success/warnings.
- New projectUrls.ts giteaUrlFor() — uses gitea_remote when present,
  falls back to convention URL.
- 3 new event types in sessionEvents.ts with idempotent useSidebar handlers.
- SidebarProject extended with path + gitea_remote so Open-in-Gitea can
  resolve without a separate fetch.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 02:51:59 +00:00

51 lines
1.2 KiB
TypeScript

export interface GiteaConfig {
baseUrl: string;
user: string;
token: string;
}
export interface GiteaRepo {
clone_url: string;
ssh_url: string;
html_url: string;
}
export class GiteaRepoExistsError extends Error {
constructor() {
super('gitea-repo-exists');
}
}
export async function createGiteaRepo(
cfg: GiteaConfig,
name: string,
options: { private: boolean }
): Promise<GiteaRepo> {
const res = await fetch(`${cfg.baseUrl}/api/v1/user/repos`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `token ${cfg.token}`,
},
body: JSON.stringify({
name,
private: options.private,
auto_init: false,
}),
});
if (res.status === 409) throw new GiteaRepoExistsError();
if (!res.ok) {
const text = await res.text().catch(() => '');
throw new Error(`gitea-api-${res.status}: ${text.slice(0, 200)}`);
}
const body = (await res.json()) as { ssh_url?: string; clone_url?: string; html_url?: string };
if (!body.ssh_url || !body.html_url || !body.clone_url) {
throw new Error(`gitea-api-unexpected-shape: ${JSON.stringify(body).slice(0, 200)}`);
}
return {
ssh_url: body.ssh_url,
clone_url: body.clone_url,
html_url: body.html_url,
};
}