From 3025b274f5c33dedaaa64ac605c04bce08f9c5a1 Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Thu, 5 Nov 2026 15:20:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(github):=20make=20Change=20Repository=20or?= =?UTF-8?q?=20Account=E2=80=A6=20work=20before=20a=20repository=20is=20con?= =?UTF-8?q?nected=20(#1492)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The action was only enabled while the Pull Requests tool window was connected to a repository, so from Find Action or a shortcut it did nothing in a project that wasn't connected yet (gh not installed or not logged in, or several GitHub remotes to choose from). It is now available in any open project: connected, it forgets the choice and shows the repository selector as before; not connected, it opens the Pull Requests tool window, which shows the selector or how to log in. Fixes #1464 --- src/features/github/index.ts | 5 +++-- src/features/github/toolwindow/toolwindow.test.tsx | 10 +++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/features/github/index.ts b/src/features/github/index.ts index 526c07631..433aa314c 100644 --- a/src/features/github/index.ts +++ b/src/features/github/index.ts @@ -144,8 +144,9 @@ function actions(): Action[] { id: "github.changeRepository", title: "Change Repository or Account…", category: "GitHub", - when: CONNECTED, - run: () => changeRepository(), + when: WHEN, + // Not connected yet: the tool window offers the repository selector, or explains how to log in. + run: () => (useGhRepository.getState().connection ? changeRepository() : void showPullRequests()), }, { // pull.request.select.action diff --git a/src/features/github/toolwindow/toolwindow.test.tsx b/src/features/github/toolwindow/toolwindow.test.tsx index 269dee84f..fd40645f4 100644 --- a/src/features/github/toolwindow/toolwindow.test.tsx +++ b/src/features/github/toolwindow/toolwindow.test.tsx @@ -3,7 +3,7 @@ import { act, render, screen } from "@testing-library/react"; import { getAction } from "@/platform/actions"; import { getContext } from "@/platform/context"; import * as ipc from "@/platform/ipc"; -import { useContributions } from "@/workbench/contributions"; +import { provideToolWindowService, useContributions, type ToolWindowService } from "@/workbench/contributions"; import { activate } from "../index"; import { setCurrentRepository } from "../api/client"; import type { GHRepository, GHUser } from "../api/types"; @@ -114,6 +114,14 @@ describe("tool window", () => { expect(getAction(id), id).toBeDefined(); }); + it("opens the tool window for Change Repository or Account while not connected", async () => { + const show = vi.fn(); + provideToolWindowService({ show } as unknown as ToolWindowService); + useGhRepository.setState({ availability: { kind: "notInstalled" } }); + await getAction("github.changeRepository")!.run({ arg: undefined, ctx: { projectOpen: true } }); + expect(show).toHaveBeenCalledWith("pullRequests", true); + }); + it("shows gh's state when it is not ready", () => { useGhRepository.setState({ availability: { kind: "notInstalled" } }); render();