From 2b714f5accdac37c8f99ebf421e30a759e186012 Mon Sep 17 00:00:00 2001 From: Seongmin Lee Date: Fri, 4 Sep 2026 23:21:56 +0900 Subject: [PATCH] web: wire branch deletion Signed-off-by: Seongmin Lee --- web/src/lib/api/pull.ts | 47 ++++++++++++++----- .../repo/pulls/PullActions.stories.svelte | 11 +++++ .../components/repo/pulls/PullActions.svelte | 13 ++++- .../[version]/[[range]]/PullViewPage.svelte | 42 ++++++++++++++--- 4 files changed, 94 insertions(+), 19 deletions(-) diff --git a/web/src/lib/api/pull.ts b/web/src/lib/api/pull.ts index 2b6f36907..071960df1 100644 --- a/web/src/lib/api/pull.ts +++ b/web/src/lib/api/pull.ts @@ -122,6 +122,7 @@ export const keepCommit = async ( }; const MERGE_COMMIT_NSID = "sh.tangled.git.mergeCommit"; +const DELETE_BRANCH_NSID = "org.tangled.temp.git.deleteBranch"; const REPO_PUSH_NSID = "sh.tangled.repo.push"; export interface MergeCommitInput { @@ -132,31 +133,55 @@ export interface MergeCommitInput { style: "rebase"; } -export const mergeCommit = async ( +const mirrorPush = async ( agent: OAuthUserAgent, mirror: string, knot: string, - input: MergeCommitInput, - fetch: typeof globalThis.fetch = globalThis.fetch + nsid: string, + body: unknown, + fetch: typeof globalThis.fetch ): Promise => { const token = await mintServiceAuth(agent, { aud: serviceDidForHost(knot), - // `sh.tangled.git.mergeCommit` expects service-auth token minted for `sh.tangled.repo.push` - // so it can reuse it on git-push. + // git write operations expect `sh.tangled.repo.push` lxm token lxm: REPO_PUSH_NSID }); - const response = await fetch(buildUrl(mirror, MERGE_COMMIT_NSID), { + const response = await fetch(buildUrl(mirror, nsid), { method: "POST", headers: { "content-type": "application/json", accept: "application/json", authorization: `Bearer ${token}` }, - body: JSON.stringify({ - target: { $type: `${MERGE_COMMIT_NSID}#target`, ...input.target }, - source: { $type: `${MERGE_COMMIT_NSID}#source`, ...input.source }, - style: input.style - }) + body: JSON.stringify(body) }); if (!response.ok) throw await toResponseError(response); }; + +export const mergeCommit = ( + agent: OAuthUserAgent, + mirror: string, + knot: string, + input: MergeCommitInput, + fetch: typeof globalThis.fetch = globalThis.fetch +): Promise => + mirrorPush( + agent, + mirror, + knot, + MERGE_COMMIT_NSID, + { + target: { $type: `${MERGE_COMMIT_NSID}#target`, ...input.target }, + source: { $type: `${MERGE_COMMIT_NSID}#source`, ...input.source }, + style: input.style + }, + fetch + ); + +export const deleteBranch = ( + agent: OAuthUserAgent, + mirror: string, + knot: string, + input: { repo: string; branch: string }, + fetch: typeof globalThis.fetch = globalThis.fetch +): Promise => mirrorPush(agent, mirror, knot, DELETE_BRANCH_NSID, input, fetch); diff --git a/web/src/lib/components/repo/pulls/PullActions.stories.svelte b/web/src/lib/components/repo/pulls/PullActions.stories.svelte index 45f131ffa..674301ddb 100644 --- a/web/src/lib/components/repo/pulls/PullActions.stories.svelte +++ b/web/src/lib/components/repo/pulls/PullActions.stories.svelte @@ -49,6 +49,17 @@ args={{ pullState: "merged" as PullState, canChangeState: false, canMerge: false }} /> + + + diff --git a/web/src/lib/components/repo/pulls/PullActions.svelte b/web/src/lib/components/repo/pulls/PullActions.svelte index b3e22e570..b07bc97ce 100644 --- a/web/src/lib/components/repo/pulls/PullActions.svelte +++ b/web/src/lib/components/repo/pulls/PullActions.svelte @@ -13,6 +13,7 @@