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();