diff --git a/src/features/github/data/local.ts b/src/features/github/data/local.ts index 233512a5..4d056e80 100644 --- a/src/features/github/data/local.ts +++ b/src/features/github/data/local.ts @@ -23,9 +23,12 @@ export const useGhBusy = create<{ busy: { title: string; line: string; request: busy: null, })); -/** Runs a cancellable, streaming gh / git operation; null when it failed, was cancelled or another one runs. */ +/** + * Runs a cancellable, streaming gh / git operation; null when it failed, was cancelled or another one runs. + * `title` shows in the banner while it runs, `failure` titles the error notification. + */ export async function withBusy( - title: string, + { title, failure }: { title: string; failure: string }, run: (request: RequestId, out: Channel) => Promise, ): Promise { if (useGhBusy.getState().busy) { @@ -48,7 +51,7 @@ export async function withBusy( notifications().notify({ group: "vcs", level: "error", - title: `${title.replace(/…$/, "")} failed`, + title: failure, body: errorMessage(e), key: "github-op", }); @@ -66,7 +69,8 @@ export function cancelBusy() { /** "Checkout Branch": fetches and checks out the pull request's branch (gh's local name). */ export async function checkoutPullRequest(number: number): Promise { // The command resolves with nothing (`null`), which `withBusy` reports as a failure. - const done = await withBusy(`Checking out #${number}…`, async (r, out) => { + const op = { title: tx`Checking out #${number}…`, failure: tx`Couldn't check out #${number}` }; + const done = await withBusy(op, async (r, out) => { await call(commands.ghPrCheckout(connectedRoot(), r, number, out)); return true; }); @@ -89,7 +93,8 @@ export async function prepareDiff(pr: GHPullRequest): Promise + const op = { title: tx`Fetching #${pr.number}…`, failure: tx`Couldn't fetch #${pr.number}` }; + const revs = await withBusy(op, (r, out) => call(commands.ghPrPrepareDiff(root, r, pr.number, pr.headRefOid, pr.baseRefOid, pr.baseRefName, repo, out)), ); if (revs) diffCache.set(key, revs); @@ -185,7 +190,11 @@ export async function openInWorktree(number: number): Promise { const revs = await prepareDiff(pr); if (!revs) return; const path = `${String(revs.root).replace(/[\\/]+$/, "")}_PR_${number}`; - const added = await withBusy(`Creating worktree for #${number}…`, async () => { + const op = { + title: tx`Creating worktree for #${number}…`, + failure: tx`Couldn't create the worktree for #${number}`, + }; + const added = await withBusy(op, async () => { await call(commands.vcsAddWorktree(revs.root, path, pr.headRefOid, null)); return true; }); diff --git a/src/features/github/timeline/comments/suggestion.ts b/src/features/github/timeline/comments/suggestion.ts index 15a8d705..1fd3c117 100644 --- a/src/features/github/timeline/comments/suggestion.ts +++ b/src/features/github/timeline/comments/suggestion.ts @@ -31,8 +31,10 @@ export async function applySuggestion( suggestion: readonly string[], commitMessage?: string, ): Promise { - const title = commitMessage ? tx("Committing suggested change") : tx("Applying suggested change"); - const done = await withBusy(title, async () => { + const op = commitMessage + ? { title: tx("Committing suggested change"), failure: tx("Couldn't commit the suggested change") } + : { title: tx("Applying suggested change"), failure: tx("Couldn't apply the suggested change") }; + const done = await withBusy(op, async () => { const root = await repositoryRoot(); const abs = `${root}/${target.path}`; const text = await call(commands.fsReadText(abs)); @@ -61,7 +63,10 @@ export async function applySuggestion( return true; }); if (!done) return false; - if (thread.viewerCanResolve) await withBusy(tx("Resolving thread"), () => resolveThread(number, thread.id)); + if (thread.viewerCanResolve) + await withBusy({ title: tx("Resolving thread"), failure: tx("Couldn't resolve the thread") }, () => + resolveThread(number, thread.id), + ); return true; } diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index 4a0dfc89..3aeb866a 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -5912,5 +5912,14 @@ "Delete shelved changes “{name}”": "删除搁置的更改“{name}”", "Rename shelved changes": "重命名搁置的更改", "Passed to the agent process, replacing variables of the same name. Changes apply to new sessions.": "传给智能体进程,覆盖同名变量。对新会话生效。", - "Expected NAME=value: {pair}": "应为 NAME=value:{pair}" + "Expected NAME=value: {pair}": "应为 NAME=value:{pair}", + "Checking out #{number}…": "正在检出 #{number}…", + "Couldn't check out #{number}": "无法检出 #{number}", + "Fetching #{number}…": "正在获取 #{number}…", + "Couldn't fetch #{number}": "无法获取 #{number}", + "Creating worktree for #{number}…": "正在为 #{number} 创建工作树…", + "Couldn't create the worktree for #{number}": "无法为 #{number} 创建工作树", + "Couldn't commit the suggested change": "无法提交建议的更改", + "Couldn't apply the suggested change": "无法应用建议的更改", + "Couldn't resolve the thread": "无法解决讨论串" }