дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 17:21:13 +02:00
feat(github): add project-scoped GitHub CLI account selection (#6277)
A project can pin a GitHub CLI account in vcs.github.account (.openidea/settings.toml, a login, never a token), chosen in Settings > Version Control > GitHub or from the Pull Requests tool window header. With an account chosen, its token is resolved through gh and set as GH_TOKEN in the project environment for the project root and its agent worktrees; a .envrc GH_TOKEN still wins, and the token is cleared when the project closes or loses trust. Copilot keeps billing to its own account through COPILOT_GITHUB_TOKEN.
Automatic (the default) sets no GH_TOKEN and makes no GitHub calls on project open. When the settings page or the Pull Requests window asks for the status with several gh accounts signed in, the project's GitHub remote is probed to suggest a non-active account with access ("Use <login> for this project").
New commands: gh_project_account_status, gh_set_project_account. The gh account listing is shared with the Copilot account selector.
Co-authored-by: dengliu <[email protected]>
Цей коміт міститься в:
1 джерело
77071238a0
коміт
a5e0c41663
29 files changed
+1215
-53
No files matched your search
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* Per-project GitHub CLI (`gh`) account selection (`vcs.github.account` in `.openidea/settings.toml`).
|
||||
* Kept free of editor/markdown imports so `GithubSettingsPage` stays within `settingsWindowBoot`.
|
||||
*/
|
||||
import { create } from "zustand";
|
||||
import type { GhProjectAccountStatus } from "@/bindings";
|
||||
import { tx } from "@/platform/i18n";
|
||||
import { call, commands, isTauri } from "@/platform/ipc";
|
||||
import type { SelectOption } from "@/ui";
|
||||
|
||||
interface GhProjectAccountState {
|
||||
status: GhProjectAccountStatus | null;
|
||||
loading: boolean;
|
||||
saving: boolean;
|
||||
/** Incremented whenever the user changes the project GitHub account so open views reconnect. */
|
||||
revision: number;
|
||||
}
|
||||
|
||||
export const useGhProjectAccount = create<GhProjectAccountState>(() => ({
|
||||
status: null,
|
||||
loading: false,
|
||||
saving: false,
|
||||
revision: 0,
|
||||
}));
|
||||
|
||||
export async function loadProjectGithubAccount(): Promise<GhProjectAccountStatus | null> {
|
||||
if (!isTauri()) return useGhProjectAccount.getState().status;
|
||||
useGhProjectAccount.setState({ loading: true });
|
||||
try {
|
||||
const status = await call(commands.ghProjectAccountStatus());
|
||||
useGhProjectAccount.setState({ status, loading: false });
|
||||
return status;
|
||||
} catch {
|
||||
useGhProjectAccount.setState({ loading: false });
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function setProjectGithubAccount(account: string): Promise<GhProjectAccountStatus | null> {
|
||||
if (!isTauri()) {
|
||||
useGhProjectAccount.setState((s) => ({
|
||||
status: s.status
|
||||
? {
|
||||
...s.status,
|
||||
configuredAccount: account,
|
||||
effectiveAccount: account || s.status.accounts.find((a) => a.active)?.login || null,
|
||||
suggestedAccount: account ? null : s.status.suggestedAccount,
|
||||
}
|
||||
: null,
|
||||
revision: s.revision + 1,
|
||||
}));
|
||||
return useGhProjectAccount.getState().status;
|
||||
}
|
||||
useGhProjectAccount.setState({ saving: true });
|
||||
try {
|
||||
const status = await call(commands.ghSetProjectAccount(account));
|
||||
useGhProjectAccount.setState((s) => ({ status, saving: false, revision: s.revision + 1 }));
|
||||
return status;
|
||||
} catch {
|
||||
useGhProjectAccount.setState({ saving: false });
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function projectAccountOptions(status: GhProjectAccountStatus | null): SelectOption[] {
|
||||
const accounts = status?.accounts ?? [];
|
||||
const configured = status?.configuredAccount ?? "";
|
||||
const activeLogin =
|
||||
accounts.find((a) => a.active)?.login ?? (!configured ? (status?.effectiveAccount ?? null) : null);
|
||||
const automaticLabel = activeLogin ? tx`Automatic (${activeLogin})` : tx("Automatic");
|
||||
|
||||
return [
|
||||
{ value: "", label: automaticLabel, verbatim: true },
|
||||
...accounts.map((a) => ({ value: a.login, label: a.login, verbatim: true })),
|
||||
...(configured && !accounts.some((a) => a.login === configured)
|
||||
? [{ value: configured, label: tx`${configured} (not signed in)`, verbatim: true }]
|
||||
: []),
|
||||
];
|
||||
}
|
||||
@@ -224,7 +224,12 @@ export async function connect(
|
||||
if (seq !== connectSeq) return false;
|
||||
if (!repository) throw new Error(`Repository ${nameWithOwner(coordinates)} not found`);
|
||||
const previous = useGhRepository.getState().connection;
|
||||
if (!sameRepository(previous?.coordinates, coordinates) || previous?.root !== root) resetRepositoryData();
|
||||
if (
|
||||
!sameRepository(previous?.coordinates, coordinates) ||
|
||||
previous?.root !== root ||
|
||||
previous?.currentUser.login !== currentUser.login
|
||||
)
|
||||
resetRepositoryData();
|
||||
setCurrentRepository({ ...coordinates, id: repository.id, root });
|
||||
useGhRepository.setState((s) => ({
|
||||
connection: { coordinates, repository, currentUser, root, remotes },
|
||||
|
||||
Reference in new issue
Заблокувати користувача