feat(github): add project-scoped GitHub CLI account selection and auto-detection

Цей коміт міститься в:
Deng Liu committed 2026-11-26 15:56:46 -08:00
1 джерело 77071238a0
коміт 7ec2539252
29 files changed
+1333 -51

No files matched your search

+75 -8
Переглянути файл
@@ -1,20 +1,87 @@
/**
* Settings › Version Control › GitHub (`GithubSettingsConfigurable`); accounts are gh's, so
* only the pull request option is here. Applies at once, like the Log page.
* Settings › Version Control › GitHub (`GithubSettingsConfigurable`): per-project GitHub CLI
* account selection (`vcs.github.account`) and pull request review options. Applies at once,
* like the Log page.
*/
import { Checkbox } from "@/ui";
import { useEffect, useId } from "react";
import { tx } from "@/platform/i18n";
import { Button, Checkbox, Select, T } from "@/ui";
import {
loadProjectGithubAccount,
projectAccountOptions,
setProjectGithubAccount,
useGhProjectAccount,
} from "../data/account";
import { setReviewDiffSettings, useReviewDiffSettings } from "./settings";
import styles from "./ReviewDiff.module.css";
export function GithubSettingsPage() {
const autoMarkViewed = useReviewDiffSettings((s) => s.autoMarkViewed);
const status = useGhProjectAccount((s) => s.status);
const saving = useGhProjectAccount((s) => s.saving);
const accountHeading = useId();
const prHeading = useId();
const selectId = useId();
useEffect(() => {
void loadProjectGithubAccount();
}, []);
const options = projectAccountOptions(status);
const value = status?.configuredAccount ?? "";
const suggested = !value ? (status?.suggestedAccount ?? null) : null;
return (
<div className={styles.page}>
<Checkbox
checked={autoMarkViewed}
onChange={(v) => setReviewDiffSettings({ autoMarkViewed: v })}
label="Automatically mark opened files as viewed"
/>
<section className={styles.section} aria-labelledby={accountHeading}>
<h2 id={accountHeading} className={styles.heading}>
<T>Account</T>
</h2>
<div className={styles.accountRow}>
<label htmlFor={selectId} className={styles.accountLabel}>
<T>GitHub account</T>:
</label>
<div className={styles.accountControl}>
<div className={styles.accountField}>
<div className={styles.accountSelect}>
<Select
id={selectId}
aria-label="GitHub account"
value={value}
disabled={saving}
options={options}
onChange={(next) => void setProjectGithubAccount(next)}
/>
</div>
{suggested && (
<Button size="small" disabled={saving} onClick={() => void setProjectGithubAccount(suggested)}>
{tx`Use ${suggested} for this project`}
</Button>
)}
</div>
<p className={styles.accountHint}>
{value ? (
<T>
Passes this account&apos;s GH_TOKEN to processes started in this project (terminals, agents, Git, and
run configurations).
</T>
) : (
<T>Uses GitHub CLI&apos;s active account without setting GH_TOKEN in the project environment.</T>
)}
</p>
</div>
</div>
</section>
<section className={styles.section} aria-labelledby={prHeading}>
<h2 id={prHeading} className={styles.heading}>
<T>Pull Requests</T>
</h2>
<Checkbox
checked={autoMarkViewed}
onChange={(v) => setReviewDiffSettings({ autoMarkViewed: v })}
label="Automatically mark opened files as viewed"
/>
</section>
</div>
);
}
+64 -1
Переглянути файл
@@ -29,6 +29,69 @@
.page {
display: flex;
flex-direction: column;
gap: var(--space-2);
gap: var(--space-4);
padding: 4px 0;
}
.section {
display: flex;
flex-direction: column;
gap: var(--space-2);
}
.heading {
margin: 0;
padding-bottom: 4px;
border-bottom: 1px solid var(--border);
color: var(--fg-strong);
font-size: var(--fs-ui);
font-weight: 600;
}
.accountRow {
display: grid;
grid-template-columns: max-content minmax(0, 1fr);
align-items: start;
column-gap: var(--space-3);
row-gap: var(--space-1);
}
.accountLabel {
line-height: var(--h-field);
color: var(--fg);
white-space: nowrap;
}
.accountControl {
display: flex;
flex-direction: column;
gap: var(--space-1);
min-width: 0;
}
.accountField {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--space-2);
min-width: 0;
}
.accountSelect {
display: flex;
width: 280px;
max-width: 100%;
min-width: 0;
}
.accountSelect > button {
flex: 1;
min-width: 0;
}
.accountHint {
margin: 0;
max-width: 480px;
color: var(--fg-subtle);
font-size: var(--fs-small);
}