дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 09:11:10 +02:00
feat(github): add in-IDE GitHub account sign-in in Settings, Pull Requests, and Clone (#6642)
Settings › Version Control › GitHub only listed accounts already signed in with gh, Clone Repository › GitHub told signed-out users to run gh auth login in a terminal, and Pull Requests opened a raw terminal tab. The PTY sign-in dialog and OAuth device-code parser move from features/agents to src/workbench/CliSignInDialog.tsx and src/platform/deviceCode.ts, so agents and GitHub share them without a cross-feature import. GitHub settings get Sign In… / Add account… (selecting a newly added second account for the project) and Install GitHub CLI when gh is missing; the Pull Requests tool window signs in in-IDE and reconnects, with Add account… in its error state, repository selector and account menu; Clone › GitHub gets Sign In… and Add account…. The merge with main carries the dialog's terminal-reply filtering and FIFO input over to the moved file. Co-authored-by: dengliu <[email protected]>
Цей коміт міститься в:
1 джерело
90734775b9
коміт
4c5f4fa1e1
25 files changed
+784
-86
No files matched your search
@@ -3,12 +3,17 @@
|
||||
* account selection (`vcs.github.account`) and pull request review options. Applies at once,
|
||||
* like the Log page.
|
||||
*/
|
||||
import { useEffect, useId } from "react";
|
||||
import { useEffect, useId, useRef, useState } from "react";
|
||||
import { GH_MANUAL_INSTALL_URL, installGhTool } from "@/platform/ghTool";
|
||||
import { tx } from "@/platform/i18n";
|
||||
import { Button, Checkbox, Select, T } from "@/ui";
|
||||
import { isCancelled } from "@/platform/ipc";
|
||||
import { openExternalUrl } from "@/platform/openUrl";
|
||||
import { Button, Checkbox, Select, Spinner, T } from "@/ui";
|
||||
import { CliSignInDialog } from "@/workbench/CliSignInDialog";
|
||||
import {
|
||||
loadProjectGithubAccount,
|
||||
projectAccountOptions,
|
||||
refreshAfterGithubSignIn,
|
||||
setProjectGithubAccount,
|
||||
useGhProjectAccount,
|
||||
} from "../data/account";
|
||||
@@ -19,6 +24,10 @@ export function GithubSettingsPage() {
|
||||
const autoMarkViewed = useReviewDiffSettings((s) => s.autoMarkViewed);
|
||||
const status = useGhProjectAccount((s) => s.status);
|
||||
const saving = useGhProjectAccount((s) => s.saving);
|
||||
const [signingIn, setSigningIn] = useState(false);
|
||||
const [installingGh, setInstallingGh] = useState(false);
|
||||
const [installError, setInstallError] = useState<string | null>(null);
|
||||
const prevLoginsRef = useRef<Set<string>>(new Set());
|
||||
const accountHeading = useId();
|
||||
const prHeading = useId();
|
||||
const selectId = useId();
|
||||
@@ -30,6 +39,27 @@ export function GithubSettingsPage() {
|
||||
const options = projectAccountOptions(status);
|
||||
const value = status?.configuredAccount ?? "";
|
||||
const suggested = !value ? (status?.suggestedAccount ?? null) : null;
|
||||
const ghMissing = status !== null && !status.ghInstalled;
|
||||
const hasAccounts = (status?.accounts.length ?? 0) > 0;
|
||||
|
||||
const startSignIn = () => {
|
||||
prevLoginsRef.current = new Set((status?.accounts ?? []).map((entry) => entry.login));
|
||||
setSigningIn(true);
|
||||
};
|
||||
|
||||
const installGh = () => {
|
||||
if (installingGh) return;
|
||||
setInstallingGh(true);
|
||||
setInstallError(null);
|
||||
void installGhTool()
|
||||
.promise.then((installed) => {
|
||||
if (installed) void loadProjectGithubAccount();
|
||||
})
|
||||
.catch((e: unknown) => {
|
||||
if (!isCancelled(e)) setInstallError(e instanceof Error ? e.message : String(e));
|
||||
})
|
||||
.finally(() => setInstallingGh(false));
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={styles.page}>
|
||||
@@ -53,6 +83,32 @@ export function GithubSettingsPage() {
|
||||
onChange={(next) => void setProjectGithubAccount(next)}
|
||||
/>
|
||||
</div>
|
||||
{status?.ghInstalled && (
|
||||
<Button
|
||||
size="small"
|
||||
variant={hasAccounts ? "secondary" : "primary"}
|
||||
disabled={saving}
|
||||
onClick={startSignIn}
|
||||
>
|
||||
<T>{hasAccounts ? "Add account…" : "Sign In…"}</T>
|
||||
</Button>
|
||||
)}
|
||||
{ghMissing && (
|
||||
<>
|
||||
<Button size="small" variant="primary" disabled={installingGh} onClick={installGh}>
|
||||
{installingGh ? (
|
||||
<>
|
||||
<Spinner size={12} /> <T>Installing…</T>
|
||||
</>
|
||||
) : (
|
||||
<T>Install GitHub CLI</T>
|
||||
)}
|
||||
</Button>
|
||||
<Button size="small" onClick={() => void openExternalUrl(GH_MANUAL_INSTALL_URL)}>
|
||||
<T>Download manually…</T>
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
{suggested && (
|
||||
<Button size="small" disabled={saving} onClick={() => void setProjectGithubAccount(suggested)}>
|
||||
{tx`Use ${suggested} for this project`}
|
||||
@@ -60,7 +116,9 @@ export function GithubSettingsPage() {
|
||||
)}
|
||||
</div>
|
||||
<p className={styles.accountHint}>
|
||||
{value ? (
|
||||
{ghMissing ? (
|
||||
<T>Install GitHub CLI (`gh`) to switch between multiple GitHub accounts.</T>
|
||||
) : value ? (
|
||||
<T>
|
||||
Passes this account's GH_TOKEN to processes started in this project (terminals, agents, Git, and
|
||||
run configurations).
|
||||
@@ -69,6 +127,11 @@ export function GithubSettingsPage() {
|
||||
<T>Uses GitHub CLI's active account without setting GH_TOKEN in the project environment.</T>
|
||||
)}
|
||||
</p>
|
||||
{installError && (
|
||||
<p className={styles.accountHint} role="alert">
|
||||
{installError}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
@@ -82,6 +145,13 @@ export function GithubSettingsPage() {
|
||||
label="Automatically mark opened files as viewed"
|
||||
/>
|
||||
</section>
|
||||
{signingIn && (
|
||||
<CliSignInDialog
|
||||
target={{ kind: "gh" }}
|
||||
onClose={() => setSigningIn(false)}
|
||||
onCompleted={() => void refreshAfterGithubSignIn(prevLoginsRef.current)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Заблокувати користувача