fix(github): make Change Repository or Account… work before a repository is connected (#1492)

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
This commit is contained in:
l0ng-ai authored and GitHub committed 2026-11-05 15:20:47 +08:00
1 parent bdf94926ec
commit 3025b274f5
2 files changed
+12 -3

No files matched your search

+3 -2
View File
@@ -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
@@ -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(<PullRequestsToolWindow />);