feat(i18n): localize Settings → Integrations → GitHub connection and auth (#2155)
Co-authored-by: Kandev Agent <agent@kandev.dev> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -9,11 +9,13 @@ import { useGitHubAppRegistrations } from "@/hooks/domains/github/use-github-app
|
||||
import { GitHubAppCreateForm } from "./github-app-create-form";
|
||||
import { GitHubAppImportForm } from "./github-app-import-form";
|
||||
import { GitHubAppRegistrationList } from "./github-app-registration-list";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
type AppView = "choose" | "import" | "create";
|
||||
type RegistrationHook = ReturnType<typeof useGitHubAppRegistrations>;
|
||||
|
||||
export function GitHubAppConnectionPanel({ workspaceId }: { workspaceId: string }) {
|
||||
const { t } = useTranslation();
|
||||
const registrations = useGitHubAppRegistrations(workspaceId);
|
||||
const [view, setView] = useState<AppView>("choose");
|
||||
const { selectedId, setSelectedId, selectedRegistration } = useAppRegistrationSelection(
|
||||
@@ -31,11 +33,12 @@ export function GitHubAppConnectionPanel({ workspaceId }: { workspaceId: string
|
||||
try {
|
||||
const response = await registrations.startInstall(selectedRegistration.id);
|
||||
const url = response.url ?? response.URL;
|
||||
if (!url) throw new Error("GitHub did not return an installation URL");
|
||||
// Surfaced to the user by the catch below, so it is copy.
|
||||
if (!url) throw new Error(t("github:githubDidNotReturnAnInstallationUrl"));
|
||||
window.location.assign(url);
|
||||
} catch (error) {
|
||||
toast({
|
||||
description: error instanceof Error ? error.message : "App installation failed",
|
||||
description: error instanceof Error ? error.message : t("github:appInstallationFailed"),
|
||||
variant: "error",
|
||||
});
|
||||
}
|
||||
@@ -67,16 +70,14 @@ export function GitHubAppConnectionPanel({ workspaceId }: { workspaceId: string
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-1">
|
||||
<h3 className="text-sm font-medium">Choose a GitHub App</h3>
|
||||
<h3 className="text-sm font-medium">{t("github:chooseAGithubApp")}</h3>
|
||||
<p className="text-xs leading-5 text-muted-foreground">
|
||||
Use an App when automation needs its own identity, short-lived tokens, and
|
||||
repository-level installation control. Setup is more involved and requires a publicly
|
||||
reachable HTTPS URL.
|
||||
{t("github:useAnAppWhenAutomationNeeds")}
|
||||
</p>
|
||||
</div>
|
||||
{registrations.loading ? (
|
||||
<div className="flex min-h-11 items-center gap-2 text-sm text-muted-foreground">
|
||||
<Spinner className="h-4 w-4" /> Loading registered Apps...
|
||||
<Spinner className="h-4 w-4" /> {t("github:loadingRegisteredApps")}
|
||||
</div>
|
||||
) : (
|
||||
<GitHubAppRegistrationList
|
||||
@@ -94,19 +95,18 @@ export function GitHubAppConnectionPanel({ workspaceId }: { workspaceId: string
|
||||
data-testid="github-app-install-button"
|
||||
>
|
||||
{registrations.mutating && <Spinner className="mr-2 h-4 w-4" />}
|
||||
Install for this workspace
|
||||
{t("github:installForThisWorkspace")}
|
||||
<IconExternalLink className="ml-2 h-4 w-4" />
|
||||
</Button>
|
||||
<Button variant="outline" className="h-11 cursor-pointer" onClick={() => setView("import")}>
|
||||
<IconPlus className="mr-2 h-4 w-4" /> Add existing App
|
||||
<IconPlus className="mr-2 h-4 w-4" /> {t("github:addExistingApp")}
|
||||
</Button>
|
||||
<Button variant="outline" className="h-11 cursor-pointer" onClick={() => setView("create")}>
|
||||
<IconPlus className="mr-2 h-4 w-4" /> Create new App
|
||||
<IconPlus className="mr-2 h-4 w-4" /> {t("github:createNewApp")}
|
||||
</Button>
|
||||
</div>
|
||||
<p className="text-xs leading-5 text-muted-foreground">
|
||||
A registration can be reused across workspaces, or you can keep work and personal Apps
|
||||
separate. Each workspace selects and installs its own credential.
|
||||
{t("github:aRegistrationCanBeReusedAcross")}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
@@ -129,9 +129,10 @@ function useAppRegistrationSelection(workspaceId: string, registrations: Registr
|
||||
}
|
||||
|
||||
function BackButton({ onClick }: { onClick: () => void }) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<Button variant="ghost" className="h-11 cursor-pointer px-2" onClick={onClick}>
|
||||
Back to registered Apps
|
||||
{t("github:backToRegisteredApps")}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
import { GitHubAppPolicyDialog } from "./github-app-policy-dialog";
|
||||
import { GitHubAppVisibilityField } from "./github-app-visibility-field";
|
||||
import type { useGitHubAppRegistrations } from "@/hooks/domains/github/use-github-app-registrations";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
type RegistrationHook = ReturnType<typeof useGitHubAppRegistrations>;
|
||||
|
||||
@@ -29,6 +30,7 @@ export function GitHubAppCreateForm({
|
||||
workspaceId: string;
|
||||
registrations: RegistrationHook;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [displayName, setDisplayName] = useState("");
|
||||
const [ownerType, setOwnerType] = useState<"user" | "organization">("organization");
|
||||
const [ownerLogin, setOwnerLogin] = useState("");
|
||||
@@ -70,7 +72,10 @@ export function GitHubAppCreateForm({
|
||||
);
|
||||
} catch (error) {
|
||||
const detail = appRegistrationError(error);
|
||||
toast({ description: detail?.error ?? "GitHub App setup could not start", variant: "error" });
|
||||
toast({
|
||||
description: detail?.error ?? t("github:githubAppSetupCouldNotStart"),
|
||||
variant: "error",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,13 +109,13 @@ function ManifestHandoff({
|
||||
handoff: StartGitHubAppManifestResponse;
|
||||
onEdit: () => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-1">
|
||||
<h3 className="text-sm font-medium">GitHub is ready to create the App</h3>
|
||||
<h3 className="text-sm font-medium">{t("github:githubIsReadyToCreateThe")}</h3>
|
||||
<p className="text-xs leading-5 text-muted-foreground">
|
||||
GitHub will show the generated permissions and ask you to confirm. Returning from GitHub
|
||||
adds the registration; installing it for this workspace remains an explicit step.
|
||||
{t("github:githubWillShowTheGeneratedPermissions")}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex flex-col gap-2 sm:flex-row">
|
||||
@@ -118,11 +123,11 @@ function ManifestHandoff({
|
||||
className="h-11 cursor-pointer"
|
||||
onClick={() => submitManifestToGitHub(handoff.registration_url, handoff.manifest)}
|
||||
>
|
||||
Continue on GitHub
|
||||
{t("github:continueOnGithub")}
|
||||
<IconExternalLink className="ml-2 h-4 w-4" />
|
||||
</Button>
|
||||
<Button variant="outline" className="h-11 cursor-pointer" onClick={onEdit}>
|
||||
Edit details
|
||||
{t("github:editDetails")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -146,24 +151,24 @@ type CreateFieldsProps = {
|
||||
};
|
||||
|
||||
function CreateAppFields(props: CreateFieldsProps) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<form onSubmit={props.onSubmit} className="space-y-4">
|
||||
<div className="space-y-1">
|
||||
<h3 className="text-sm font-medium">Create a GitHub App</h3>
|
||||
<h3 className="text-sm font-medium">{t("github:createAGithubApp")}</h3>
|
||||
<p className="text-xs leading-5 text-muted-foreground">
|
||||
Kandev generates the exact App policy. You confirm creation on GitHub; Kandev then stores
|
||||
this registration so it can be selected by a workspace.
|
||||
{t("github:kandevGeneratesTheExactAppPolicy")}
|
||||
</p>
|
||||
</div>
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
<Field label="Name in Kandev" error={props.errors.displayName}>
|
||||
<Field label={t("github:nameInKandev")} error={props.errors.displayName}>
|
||||
<Input
|
||||
className="h-11"
|
||||
value={props.displayName}
|
||||
onChange={(event) => props.onDisplayName(event.target.value)}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="GitHub owner login" error={props.errors.ownerLogin}>
|
||||
<Field label={t("github:githubOwnerLogin")} error={props.errors.ownerLogin}>
|
||||
<Input
|
||||
className="h-11"
|
||||
value={props.ownerLogin}
|
||||
@@ -177,13 +182,13 @@ function CreateAppFields(props: CreateFieldsProps) {
|
||||
className="flex min-h-11 flex-wrap items-center gap-5"
|
||||
>
|
||||
<Label className="flex cursor-pointer items-center gap-2">
|
||||
<RadioGroupItem value="organization" /> Organization
|
||||
<RadioGroupItem value="organization" /> {t("github:organization")}
|
||||
</Label>
|
||||
<Label className="flex cursor-pointer items-center gap-2">
|
||||
<RadioGroupItem value="user" /> Personal account
|
||||
<RadioGroupItem value="user" /> {t("github:personalAccount")}
|
||||
</Label>
|
||||
</RadioGroup>
|
||||
<Field label="Public Kandev URL" error={props.errors.publicBaseUrl}>
|
||||
<Field label={t("github:publicKandevUrl")} error={props.errors.publicBaseUrl}>
|
||||
<Input
|
||||
className="h-11"
|
||||
type="url"
|
||||
@@ -192,14 +197,12 @@ function CreateAppFields(props: CreateFieldsProps) {
|
||||
onChange={(event) => props.onPublicBaseUrl(event.target.value)}
|
||||
/>
|
||||
</Field>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
GitHub must reach this HTTPS origin for signed webhooks and callbacks.
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground">{t("github:githubMustReachThisHttpsOrigin")}</p>
|
||||
<GitHubAppVisibilityField value={props.visibility} onChange={props.onVisibility} />
|
||||
<div className="flex flex-col gap-2 sm:flex-row">
|
||||
<Button type="submit" disabled={props.mutating} className="h-11 cursor-pointer">
|
||||
{props.mutating && <Spinner className="mr-2 h-4 w-4" />}
|
||||
Prepare App on GitHub
|
||||
{t("github:prepareAppOnGithub")}
|
||||
<IconExternalLink className="ml-2 h-4 w-4" />
|
||||
</Button>
|
||||
<GitHubAppPolicyDialog />
|
||||
|
||||
@@ -4,6 +4,7 @@ import { RadioGroup, RadioGroupItem } from "@kandev/ui/radio-group";
|
||||
import { Textarea } from "@kandev/ui/textarea";
|
||||
import type { GitHubAppOwnerType, GitHubAppVisibility } from "@/lib/types/github";
|
||||
import type { AppSetupErrors } from "./github-app-onboarding-model";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
export type GitHubAppImportValues = {
|
||||
displayName: string;
|
||||
@@ -30,24 +31,25 @@ export function GitHubAppImportIdentityFields({
|
||||
errors: AppSetupErrors;
|
||||
update: Update;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
<Field label="Name in Kandev" error={errors.displayName}>
|
||||
<Field label={t("github:nameInKandev")} error={errors.displayName}>
|
||||
<Input
|
||||
className="h-11"
|
||||
value={values.displayName}
|
||||
onChange={(e) => update("displayName", e.target.value)}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="GitHub App slug" error={errors.slug}>
|
||||
<Field label={t("github:githubAppSlug")} error={errors.slug}>
|
||||
<Input
|
||||
className="h-11"
|
||||
value={values.slug}
|
||||
onChange={(e) => update("slug", e.target.value)}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="GitHub owner login" error={errors.ownerLogin}>
|
||||
<Field label={t("github:githubOwnerLogin")} error={errors.ownerLogin}>
|
||||
<Input
|
||||
className="h-11"
|
||||
value={values.ownerLogin}
|
||||
@@ -61,10 +63,10 @@ export function GitHubAppImportIdentityFields({
|
||||
className="flex min-h-11 flex-wrap items-center gap-5"
|
||||
>
|
||||
<Label className="flex cursor-pointer items-center gap-2">
|
||||
<RadioGroupItem value="Organization" /> Organization
|
||||
<RadioGroupItem value="Organization" /> {t("github:organization")}
|
||||
</Label>
|
||||
<Label className="flex cursor-pointer items-center gap-2">
|
||||
<RadioGroupItem value="User" /> Personal account
|
||||
<RadioGroupItem value="User" /> {t("github:personalAccount")}
|
||||
</Label>
|
||||
</RadioGroup>
|
||||
</div>
|
||||
@@ -80,11 +82,14 @@ export function GitHubAppImportSecretFields({
|
||||
errors: AppSetupErrors;
|
||||
update: Update;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
// Keys are the value/error field names; only the labels are copy. Resolved
|
||||
// here rather than at module scope so they follow a locale switch.
|
||||
const labels = {
|
||||
appId: "App ID",
|
||||
clientId: "Client ID",
|
||||
clientSecret: "Client secret",
|
||||
webhookSecret: "Webhook secret",
|
||||
appId: t("github:appId"),
|
||||
clientId: t("github:clientId"),
|
||||
clientSecret: t("github:clientSecret"),
|
||||
webhookSecret: t("github:webhookSecret"),
|
||||
} as const;
|
||||
return (
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
@@ -100,7 +105,7 @@ export function GitHubAppImportSecretFields({
|
||||
</Field>
|
||||
))}
|
||||
<div className="sm:col-span-2">
|
||||
<Field label="Private key (.pem)" error={errors.privateKey}>
|
||||
<Field label={t("github:privateKeyPem")} error={errors.privateKey}>
|
||||
<Textarea
|
||||
className="min-h-28 font-mono text-xs"
|
||||
value={values.privateKey}
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
type GitHubAppImportValues,
|
||||
} from "./github-app-import-fields";
|
||||
import { GitHubAppVisibilityField } from "./github-app-visibility-field";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
type RegistrationHook = ReturnType<typeof useGitHubAppRegistrations>;
|
||||
|
||||
@@ -36,6 +37,7 @@ export function GitHubAppImportForm({
|
||||
registrations: RegistrationHook;
|
||||
onImported: (registrationId: string) => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [preparation, setPreparation] = useState<PrepareGitHubAppImportResponse | null>(null);
|
||||
const [values, setValues] = useState(initialValues);
|
||||
const [errors, setErrors] = useState<AppSetupErrors>({});
|
||||
@@ -56,7 +58,7 @@ export function GitHubAppImportForm({
|
||||
try {
|
||||
setPreparation(await registrations.prepareImport({ public_base_url: publicBaseUrl }));
|
||||
} catch (error) {
|
||||
showError(error, "Import setup could not start", toast);
|
||||
showError(error, t("github:importSetupCouldNotStart"), toast);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,12 +89,12 @@ export function GitHubAppImportForm({
|
||||
});
|
||||
setValues(clearImportSecrets);
|
||||
toast({
|
||||
description: "GitHub App imported. It is ready to install.",
|
||||
description: t("github:githubAppImportedItIsReady"),
|
||||
variant: "success",
|
||||
});
|
||||
onImported(imported.id);
|
||||
} catch (error) {
|
||||
showError(error, "GitHub App could not be imported", toast);
|
||||
showError(error, t("github:githubAppCouldNotBeImported"), toast);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,16 +138,16 @@ function PrepareImportForm(props: {
|
||||
onPublicBaseUrl: (value: string) => void;
|
||||
onSubmit: (event: React.FormEvent) => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<form onSubmit={props.onSubmit} className="space-y-3">
|
||||
<div className="space-y-1">
|
||||
<h3 className="text-sm font-medium">Add an existing GitHub App</h3>
|
||||
<h3 className="text-sm font-medium">{t("github:addAnExistingGithubApp")}</h3>
|
||||
<p className="text-xs leading-5 text-muted-foreground">
|
||||
Kandev first reserves exact callback and webhook URLs, then guides you through GitHub's
|
||||
App settings. Existing workspace access is unchanged until you install the imported App.
|
||||
{t("github:kandevFirstReservesExactCallbackAnd")}
|
||||
</p>
|
||||
</div>
|
||||
<Field label="Public Kandev URL" error={props.error}>
|
||||
<Field label={t("github:publicKandevUrl")} error={props.error}>
|
||||
<Input
|
||||
className="h-11"
|
||||
type="url"
|
||||
@@ -156,7 +158,7 @@ function PrepareImportForm(props: {
|
||||
</Field>
|
||||
<Button type="submit" disabled={props.mutating} className="h-11 cursor-pointer">
|
||||
{props.mutating && <Spinner className="mr-2 h-4 w-4" />}
|
||||
Generate setup instructions
|
||||
{t("github:generateSetupInstructions")}
|
||||
</Button>
|
||||
</form>
|
||||
);
|
||||
@@ -175,6 +177,7 @@ type PreparedImportProps = {
|
||||
};
|
||||
|
||||
function PreparedImportForm(props: PreparedImportProps) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<form onSubmit={props.onSubmit} className="space-y-5">
|
||||
<GitHubAppImportIdentityFields
|
||||
@@ -192,7 +195,7 @@ function PreparedImportForm(props: PreparedImportProps) {
|
||||
<div className="flex flex-col gap-2 sm:flex-row">
|
||||
<Button type="submit" disabled={props.mutating} className="h-11 cursor-pointer">
|
||||
{props.mutating && <Spinner className="mr-2 h-4 w-4" />}
|
||||
Verify and import App
|
||||
{t("github:verifyAndImportApp")}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
@@ -200,7 +203,7 @@ function PreparedImportForm(props: PreparedImportProps) {
|
||||
className="h-11 cursor-pointer"
|
||||
onClick={props.onStartOver}
|
||||
>
|
||||
Start over
|
||||
{t("github:startOver")}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -6,7 +6,13 @@ import { Button } from "@kandev/ui/button";
|
||||
import { useCopyToClipboard } from "@/hooks/use-copy-to-clipboard";
|
||||
import type { PrepareGitHubAppImportResponse } from "@/lib/types/github";
|
||||
import { GitHubAppPolicyDialog } from "./github-app-policy-dialog";
|
||||
import { Trans, useTranslation } from "react-i18next";
|
||||
import { formatDateTime } from "@/lib/i18n/formats";
|
||||
|
||||
// These are the verbatim field names on GitHub's own "Register a new GitHub App"
|
||||
// form, which is English-only. The guide tells the user which field to paste each
|
||||
// value into, so translating them would break that mapping — they are references
|
||||
// to another product's UI, not our copy.
|
||||
const urlLabels: [keyof PrepareGitHubAppImportResponse, string][] = [
|
||||
["public_base_url", "Homepage URL"],
|
||||
["personal_callback_url", "User authorization callback URL"],
|
||||
@@ -21,6 +27,7 @@ export function GitHubAppImportGuide({
|
||||
preparation: PrepareGitHubAppImportResponse;
|
||||
settingsUrl?: string;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const { copy } = useCopyToClipboard();
|
||||
const [copied, setCopied] = useState("");
|
||||
async function copyValue(value: string) {
|
||||
@@ -28,16 +35,24 @@ export function GitHubAppImportGuide({
|
||||
setCopied(value);
|
||||
}
|
||||
return (
|
||||
<section className="space-y-3" aria-label="GitHub App configuration instructions">
|
||||
<section className="space-y-3" aria-label={t("github:githubAppConfigurationInstructions")}>
|
||||
<div className="space-y-1">
|
||||
<h3 className="text-sm font-medium">Configure the existing App on GitHub</h3>
|
||||
<h3 className="text-sm font-medium">{t("github:configureTheExistingAppOnGithub")}</h3>
|
||||
<p className="text-xs leading-5 text-muted-foreground">
|
||||
Set these exact URLs, create a client secret and webhook secret, and download a private
|
||||
key. This one-time setup expires {new Date(preparation.expires_at).toLocaleString()}.
|
||||
{t("github:setTheseExactUrlsCreateAClientSecret", {
|
||||
expiresAt: formatDateTime(preparation.expires_at),
|
||||
})}
|
||||
</p>
|
||||
<p className="text-xs leading-5 text-muted-foreground">
|
||||
For webhooks, choose <strong>application/json</strong> as the content type and keep SSL
|
||||
verification enabled.
|
||||
{/* The content-type value is a literal the user selects on GitHub, so it
|
||||
is interpolated rather than written into the catalog. */}
|
||||
<Trans
|
||||
i18nKey="github:forWebhooksChooseContentType"
|
||||
values={{ contentType: "application/json" }}
|
||||
>
|
||||
For webhooks, choose <strong>{"{{contentType}}"}</strong> as the content type and keep
|
||||
SSL verification enabled.
|
||||
</Trans>
|
||||
</p>
|
||||
</div>
|
||||
<div className="divide-y rounded-md border">
|
||||
@@ -53,7 +68,7 @@ export function GitHubAppImportGuide({
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-11 w-11 shrink-0 cursor-pointer"
|
||||
aria-label={`Copy ${label}`}
|
||||
aria-label={t("github:copy", { label })}
|
||||
onClick={() => void copyValue(value)}
|
||||
>
|
||||
{copied === value ? (
|
||||
@@ -71,13 +86,13 @@ export function GitHubAppImportGuide({
|
||||
{settingsUrl ? (
|
||||
<Button asChild variant="outline" className="h-11 cursor-pointer">
|
||||
<a href={settingsUrl} target="_blank" rel="noreferrer">
|
||||
Open GitHub App settings
|
||||
{t("github:openGithubAppSettings")}
|
||||
<IconExternalLink className="ml-2 h-4 w-4" />
|
||||
</a>
|
||||
</Button>
|
||||
) : (
|
||||
<Button type="button" variant="outline" className="h-11" disabled>
|
||||
Open GitHub App settings
|
||||
{t("github:openGithubAppSettings")}
|
||||
<IconExternalLink className="ml-2 h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
|
||||
@@ -5,6 +5,7 @@ import type {
|
||||
GitHubAppRegistrationErrorBody,
|
||||
GitHubAppVisibility,
|
||||
} from "@/lib/types/github";
|
||||
import { t } from "@/lib/i18n";
|
||||
|
||||
const ownerPattern = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/;
|
||||
const slugPattern = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,98}[A-Za-z0-9])?$/;
|
||||
@@ -29,19 +30,19 @@ export function normalizePublicBaseUrl(rawValue: string, errors: AppSetupErrors)
|
||||
try {
|
||||
url = new URL(rawValue.trim());
|
||||
} catch {
|
||||
errors.publicBaseUrl = "Enter a public HTTPS origin.";
|
||||
errors.publicBaseUrl = t("github:enterAPublicHttpsOrigin");
|
||||
return null;
|
||||
}
|
||||
if (url.protocol !== "https:" || url.username || url.password) {
|
||||
errors.publicBaseUrl = "Enter a public HTTPS origin.";
|
||||
errors.publicBaseUrl = t("github:enterAPublicHttpsOrigin");
|
||||
return null;
|
||||
}
|
||||
if (url.hostname === "localhost" || url.hostname.endsWith(".localhost")) {
|
||||
errors.publicBaseUrl = "Enter a public host, not localhost.";
|
||||
errors.publicBaseUrl = t("github:enterAPublicHostNotLocalhost");
|
||||
return null;
|
||||
}
|
||||
if ((url.pathname && url.pathname !== "/") || url.search || url.hash) {
|
||||
errors.publicBaseUrl = "Enter an origin without a path, query, or fragment.";
|
||||
errors.publicBaseUrl = t("github:enterAnOriginWithoutAPath");
|
||||
return null;
|
||||
}
|
||||
return url.origin;
|
||||
@@ -57,8 +58,8 @@ export function validateRegistrationBasics(input: {
|
||||
const displayName = input.displayName.trim();
|
||||
const ownerLogin = input.ownerLogin.trim();
|
||||
if (!displayName || displayName.length > 100)
|
||||
errors.displayName = "Enter a name up to 100 characters.";
|
||||
if (!ownerPattern.test(ownerLogin)) errors.ownerLogin = "Enter a valid GitHub account login.";
|
||||
errors.displayName = t("github:enterANameUpTo100Characters");
|
||||
if (!ownerPattern.test(ownerLogin)) errors.ownerLogin = t("github:enterAValidGithubAccountLogin");
|
||||
const publicBaseUrl = normalizePublicBaseUrl(input.publicBaseUrl, errors);
|
||||
return { displayName, ownerLogin, publicBaseUrl, errors };
|
||||
}
|
||||
@@ -73,12 +74,13 @@ export function validateImportSecrets(input: {
|
||||
}) {
|
||||
const errors: AppSetupErrors = {};
|
||||
const appId = Number(input.appId);
|
||||
if (!Number.isSafeInteger(appId) || appId <= 0) errors.appId = "Enter the numeric GitHub App ID.";
|
||||
if (!input.clientId.trim()) errors.clientId = "Enter the App client ID.";
|
||||
if (!input.clientSecret) errors.clientSecret = "Enter the App client secret.";
|
||||
if (!input.privateKey.trim()) errors.privateKey = "Paste the App private key.";
|
||||
if (!input.webhookSecret) errors.webhookSecret = "Enter the webhook secret.";
|
||||
if (!slugPattern.test(input.slug.trim())) errors.slug = "Enter the GitHub App slug.";
|
||||
if (!Number.isSafeInteger(appId) || appId <= 0)
|
||||
errors.appId = t("github:enterTheNumericGithubAppId");
|
||||
if (!input.clientId.trim()) errors.clientId = t("github:enterTheAppClientId");
|
||||
if (!input.clientSecret) errors.clientSecret = t("github:enterTheAppClientSecret");
|
||||
if (!input.privateKey.trim()) errors.privateKey = t("github:pasteTheAppPrivateKey");
|
||||
if (!input.webhookSecret) errors.webhookSecret = t("github:enterTheWebhookSecret");
|
||||
if (!slugPattern.test(input.slug.trim())) errors.slug = t("github:enterTheGithubAppSlug");
|
||||
return { appId, errors };
|
||||
}
|
||||
|
||||
@@ -105,31 +107,31 @@ export function callbackNotice(code: string): CallbackNotice {
|
||||
if (code === "app_registered")
|
||||
return {
|
||||
tone: "success",
|
||||
title: "GitHub App added",
|
||||
description: "The App is ready to select and install for this workspace.",
|
||||
title: t("github:githubAppAdded"),
|
||||
description: t("github:theAppIsReadyToSelect"),
|
||||
};
|
||||
if (code === "app_connected")
|
||||
return {
|
||||
tone: "success",
|
||||
title: "GitHub App connected",
|
||||
description: "Workspace automation now uses the verified App installation.",
|
||||
title: t("github:githubAppConnected"),
|
||||
description: t("github:workspaceAutomationNowUsesTheVerified"),
|
||||
};
|
||||
if (code === "personal_connected")
|
||||
return {
|
||||
tone: "success",
|
||||
title: "GitHub identity connected",
|
||||
description: "My GitHub now uses your verified personal identity.",
|
||||
title: t("github:githubIdentityConnected"),
|
||||
description: t("github:myGithubNowUsesYourVerified"),
|
||||
};
|
||||
if (code === "github_app_registration_cancelled")
|
||||
return {
|
||||
tone: "info",
|
||||
title: "GitHub App setup cancelled",
|
||||
description: "The existing workspace connection was not changed.",
|
||||
title: t("github:githubAppSetupCancelled"),
|
||||
description: t("github:theExistingWorkspaceConnectionWasNot"),
|
||||
};
|
||||
return {
|
||||
tone: "error",
|
||||
title: "GitHub setup was not completed",
|
||||
description: "The GitHub response could not be verified. Review the connection and try again.",
|
||||
title: t("github:githubSetupWasNotCompleted"),
|
||||
description: t("github:theGithubResponseCouldNotBe"),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from "@kandev/ui/dialog";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
export const githubAppPermissions: Record<string, "read" | "write"> = {
|
||||
actions: "read",
|
||||
@@ -41,24 +42,23 @@ export function GitHubAppPolicyDialog({
|
||||
permissions?: Record<string, "read" | "write">;
|
||||
events?: string[];
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<Dialog>
|
||||
<DialogTrigger asChild>
|
||||
<Button variant="outline" className="h-11 cursor-pointer">
|
||||
<IconShieldCheck className="mr-2 h-4 w-4" />
|
||||
Review permissions
|
||||
{t("github:reviewPermissions")}
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="flex max-h-[80dvh] flex-col overflow-hidden sm:max-w-lg">
|
||||
<DialogHeader className="shrink-0">
|
||||
<DialogTitle>Required GitHub App policy</DialogTitle>
|
||||
<DialogDescription>
|
||||
An imported App must have at least these repository permissions and subscribed events.
|
||||
</DialogDescription>
|
||||
<DialogTitle>{t("github:requiredGithubAppPolicy")}</DialogTitle>
|
||||
<DialogDescription>{t("github:anImportedAppMustHaveAt")}</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="min-h-0 flex-1 space-y-5 overflow-y-auto overscroll-contain">
|
||||
<section>
|
||||
<h3 className="mb-2 text-sm font-medium">Repository permissions</h3>
|
||||
<h3 className="mb-2 text-sm font-medium">{t("github:repositoryPermissions")}</h3>
|
||||
<div className="divide-y rounded-md border">
|
||||
{Object.entries(permissions)
|
||||
.sort(([left], [right]) => left.localeCompare(right))
|
||||
@@ -74,7 +74,7 @@ export function GitHubAppPolicyDialog({
|
||||
</div>
|
||||
</section>
|
||||
<section>
|
||||
<h3 className="mb-2 text-sm font-medium">Subscribed events</h3>
|
||||
<h3 className="mb-2 text-sm font-medium">{t("github:subscribedEvents")}</h3>
|
||||
<div className="divide-y rounded-md border">
|
||||
{events.map((event) => (
|
||||
<div key={event} className="flex min-h-11 items-center px-3 text-sm">
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Label } from "@kandev/ui/label";
|
||||
import { RadioGroup, RadioGroupItem } from "@kandev/ui/radio-group";
|
||||
import type { GitHubAppRegistrationCatalogItem } from "@/lib/types/github";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
export function GitHubAppRegistrationList({
|
||||
registrations,
|
||||
@@ -14,10 +15,11 @@ export function GitHubAppRegistrationList({
|
||||
value: string;
|
||||
onChange: (registrationId: string) => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
if (!registrations.length) {
|
||||
return (
|
||||
<div className="rounded-md border border-dashed p-4 text-sm text-muted-foreground">
|
||||
No GitHub Apps are registered yet. Add an existing App or create one below.
|
||||
{t("github:noGithubAppsAreRegisteredYet")}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -44,28 +46,29 @@ export function GitHubAppRegistrationList({
|
||||
{registration.visibility}
|
||||
</Badge>
|
||||
{registration.status === "invalid" && (
|
||||
<Badge variant="destructive">Needs attention</Badge>
|
||||
<Badge variant="destructive">{t("github:needsAttention")}</Badge>
|
||||
)}
|
||||
{registration.selected && (
|
||||
<Badge variant="secondary">
|
||||
<IconCheck className="mr-1 h-3 w-3" /> In use
|
||||
<IconCheck className="mr-1 h-3 w-3" /> {t("github:inUse")}
|
||||
</Badge>
|
||||
)}
|
||||
</span>
|
||||
<span className="block break-words text-xs font-normal text-muted-foreground">
|
||||
{registration.owner_login}/{registration.slug} ·{" "}
|
||||
{registration.source === "managed" ? "Created by Kandev" : "Imported"}
|
||||
{registration.source === "managed"
|
||||
? t("github:createdByKandev")
|
||||
: t("github:imported")}
|
||||
</span>
|
||||
{registration.shared && (
|
||||
<span className="flex items-start gap-1.5 text-xs font-normal leading-5 text-amber-600 dark:text-amber-400">
|
||||
<IconAlertTriangle className="mt-0.5 h-3.5 w-3.5 shrink-0" />
|
||||
Used by {registration.workspace_binding_count} workspaces. Editing or deleting it
|
||||
affects all of them.
|
||||
{t("github:usedByWorkspaces", { count: registration.workspace_binding_count })}
|
||||
</span>
|
||||
)}
|
||||
{registration.status === "invalid" && (
|
||||
<span className="block text-xs font-normal leading-5 text-destructive">
|
||||
{registration.last_error || "The stored App credentials are unavailable."}
|
||||
{registration.last_error || t("github:theStoredAppCredentialsAreUnavailable")}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Label } from "@kandev/ui/label";
|
||||
import { RadioGroup, RadioGroupItem } from "@kandev/ui/radio-group";
|
||||
import type { GitHubAppVisibility } from "@/lib/types/github";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
export function GitHubAppVisibilityField({
|
||||
value,
|
||||
@@ -9,9 +10,10 @@ export function GitHubAppVisibilityField({
|
||||
value: GitHubAppVisibility;
|
||||
onChange: (value: GitHubAppVisibility) => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<fieldset className="space-y-2">
|
||||
<legend className="text-sm font-medium">Who can install this App?</legend>
|
||||
<legend className="text-sm font-medium">{t("github:whoCanInstallThisApp")}</legend>
|
||||
<RadioGroup
|
||||
value={value}
|
||||
onValueChange={(next) => onChange(next as GitHubAppVisibility)}
|
||||
@@ -20,18 +22,18 @@ export function GitHubAppVisibilityField({
|
||||
<Label className="flex min-h-20 cursor-pointer items-start gap-3 rounded-md border p-3">
|
||||
<RadioGroupItem value="private" className="mt-0.5" />
|
||||
<span>
|
||||
<span className="block text-sm font-medium">Only the App owner</span>
|
||||
<span className="block text-sm font-medium">{t("github:onlyTheAppOwner")}</span>
|
||||
<span className="block text-xs font-normal leading-5 text-muted-foreground">
|
||||
Best for personal or company-internal automation.
|
||||
{t("github:bestForPersonalOrCompanyInternal")}
|
||||
</span>
|
||||
</span>
|
||||
</Label>
|
||||
<Label className="flex min-h-20 cursor-pointer items-start gap-3 rounded-md border p-3">
|
||||
<RadioGroupItem value="public" className="mt-0.5" />
|
||||
<span>
|
||||
<span className="block text-sm font-medium">Other GitHub accounts</span>
|
||||
<span className="block text-sm font-medium">{t("github:otherGithubAccounts")}</span>
|
||||
<span className="block text-xs font-normal leading-5 text-muted-foreground">
|
||||
Allows installation elsewhere. It does not publish to Marketplace or grant repos.
|
||||
{t("github:allowsInstallationElsewhereItDoesNot")}
|
||||
</span>
|
||||
</span>
|
||||
</Label>
|
||||
|
||||
@@ -2,29 +2,38 @@ import { IconBrandGithub, IconKey, IconTerminal2 } from "@tabler/icons-react";
|
||||
import { Label } from "@kandev/ui/label";
|
||||
import { RadioGroup, RadioGroupItem } from "@kandev/ui/radio-group";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
export type GitHubAutomationMethod = "pat" | "cli" | "app";
|
||||
|
||||
const methods = [
|
||||
// `value` is the wire enum the connection form switches on — never translated.
|
||||
// The copy travels as catalog keys resolved at render: a `t()` call here would
|
||||
// be module scope and freeze at the boot locale (see docs/i18n.md). Every entry
|
||||
// carries both keys, so `t()` never receives `string | undefined`.
|
||||
type AuthMethodOption = {
|
||||
value: GitHubAutomationMethod;
|
||||
labelKey: string;
|
||||
descriptionKey: string;
|
||||
icon: typeof IconTerminal2;
|
||||
};
|
||||
|
||||
const methods: AuthMethodOption[] = [
|
||||
{
|
||||
value: "cli" as const,
|
||||
label: "GitHub CLI account",
|
||||
description:
|
||||
"Resolved from one named host account when needed. Managed tasks receive a scoped brokered identity; host Git is not inherited unless selected below.",
|
||||
value: "cli",
|
||||
labelKey: "github:githubCliAccount",
|
||||
descriptionKey: "github:resolvedFromOneNamedHostAccount",
|
||||
icon: IconTerminal2,
|
||||
},
|
||||
{
|
||||
value: "pat" as const,
|
||||
label: "Personal access token",
|
||||
description:
|
||||
"Stored encrypted by Kandev. Workspace automation and managed task GitHub HTTPS/gh act as your account.",
|
||||
value: "pat",
|
||||
labelKey: "github:personalAccessToken",
|
||||
descriptionKey: "github:storedEncryptedByKandevWorkspaceAutomation",
|
||||
icon: IconKey,
|
||||
},
|
||||
{
|
||||
value: "app" as const,
|
||||
label: "GitHub App",
|
||||
description:
|
||||
"Stored App credentials mint short-lived installation tokens. Managed tasks receive a scoped brokered App identity for allowed repositories.",
|
||||
value: "app",
|
||||
labelKey: "github:githubApp",
|
||||
descriptionKey: "github:storedAppCredentialsMintShortLived",
|
||||
icon: IconBrandGithub,
|
||||
},
|
||||
];
|
||||
@@ -36,12 +45,13 @@ export function GitHubAuthMethodList({
|
||||
value: GitHubAutomationMethod;
|
||||
onChange: (value: GitHubAutomationMethod) => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<RadioGroup
|
||||
value={value}
|
||||
onValueChange={(next) => onChange(next as GitHubAutomationMethod)}
|
||||
className="grid gap-2 sm:grid-cols-3"
|
||||
aria-label="Connection method"
|
||||
aria-label={t("github:connectionMethod")}
|
||||
>
|
||||
{methods.map((method) => {
|
||||
const Icon = method.icon;
|
||||
@@ -63,10 +73,10 @@ export function GitHubAuthMethodList({
|
||||
<span className="min-w-0 space-y-1">
|
||||
<span className="flex items-center gap-2 text-sm font-medium">
|
||||
<Icon className="h-4 w-4 shrink-0" />
|
||||
{method.label}
|
||||
{t(method.labelKey)}
|
||||
</span>
|
||||
<span className="block text-xs font-normal leading-5 text-muted-foreground">
|
||||
{method.description}
|
||||
{t(method.descriptionKey)}
|
||||
</span>
|
||||
</span>
|
||||
</Label>
|
||||
|
||||
@@ -5,6 +5,8 @@ import { Label } from "@kandev/ui/label";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@kandev/ui/select";
|
||||
import { fetchGitHubCLIAccounts } from "@/lib/api/domains/github-api";
|
||||
import type { GitHubCLIAccount } from "@/lib/types/github";
|
||||
import { Trans, useTranslation } from "react-i18next";
|
||||
import type { TFunction } from "i18next";
|
||||
|
||||
function GitHubCLIAccountNotice({
|
||||
loadError,
|
||||
@@ -15,25 +17,32 @@ function GitHubCLIAccountNotice({
|
||||
loading: boolean;
|
||||
hasAccounts: boolean;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
if (loading || hasAccounts) return null;
|
||||
if (loadError) {
|
||||
return (
|
||||
<p role="alert" className="text-xs text-destructive">
|
||||
Could not load GitHub CLI accounts. {loadError}
|
||||
{t("github:couldNotLoadGithubCliAccounts", { error: loadError })}
|
||||
</p>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Sign in with <code>gh auth login</code>, then reopen this dialog.
|
||||
{/* The command is a value, not copy: writing it into the catalog lets the
|
||||
pseudo-locale transliterate it into something the user cannot type. */}
|
||||
<Trans i18nKey="github:signInWithGhAuthLogin" values={{ command: "gh auth login" }}>
|
||||
Sign in with <code>{"{{command}}"}</code>, then reopen this dialog.
|
||||
</Trans>
|
||||
</p>
|
||||
);
|
||||
}
|
||||
|
||||
function accountPlaceholder(loading: boolean, loadError: string | null) {
|
||||
if (loading) return "Loading accounts...";
|
||||
if (loadError) return "Accounts unavailable";
|
||||
return "No gh accounts found";
|
||||
// Plain function, so `t` is threaded in rather than taken from the hook. The
|
||||
// guard never inspects this shape — `mode: "jsx-only"` only sees JSX literals.
|
||||
function accountPlaceholder(t: TFunction, loading: boolean, loadError: string | null) {
|
||||
if (loading) return t("github:loadingAccounts");
|
||||
if (loadError) return t("github:accountsUnavailable");
|
||||
return t("github:noGhAccountsFound");
|
||||
}
|
||||
|
||||
export function GitHubCLIForm({
|
||||
@@ -45,6 +54,7 @@ export function GitHubCLIForm({
|
||||
onAccountChange: (account: GitHubCLIAccount | null) => void;
|
||||
disabled?: boolean;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [accounts, setAccounts] = useState<GitHubCLIAccount[]>([]);
|
||||
const [selected, setSelected] = useState("");
|
||||
const [loadError, setLoadError] = useState<string | null>(null);
|
||||
@@ -71,7 +81,7 @@ export function GitHubCLIForm({
|
||||
if (!current) return;
|
||||
setAccounts([]);
|
||||
setLoadError(
|
||||
error instanceof Error ? error.message : "Unexpected response from the server",
|
||||
error instanceof Error ? error.message : t("github:unexpectedResponseFromTheServer"),
|
||||
);
|
||||
})
|
||||
.finally(() => current && setLoading(false));
|
||||
@@ -92,9 +102,9 @@ export function GitHubCLIForm({
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="github-cli-account">GitHub CLI account</Label>
|
||||
<Label htmlFor="github-cli-account">{t("github:githubCliAccount")}</Label>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Choose the exact account. Kandev does not silently follow the CLI's active-account change.
|
||||
{t("github:chooseTheExactAccountKandevDoes")}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex flex-col gap-2 sm:flex-row sm:items-stretch">
|
||||
@@ -104,12 +114,12 @@ export function GitHubCLIForm({
|
||||
disabled={disabled || loading || !accounts.length}
|
||||
>
|
||||
<SelectTrigger id="github-cli-account" className="min-h-11 min-w-0 flex-1">
|
||||
<SelectValue placeholder={accountPlaceholder(loading, loadError)} />
|
||||
<SelectValue placeholder={accountPlaceholder(t, loading, loadError)} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{accounts.map((item) => (
|
||||
<SelectItem key={`${item.host}:${item.login}`} value={`${item.host}\n${item.login}`}>
|
||||
{item.login} ({item.host}){item.active ? " - active" : ""}
|
||||
{item.login} ({item.host}){item.active ? t("github:cliAccountActiveSuffix") : ""}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
|
||||
@@ -24,6 +24,7 @@ import type { TaskGitCredentialsState } from "@/hooks/domains/github/use-task-gi
|
||||
import type { GitHubStatus } from "@/lib/types/github";
|
||||
import type { GitHubAutomationMethod } from "./github-auth-method-list";
|
||||
import { GitHubConnectionSettingsForm } from "./github-connection-settings-form";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
function methodForStatus(status: GitHubStatus): GitHubAutomationMethod {
|
||||
if (status.automation?.source === "github_app_installation") return "app";
|
||||
@@ -31,9 +32,6 @@ function methodForStatus(status: GitHubStatus): GitHubAutomationMethod {
|
||||
return "pat";
|
||||
}
|
||||
|
||||
const description =
|
||||
"This workspace uses one credential for repository sync, watches, background jobs, and managed agent GitHub access. Executor profile credentials can still take precedence.";
|
||||
|
||||
export function GitHubConnectionDialog({
|
||||
status,
|
||||
workspaceId,
|
||||
@@ -45,6 +43,7 @@ export function GitHubConnectionDialog({
|
||||
onSaved: () => void;
|
||||
taskAccess: TaskGitCredentialsState;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [method, setMethod] = useState<GitHubAutomationMethod>(() => methodForStatus(status));
|
||||
const { isMobile } = useResponsiveBreakpoint();
|
||||
@@ -68,7 +67,7 @@ export function GitHubConnectionDialog({
|
||||
const trigger = (
|
||||
<Button variant={connected ? "outline" : "default"} className="h-11 cursor-pointer">
|
||||
<IconPlug className="mr-2 h-4 w-4" />
|
||||
{connected ? "Change connection" : "Connect GitHub"}
|
||||
{connected ? t("github:changeConnection") : t("github:connectGithub")}
|
||||
</Button>
|
||||
);
|
||||
const body = (
|
||||
@@ -94,8 +93,10 @@ export function GitHubConnectionDialog({
|
||||
className="h-[calc(100dvh-16px-env(safe-area-inset-bottom,0px))] max-h-[calc(100dvh-16px-env(safe-area-inset-bottom,0px))] overflow-hidden"
|
||||
>
|
||||
<DrawerHeader className="shrink-0 border-b text-left">
|
||||
<DrawerTitle>{connected ? "Change GitHub connection" : "Connect GitHub"}</DrawerTitle>
|
||||
<DrawerDescription>{description}</DrawerDescription>
|
||||
<DrawerTitle>
|
||||
{connected ? t("github:changeGithubConnection") : t("github:connectGithub")}
|
||||
</DrawerTitle>
|
||||
<DrawerDescription>{t("github:thisWorkspaceUsesOneCredentialFor")}</DrawerDescription>
|
||||
</DrawerHeader>
|
||||
{body}
|
||||
</DrawerContent>
|
||||
@@ -111,8 +112,10 @@ export function GitHubConnectionDialog({
|
||||
className="flex max-h-[85dvh] flex-col overflow-hidden sm:max-w-4xl"
|
||||
>
|
||||
<DialogHeader className="shrink-0">
|
||||
<DialogTitle>{connected ? "Change GitHub connection" : "Connect GitHub"}</DialogTitle>
|
||||
<DialogDescription>{description}</DialogDescription>
|
||||
<DialogTitle>
|
||||
{connected ? t("github:changeGithubConnection") : t("github:connectGithub")}
|
||||
</DialogTitle>
|
||||
<DialogDescription>{t("github:thisWorkspaceUsesOneCredentialFor")}</DialogDescription>
|
||||
</DialogHeader>
|
||||
{body}
|
||||
</DialogContent>
|
||||
|
||||
@@ -21,6 +21,8 @@ import { GitHubAuthMethodList, type GitHubAutomationMethod } from "./github-auth
|
||||
import { GitHubCLIForm } from "./github-cli-form";
|
||||
import { GitHubPATForm } from "./github-pat-form";
|
||||
import { GitHubTaskAccessForm } from "./github-task-credentials-section";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { TFunction } from "i18next";
|
||||
|
||||
function methodForStatus(status: GitHubStatus): GitHubAutomationMethod {
|
||||
if (status.automation?.source === "github_app_installation") return "app";
|
||||
@@ -28,16 +30,29 @@ function methodForStatus(status: GitHubStatus): GitHubAutomationMethod {
|
||||
return "pat";
|
||||
}
|
||||
|
||||
function errorMessage(error: unknown) {
|
||||
return error instanceof Error ? error.message : "The settings could not be saved";
|
||||
// `t` is threaded in: these are plain functions, and their messages are shown
|
||||
// to the user through the caller's toast.
|
||||
function errorMessage(t: TFunction, error: unknown) {
|
||||
return error instanceof Error ? error.message : t("github:theSettingsCouldNotBeSaved");
|
||||
}
|
||||
|
||||
// A partial save reports which change failed alongside the ones that landed.
|
||||
function saveFailureToast(t: TFunction, reason: unknown, successes: number) {
|
||||
const detail = errorMessage(t, reason);
|
||||
return {
|
||||
description: successes > 0 ? t("github:someSettingsWereSavedButAnother", { detail }) : detail,
|
||||
variant: "error" as const,
|
||||
};
|
||||
}
|
||||
|
||||
function runSaveOperations({
|
||||
t,
|
||||
workspaceId,
|
||||
connectionRequest,
|
||||
taskMode,
|
||||
saveTask,
|
||||
}: {
|
||||
t: TFunction;
|
||||
workspaceId: string;
|
||||
connectionRequest: SetGitHubConnectionRequest | null;
|
||||
taskMode: TaskGitCredentialsMode | null;
|
||||
@@ -50,7 +65,7 @@ function runSaveOperations({
|
||||
if (taskMode) {
|
||||
operations.push(
|
||||
saveTask(taskMode).then((saved) => {
|
||||
if (!saved) throw new Error("The workspace changed before task access was saved");
|
||||
if (!saved) throw new Error(t("github:theWorkspaceChangedBeforeTaskAccess"));
|
||||
}),
|
||||
);
|
||||
}
|
||||
@@ -104,6 +119,7 @@ function useConnectionSettingsDraft({
|
||||
onComplete,
|
||||
taskAccess,
|
||||
}: SettingsFormProps) {
|
||||
const { t } = useTranslation();
|
||||
const [token, setToken] = useState("");
|
||||
const [cliAccount, setCLIAccount] = useState<GitHubCLIAccount | null>(null);
|
||||
const [taskMode, setTaskMode] = useState<TaskGitCredentialsMode>(taskAccess.mode);
|
||||
@@ -148,6 +164,7 @@ function useConnectionSettingsDraft({
|
||||
const savingWorkspaceId = workspaceId;
|
||||
setSaving(true);
|
||||
const results = await runSaveOperations({
|
||||
t,
|
||||
workspaceId,
|
||||
connectionRequest,
|
||||
taskMode: taskDirty ? taskMode : null,
|
||||
@@ -162,21 +179,17 @@ function useConnectionSettingsDraft({
|
||||
if (successes > 0) onSaved();
|
||||
if (failures.length === 0) {
|
||||
setToken("");
|
||||
toast({ description: "GitHub access settings saved", variant: "success" });
|
||||
toast({ description: t("github:githubAccessSettingsSaved"), variant: "success" });
|
||||
onComplete();
|
||||
return;
|
||||
}
|
||||
const detail = errorMessage(failures[0].reason);
|
||||
toast({
|
||||
description:
|
||||
successes > 0 ? `Some settings were saved, but another change failed: ${detail}` : detail,
|
||||
variant: "error",
|
||||
});
|
||||
toast(saveFailureToast(t, failures[0].reason, successes));
|
||||
}, [
|
||||
canSave,
|
||||
connectionRequest,
|
||||
onComplete,
|
||||
onSaved,
|
||||
t,
|
||||
taskAccess,
|
||||
taskDirty,
|
||||
taskMode,
|
||||
@@ -197,6 +210,7 @@ function useConnectionSettingsDraft({
|
||||
}
|
||||
|
||||
export function GitHubConnectionSettingsForm(props: SettingsFormProps) {
|
||||
const { t } = useTranslation();
|
||||
const { method, workspaceId, onMethodChange, taskAccess, isMobile } = props;
|
||||
const {
|
||||
token,
|
||||
@@ -248,8 +262,7 @@ export function GitHubConnectionSettingsForm(props: SettingsFormProps) {
|
||||
/>
|
||||
{methodNeedsWorkflow && (
|
||||
<p className="text-xs leading-5 text-muted-foreground">
|
||||
Install a GitHub App above to change the workspace connection. Task access can be
|
||||
saved after the installation finishes.
|
||||
{t("github:installAGithubAppAboveTo")}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
@@ -275,7 +288,7 @@ export function GitHubConnectionSettingsForm(props: SettingsFormProps) {
|
||||
data-dialog-default-action
|
||||
>
|
||||
{saving && <Spinner className="mr-2 h-4 w-4" />}
|
||||
{saving ? "Saving changes…" : "Save changes"}
|
||||
{saving ? t("github:savingChanges") : t("github:saveChanges")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -5,6 +5,7 @@ import { IconEye, IconEyeOff } from "@tabler/icons-react";
|
||||
import { Button } from "@kandev/ui/button";
|
||||
import { Input } from "@kandev/ui/input";
|
||||
import { Label } from "@kandev/ui/label";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
export function GitHubPATForm({
|
||||
workspaceId,
|
||||
@@ -17,6 +18,7 @@ export function GitHubPATForm({
|
||||
onChange: (value: string) => void;
|
||||
disabled?: boolean;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [visible, setVisible] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -26,10 +28,8 @@ export function GitHubPATForm({
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="github-workspace-token">Personal access token</Label>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Kandev stores this token for this workspace. GitHub records actions as the token owner.
|
||||
</p>
|
||||
<Label htmlFor="github-workspace-token">{t("github:personalAccessToken")}</Label>
|
||||
<p className="text-xs text-muted-foreground">{t("github:kandevStoresThisTokenForThis")}</p>
|
||||
</div>
|
||||
<div className="flex flex-col gap-2 sm:flex-row sm:items-stretch">
|
||||
<div className="relative min-w-0 flex-1">
|
||||
@@ -50,7 +50,7 @@ export function GitHubPATForm({
|
||||
className="absolute right-0 top-0 h-11 w-11 cursor-pointer"
|
||||
onClick={() => setVisible((current) => !current)}
|
||||
disabled={disabled}
|
||||
aria-label={visible ? "Hide token" : "Show token"}
|
||||
aria-label={visible ? t("github:hideToken") : t("github:showToken")}
|
||||
>
|
||||
{visible ? <IconEyeOff className="h-4 w-4" /> : <IconEye className="h-4 w-4" />}
|
||||
</Button>
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
DialogTrigger,
|
||||
} from "@kandev/ui/dialog";
|
||||
import type { GitHubStatus } from "@/lib/types/github";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
type PermissionState = {
|
||||
name: string;
|
||||
@@ -37,6 +38,7 @@ function permissionStates(status: GitHubStatus): PermissionState[] {
|
||||
}
|
||||
|
||||
export function GitHubPermissionsDialog({ status }: { status: GitHubStatus }) {
|
||||
const { t } = useTranslation();
|
||||
if (status.automation?.source !== "github_app_installation") return null;
|
||||
const permissions = permissionStates(status);
|
||||
if (permissions.length === 0) return null;
|
||||
@@ -51,14 +53,14 @@ export function GitHubPermissionsDialog({ status }: { status: GitHubStatus }) {
|
||||
) : (
|
||||
<IconShieldCheck className="mr-2 h-4 w-4" />
|
||||
)}
|
||||
View permissions
|
||||
{t("github:viewPermissions")}
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="sm:max-w-lg">
|
||||
<DialogHeader>
|
||||
<DialogTitle>GitHub App permissions</DialogTitle>
|
||||
<DialogTitle>{t("github:githubAppPermissions")}</DialogTitle>
|
||||
<DialogDescription>
|
||||
Permissions available to Kandev through this workspace's GitHub App installation.
|
||||
{t("github:permissionsAvailableToKandevThroughThis")}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="max-h-[55vh] divide-y overflow-y-auto" data-testid="github-capabilities">
|
||||
@@ -77,7 +79,7 @@ export function GitHubPermissionsDialog({ status }: { status: GitHubStatus }) {
|
||||
permission.available ? "text-muted-foreground" : "font-medium text-destructive"
|
||||
}
|
||||
>
|
||||
{permission.available ? "Available" : "Missing"}
|
||||
{permission.available ? t("github:available") : t("github:missing")}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
|
||||
@@ -6,11 +6,16 @@ import { IconAlertTriangle } from "@tabler/icons-react";
|
||||
import { Alert, AlertDescription } from "@kandev/ui/alert";
|
||||
import type { GitHubRateLimitInfo, GitHubRateLimitSnapshot } from "@/lib/types/github";
|
||||
import { GitHubAccessHelp } from "./github-access-help";
|
||||
import { useTranslation } from "react-i18next";
|
||||
// Locale-aware digit grouping; `toLocaleString("en-US")` pinned it to English.
|
||||
import { formatNumber } from "@/lib/i18n/formats";
|
||||
|
||||
const RESOURCE_LABELS: Record<string, { label: string; unit: string }> = {
|
||||
core: { label: "API rate limit", unit: "requests" },
|
||||
graphql: { label: "GraphQL query limit", unit: "points" },
|
||||
search: { label: "Search limit", unit: "requests" },
|
||||
// Keyed by GitHub's rate-limit resource name, which is wire data. Catalog keys
|
||||
// rather than `t()` calls, because this is module scope (see docs/i18n.md).
|
||||
const RESOURCE_LABELS: Record<string, { labelKey: string; unitKey: string }> = {
|
||||
core: { labelKey: "github:apiRateLimit", unitKey: "github:rateLimitUnitRequests" },
|
||||
graphql: { labelKey: "github:graphqlQueryLimit", unitKey: "github:rateLimitUnitPoints" },
|
||||
search: { labelKey: "github:searchLimit", unitKey: "github:rateLimitUnitRequests" },
|
||||
};
|
||||
|
||||
// useTickNow re-renders every intervalMs and exposes a stable now-value so the
|
||||
@@ -55,6 +60,7 @@ function snapshotsFromInfo(info: GitHubRateLimitInfo): GitHubRateLimitSnapshot[]
|
||||
}
|
||||
|
||||
export function GitHubRateLimitDisplay({ info }: { info?: GitHubRateLimitInfo }) {
|
||||
const { t } = useTranslation();
|
||||
const now = useTickNow(30_000);
|
||||
if (!info) return null;
|
||||
const snapshots = snapshotsFromInfo(info);
|
||||
@@ -63,9 +69,9 @@ export function GitHubRateLimitDisplay({ info }: { info?: GitHubRateLimitInfo })
|
||||
|
||||
return (
|
||||
<GitHubAccessHelp
|
||||
label="Show GitHub API limits"
|
||||
title="GitHub API limits"
|
||||
description="Current GitHub API rate and query limits for this workspace connection."
|
||||
label={t("github:showGithubApiLimits")}
|
||||
title={t("github:githubApiLimits")}
|
||||
description={t("github:currentGithubApiRateAndQuery")}
|
||||
content={<RateLimitDetails snapshots={snapshots} exhausted={exhausted} />}
|
||||
/>
|
||||
);
|
||||
@@ -78,34 +84,44 @@ function RateLimitDetails({
|
||||
snapshots: GitHubRateLimitSnapshot[];
|
||||
exhausted: GitHubRateLimitSnapshot[];
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<div className="space-y-2" data-testid="github-rate-limit-display">
|
||||
{exhausted.length > 0 && (
|
||||
<Alert variant="destructive" data-testid="github-rate-limit-exhausted">
|
||||
<IconAlertTriangle className="h-4 w-4" />
|
||||
<AlertDescription className="text-xs">
|
||||
GitHub API access is exhausted for{" "}
|
||||
{exhausted
|
||||
.map((snapshot) => RESOURCE_LABELS[snapshot.resource]?.label ?? snapshot.resource)
|
||||
.join(", ")}
|
||||
. Background PR and issue checks are paused until the last limit resets{" "}
|
||||
{formatReset(latestReset(exhausted))}.
|
||||
{t("github:githubApiAccessIsExhaustedFor", {
|
||||
resources: exhausted
|
||||
.map((snapshot) =>
|
||||
RESOURCE_LABELS[snapshot.resource]
|
||||
? t(RESOURCE_LABELS[snapshot.resource].labelKey)
|
||||
: snapshot.resource,
|
||||
)
|
||||
.join(", "),
|
||||
reset: formatReset(latestReset(exhausted)),
|
||||
})}
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
<div className="space-y-1 text-xs text-muted-foreground">
|
||||
{snapshots.map((snapshot) => {
|
||||
const resource = RESOURCE_LABELS[snapshot.resource] ?? {
|
||||
label: snapshot.resource,
|
||||
unit: "requests",
|
||||
};
|
||||
const limit = snapshot.limit > 0 ? snapshot.limit.toLocaleString("en-US") : "unknown";
|
||||
const resource = RESOURCE_LABELS[snapshot.resource];
|
||||
// An unknown resource name is wire data, so it is shown verbatim.
|
||||
const label = resource ? t(resource.labelKey) : snapshot.resource;
|
||||
const unit = t(resource?.unitKey ?? "github:rateLimitUnitRequests");
|
||||
const limit =
|
||||
snapshot.limit > 0 ? formatNumber(snapshot.limit) : t("github:rateLimitUnknown");
|
||||
const reset = formatReset(snapshot);
|
||||
return (
|
||||
<p key={snapshot.resource} data-testid={`github-rate-limit-${snapshot.resource}`}>
|
||||
<span className="font-medium text-foreground">{resource.label}:</span>{" "}
|
||||
{snapshot.remaining.toLocaleString("en-US")} of {limit} {resource.unit} remaining
|
||||
{reset ? ` · resets ${reset}` : ""}
|
||||
<span className="font-medium text-foreground">{label}:</span>{" "}
|
||||
{t("github:rateLimitRemaining", {
|
||||
remaining: formatNumber(snapshot.remaining),
|
||||
limit,
|
||||
unit,
|
||||
})}
|
||||
{reset ? t("github:resets", { reset }) : ""}
|
||||
</p>
|
||||
);
|
||||
})}
|
||||
|
||||
@@ -29,6 +29,8 @@ import type {
|
||||
RepoFilter,
|
||||
UpdateGitHubWorkspaceSettingsRequest,
|
||||
} from "@/lib/types/github";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { t as translate } from "@/lib/i18n";
|
||||
|
||||
function splitCSV(value: string): string[] {
|
||||
return value
|
||||
@@ -51,10 +53,30 @@ function repoFiltersToInput(repos: RepoFilter[]): string {
|
||||
return repos.map((repo) => `${repo.owner}/${repo.name}`).join(", ");
|
||||
}
|
||||
|
||||
const repositoryScopeHelp =
|
||||
"Limits the GitHub pull requests and issues Kandev discovers for this workspace, including My GitHub results and review and issue watches. It does not change GitHub permissions or repository access.";
|
||||
// Only the list matching the selected mode is sent; the other stays untouched
|
||||
// server-side.
|
||||
function scopePayload({
|
||||
workspaceId,
|
||||
mode,
|
||||
orgs,
|
||||
parsedRepos,
|
||||
}: {
|
||||
workspaceId: string;
|
||||
mode: GitHubRepoScopeMode;
|
||||
orgs: string;
|
||||
parsedRepos: RepoFilter[];
|
||||
}): UpdateGitHubWorkspaceSettingsRequest {
|
||||
const payload: UpdateGitHubWorkspaceSettingsRequest = {
|
||||
workspace_id: workspaceId,
|
||||
repo_scope_mode: mode,
|
||||
};
|
||||
if (mode === "orgs") payload.repo_scope_orgs = splitCSV(orgs);
|
||||
if (mode === "repos") payload.repo_scope_repos = parsedRepos;
|
||||
return payload;
|
||||
}
|
||||
|
||||
function RepositoryScopeHelp() {
|
||||
const { t } = useTranslation();
|
||||
const usesTouchDrawer = useTouchDrawer();
|
||||
const [open, setOpen] = useState(false);
|
||||
const button = (
|
||||
@@ -65,7 +87,7 @@ function RepositoryScopeHelp() {
|
||||
className="h-11 w-11 cursor-pointer text-muted-foreground sm:h-7 sm:w-7"
|
||||
aria-haspopup="dialog"
|
||||
aria-expanded={open}
|
||||
aria-label="Explain repository scope"
|
||||
aria-label={t("github:explainRepositoryScope")}
|
||||
>
|
||||
<IconInfoCircle className="h-4 w-4" />
|
||||
</Button>
|
||||
@@ -77,7 +99,7 @@ function RepositoryScopeHelp() {
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>{drawerTrigger}</TooltipTrigger>
|
||||
<TooltipContent side="top" align="start" className="max-w-[320px] text-xs leading-relaxed">
|
||||
{repositoryScopeHelp}
|
||||
{t("github:repositoryScopeHelp")}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
);
|
||||
@@ -87,8 +109,8 @@ function RepositoryScopeHelp() {
|
||||
{trigger}
|
||||
<DrawerContent>
|
||||
<DrawerHeader>
|
||||
<DrawerTitle>Repository Scope</DrawerTitle>
|
||||
<DrawerDescription>{repositoryScopeHelp}</DrawerDescription>
|
||||
<DrawerTitle>{t("github:repositoryScope")}</DrawerTitle>
|
||||
<DrawerDescription>{t("github:repositoryScopeHelp")}</DrawerDescription>
|
||||
</DrawerHeader>
|
||||
</DrawerContent>
|
||||
</Drawer>
|
||||
@@ -118,6 +140,7 @@ function RepositoryScopeFields({
|
||||
onOrgsChange,
|
||||
onReposChange,
|
||||
}: ScopeFieldsProps) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<SettingsCard
|
||||
isDirty={mode !== baseline.mode || orgs !== baseline.orgs || repos !== baseline.repos}
|
||||
@@ -125,7 +148,7 @@ function RepositoryScopeFields({
|
||||
<CardContent className="grid gap-4 py-4 md:grid-cols-[220px_minmax(0,1fr)]">
|
||||
<div className="space-y-1.5">
|
||||
<label className="text-sm font-medium" htmlFor="github-scope-mode">
|
||||
Mode
|
||||
{t("github:mode")}
|
||||
</label>
|
||||
<Select
|
||||
value={mode}
|
||||
@@ -140,16 +163,16 @@ function RepositoryScopeFields({
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">All repositories</SelectItem>
|
||||
<SelectItem value="orgs">Organizations</SelectItem>
|
||||
<SelectItem value="repos">Selected repositories</SelectItem>
|
||||
<SelectItem value="all">{t("github:allRepositories")}</SelectItem>
|
||||
<SelectItem value="orgs">{t("github:organizations")}</SelectItem>
|
||||
<SelectItem value="repos">{t("github:selectedRepositories")}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="grid gap-3">
|
||||
<div className="space-y-1.5">
|
||||
<label className="text-sm font-medium" htmlFor="github-scope-orgs">
|
||||
Organizations
|
||||
{t("github:organizations")}
|
||||
</label>
|
||||
<Input
|
||||
id="github-scope-orgs"
|
||||
@@ -163,7 +186,7 @@ function RepositoryScopeFields({
|
||||
</div>
|
||||
<div className="space-y-1.5">
|
||||
<label className="text-sm font-medium" htmlFor="github-scope-repos">
|
||||
Repositories
|
||||
{t("github:repositories")}
|
||||
</label>
|
||||
<Input
|
||||
id="github-scope-repos"
|
||||
@@ -176,7 +199,9 @@ function RepositoryScopeFields({
|
||||
data-testid="github-scope-repos-input"
|
||||
/>
|
||||
{invalidRepos && (
|
||||
<p className="text-xs text-destructive">Use comma-separated owner/repo values.</p>
|
||||
<p className="text-xs text-destructive">
|
||||
{t("github:useCommaSeparatedOwnerRepoValues")}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
@@ -186,6 +211,7 @@ function RepositoryScopeFields({
|
||||
}
|
||||
|
||||
function useGitHubRepoScopeDraft(workspaceId: string) {
|
||||
const { t } = useTranslation();
|
||||
const { toast } = useToast();
|
||||
const [mode, setMode] = useState<GitHubRepoScopeMode>("all");
|
||||
const [orgs, setOrgs] = useState("");
|
||||
@@ -219,8 +245,15 @@ function useGitHubRepoScopeDraft(workspaceId: string) {
|
||||
setRepos(next.repos);
|
||||
})
|
||||
.catch(() => {
|
||||
// The module-level `t` resolves at call time, so this follows the active
|
||||
// locale without putting the hook's `t` in the effect deps — that would
|
||||
// refetch on every locale switch and overwrite the user's unsaved edits
|
||||
// via the setMode/setOrgs/setRepos calls above.
|
||||
if (!cancelled)
|
||||
toast({ description: "Failed to load GitHub workspace settings", variant: "error" });
|
||||
toast({
|
||||
description: translate("github:failedToLoadGithubWorkspaceSettings"),
|
||||
variant: "error",
|
||||
});
|
||||
})
|
||||
.finally(() => {
|
||||
if (!cancelled) setLoading(false);
|
||||
@@ -233,17 +266,9 @@ function useGitHubRepoScopeDraft(workspaceId: string) {
|
||||
const save = useCallback(async () => {
|
||||
const submitted = { mode, orgs, repos };
|
||||
try {
|
||||
const payload: UpdateGitHubWorkspaceSettingsRequest = {
|
||||
workspace_id: workspaceId,
|
||||
repo_scope_mode: mode,
|
||||
};
|
||||
if (mode === "orgs") {
|
||||
payload.repo_scope_orgs = splitCSV(orgs);
|
||||
}
|
||||
if (mode === "repos") {
|
||||
payload.repo_scope_repos = parsedRepos;
|
||||
}
|
||||
const updated = await updateGitHubWorkspaceSettings(payload);
|
||||
const updated = await updateGitHubWorkspaceSettings(
|
||||
scopePayload({ workspaceId, mode, orgs, parsedRepos }),
|
||||
);
|
||||
const saved = {
|
||||
mode: updated.repo_scope_mode,
|
||||
orgs: (updated.repo_scope_orgs ?? []).join(", "),
|
||||
@@ -253,12 +278,12 @@ function useGitHubRepoScopeDraft(workspaceId: string) {
|
||||
setMode((current) => (current === submitted.mode ? saved.mode : current));
|
||||
setOrgs((current) => (current === submitted.orgs ? saved.orgs : current));
|
||||
setRepos((current) => (current === submitted.repos ? saved.repos : current));
|
||||
toast({ description: "GitHub workspace settings saved", variant: "success" });
|
||||
toast({ description: t("github:githubWorkspaceSettingsSaved"), variant: "success" });
|
||||
} catch {
|
||||
toast({ description: "Failed to save GitHub workspace settings", variant: "error" });
|
||||
toast({ description: t("github:failedToSaveGithubWorkspaceSettings"), variant: "error" });
|
||||
throw new Error("Failed to save GitHub workspace settings");
|
||||
}
|
||||
}, [mode, orgs, parsedRepos, repos, toast, workspaceId]);
|
||||
}, [mode, orgs, parsedRepos, repos, t, toast, workspaceId]);
|
||||
const discard = useCallback(() => {
|
||||
setMode(baseline.mode);
|
||||
setOrgs(baseline.orgs);
|
||||
@@ -272,7 +297,7 @@ function useGitHubRepoScopeDraft(workspaceId: string) {
|
||||
revision,
|
||||
isDirty: dirty,
|
||||
canSave: !loading && !invalidRepos,
|
||||
invalidReason: invalidRepos ? "Use comma-separated owner/repo values." : undefined,
|
||||
invalidReason: invalidRepos ? t("github:useCommaSeparatedOwnerRepoValues") : undefined,
|
||||
save,
|
||||
discard,
|
||||
});
|
||||
@@ -291,13 +316,14 @@ function useGitHubRepoScopeDraft(workspaceId: string) {
|
||||
}
|
||||
|
||||
export function GitHubRepoScopeSection({ workspaceId }: { workspaceId: string }) {
|
||||
const { t } = useTranslation();
|
||||
const draft = useGitHubRepoScopeDraft(workspaceId);
|
||||
|
||||
return (
|
||||
<SettingsSection
|
||||
title="Repository Scope"
|
||||
title={t("github:repositoryScope")}
|
||||
titleAccessory={<RepositoryScopeHelp />}
|
||||
description="Limits GitHub pull requests and issues shown or imported in this workspace."
|
||||
description={t("github:limitsGithubPullRequestsAndIssues")}
|
||||
>
|
||||
<RepositoryScopeFields
|
||||
mode={draft.mode}
|
||||
|
||||
@@ -25,6 +25,7 @@ import { useWatcherEnabledDrafts } from "@/components/integrations/use-watcher-e
|
||||
import { ResetWatchDialog, useWatchResetController } from "@/components/watches/reset-watch-dialog";
|
||||
import { cleanupMergedReviewTasks, cleanupClosedIssueTasks } from "@/lib/api/domains/github-api";
|
||||
import type { ReviewWatch, IssueWatch } from "@/lib/types/github";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
// CleanupNowButton runs a manual global sweep over the dedup tables. Useful
|
||||
// for users who upgraded with a pile of legacy merged-PR / closed-issue
|
||||
@@ -37,6 +38,7 @@ function CleanupNowButton({
|
||||
label: string;
|
||||
run: () => Promise<{ deleted: number }>;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const { toast } = useToast();
|
||||
const [busy, setBusy] = useState(false);
|
||||
return (
|
||||
@@ -51,12 +53,12 @@ function CleanupNowButton({
|
||||
toast({
|
||||
description:
|
||||
deleted === 0
|
||||
? "No tasks to clean up"
|
||||
: `Deleted ${deleted} task${deleted === 1 ? "" : "s"}`,
|
||||
? t("github:noTasksToCleanUp")
|
||||
: t("github:deletedTasks", { count: deleted }),
|
||||
variant: "success",
|
||||
});
|
||||
} catch {
|
||||
toast({ description: "Cleanup failed", variant: "error" });
|
||||
toast({ description: t("github:cleanupFailed"), variant: "error" });
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
@@ -64,12 +66,13 @@ function CleanupNowButton({
|
||||
className="cursor-pointer"
|
||||
>
|
||||
<IconTrashX className="h-4 w-4 mr-1" />
|
||||
{busy ? "Cleaning…" : label}
|
||||
{busy ? t("github:cleaning") : label}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
function useWatchActions(workspaceId?: string | null) {
|
||||
const { t } = useTranslation();
|
||||
const {
|
||||
items: watches,
|
||||
create,
|
||||
@@ -85,24 +88,24 @@ function useWatchActions(workspaceId?: string | null) {
|
||||
async (id: string) => {
|
||||
const watch = watches.find((item) => item.id === id);
|
||||
if (!watch) {
|
||||
toast({ description: "Review watch not found", variant: "error" });
|
||||
toast({ description: t("github:reviewWatchNotFound"), variant: "error" });
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await remove(id, watch.workspace_id);
|
||||
toast({ description: "Review watch deleted", variant: "success" });
|
||||
toast({ description: t("github:reviewWatchDeleted"), variant: "success" });
|
||||
} catch {
|
||||
toast({ description: "Failed to delete review watch", variant: "error" });
|
||||
toast({ description: t("github:failedToDeleteReviewWatch"), variant: "error" });
|
||||
}
|
||||
},
|
||||
[remove, toast, watches],
|
||||
[remove, t, toast, watches],
|
||||
);
|
||||
|
||||
const handleTrigger = useCallback(
|
||||
async (id: string) => {
|
||||
const watch = watches.find((item) => item.id === id);
|
||||
if (!watch) {
|
||||
toast({ description: "Review watch not found", variant: "error" });
|
||||
toast({ description: t("github:reviewWatchNotFound"), variant: "error" });
|
||||
return;
|
||||
}
|
||||
try {
|
||||
@@ -110,17 +113,17 @@ function useWatchActions(workspaceId?: string | null) {
|
||||
const count = result?.new_prs_found ?? 0;
|
||||
if (count > 0) {
|
||||
toast({
|
||||
description: `Found ${count} new PR${count > 1 ? "s" : ""}`,
|
||||
description: t("github:foundNewPrs", { count }),
|
||||
variant: "success",
|
||||
});
|
||||
} else {
|
||||
toast({ description: "No new PRs found" });
|
||||
toast({ description: t("github:noNewPrsFound") });
|
||||
}
|
||||
} catch {
|
||||
toast({ description: "Failed to check for PRs", variant: "error" });
|
||||
toast({ description: t("github:failedToCheckForPrs"), variant: "error" });
|
||||
}
|
||||
},
|
||||
[trigger, toast, watches],
|
||||
[trigger, t, toast, watches],
|
||||
);
|
||||
|
||||
const handleReset = useCallback(
|
||||
@@ -130,16 +133,16 @@ function useWatchActions(workspaceId?: string | null) {
|
||||
toast({
|
||||
description:
|
||||
tasksDeleted > 0
|
||||
? `Reset complete — deleted ${tasksDeleted} task(s); next poll will re-import.`
|
||||
: "Reset complete — next poll will re-import matches.",
|
||||
? t("github:resetCompleteDeletedTasks", { count: tasksDeleted })
|
||||
: t("github:resetCompleteNextPollWillRe"),
|
||||
variant: "success",
|
||||
});
|
||||
} catch {
|
||||
toast({ description: "Failed to reset review watch", variant: "error" });
|
||||
toast({ description: t("github:failedToResetReviewWatch"), variant: "error" });
|
||||
throw new Error("reset failed");
|
||||
}
|
||||
},
|
||||
[reset, toast],
|
||||
[reset, t, toast],
|
||||
);
|
||||
|
||||
return {
|
||||
@@ -154,6 +157,7 @@ function useWatchActions(workspaceId?: string | null) {
|
||||
}
|
||||
|
||||
function useIssueWatchActions(workspaceId?: string | null) {
|
||||
const { t } = useTranslation();
|
||||
const {
|
||||
items: watches,
|
||||
create,
|
||||
@@ -169,24 +173,24 @@ function useIssueWatchActions(workspaceId?: string | null) {
|
||||
async (id: string) => {
|
||||
const watch = watches.find((item) => item.id === id);
|
||||
if (!watch) {
|
||||
toast({ description: "Issue watch not found", variant: "error" });
|
||||
toast({ description: t("github:issueWatchNotFound"), variant: "error" });
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await remove(id, watch.workspace_id);
|
||||
toast({ description: "Issue watch deleted", variant: "success" });
|
||||
toast({ description: t("github:issueWatchDeleted"), variant: "success" });
|
||||
} catch {
|
||||
toast({ description: "Failed to delete issue watch", variant: "error" });
|
||||
toast({ description: t("github:failedToDeleteIssueWatch"), variant: "error" });
|
||||
}
|
||||
},
|
||||
[remove, toast, watches],
|
||||
[remove, t, toast, watches],
|
||||
);
|
||||
|
||||
const handleTrigger = useCallback(
|
||||
async (id: string) => {
|
||||
const watch = watches.find((item) => item.id === id);
|
||||
if (!watch) {
|
||||
toast({ description: "Issue watch not found", variant: "error" });
|
||||
toast({ description: t("github:issueWatchNotFound"), variant: "error" });
|
||||
return;
|
||||
}
|
||||
try {
|
||||
@@ -194,17 +198,17 @@ function useIssueWatchActions(workspaceId?: string | null) {
|
||||
const count = result?.new_issues_found ?? 0;
|
||||
if (count > 0) {
|
||||
toast({
|
||||
description: `Found ${count} new issue${count > 1 ? "s" : ""}`,
|
||||
description: t("github:foundNewIssues", { count }),
|
||||
variant: "success",
|
||||
});
|
||||
} else {
|
||||
toast({ description: "No new issues found" });
|
||||
toast({ description: t("github:noNewIssuesFound") });
|
||||
}
|
||||
} catch {
|
||||
toast({ description: "Failed to check for issues", variant: "error" });
|
||||
toast({ description: t("github:failedToCheckForIssues"), variant: "error" });
|
||||
}
|
||||
},
|
||||
[trigger, toast, watches],
|
||||
[trigger, t, toast, watches],
|
||||
);
|
||||
|
||||
const handleReset = useCallback(
|
||||
@@ -214,16 +218,16 @@ function useIssueWatchActions(workspaceId?: string | null) {
|
||||
toast({
|
||||
description:
|
||||
tasksDeleted > 0
|
||||
? `Reset complete — deleted ${tasksDeleted} task(s); next poll will re-import.`
|
||||
: "Reset complete — next poll will re-import matches.",
|
||||
? t("github:resetCompleteDeletedTasks", { count: tasksDeleted })
|
||||
: t("github:resetCompleteNextPollWillRe"),
|
||||
variant: "success",
|
||||
});
|
||||
} catch {
|
||||
toast({ description: "Failed to reset issue watch", variant: "error" });
|
||||
toast({ description: t("github:failedToResetIssueWatch"), variant: "error" });
|
||||
throw new Error("reset failed");
|
||||
}
|
||||
},
|
||||
[reset, toast],
|
||||
[reset, t, toast],
|
||||
);
|
||||
|
||||
return {
|
||||
@@ -238,6 +242,7 @@ function useIssueWatchActions(workspaceId?: string | null) {
|
||||
}
|
||||
|
||||
export function GitHubConnectionSection({ workspaceId }: { workspaceId: string }) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<>
|
||||
<div>
|
||||
@@ -246,17 +251,17 @@ export function GitHubConnectionSection({ workspaceId }: { workspaceId: string }
|
||||
data-testid="github-integration-heading"
|
||||
>
|
||||
<IconBrandGithub className="h-6 w-6" />
|
||||
GitHub Integration
|
||||
{t("github:githubIntegration")}
|
||||
</h2>
|
||||
<p className="text-sm text-muted-foreground mt-1">
|
||||
Choose the automation and personal identities used by this workspace.
|
||||
{t("github:chooseTheAutomationAndPersonalIdentities")}
|
||||
</p>
|
||||
</div>
|
||||
<Separator />
|
||||
<GitHubCallbackNotice workspaceId={workspaceId} />
|
||||
<SettingsSection
|
||||
title="Workspace GitHub access"
|
||||
description="Credential used for repository sync, watches, and managed agent git and gh commands. Executor profile tokens take precedence."
|
||||
title={t("github:workspaceGithubAccess")}
|
||||
description={t("github:credentialUsedForRepositorySyncWatches")}
|
||||
>
|
||||
<GitHubAutomationSettings workspaceId={workspaceId} />
|
||||
</SettingsSection>
|
||||
@@ -268,6 +273,7 @@ export function GitHubConnectionSection({ workspaceId }: { workspaceId: string }
|
||||
}
|
||||
|
||||
function PerWorkspaceSection({ workspaceId }: { workspaceId: string }) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<div className="space-y-8">
|
||||
<GitHubConnectionSection workspaceId={workspaceId} />
|
||||
@@ -275,7 +281,10 @@ function PerWorkspaceSection({ workspaceId }: { workspaceId: string }) {
|
||||
<IssueWatchSection workspaceId={workspaceId} />
|
||||
<GitHubRepoScopeSection workspaceId={workspaceId} />
|
||||
<ActionPresetsSection workspaceId={workspaceId} />
|
||||
<SettingsSection title="PR Analytics" description="Pull request activity for this workspace.">
|
||||
<SettingsSection
|
||||
title={t("github:prAnalytics")}
|
||||
description={t("github:pullRequestActivityForThisWorkspace")}
|
||||
>
|
||||
<PRStatsPanel workspaceId={workspaceId} />
|
||||
</SettingsSection>
|
||||
<DefaultQueriesSection workspaceId={workspaceId} />
|
||||
@@ -300,6 +309,7 @@ export function GitHubIntegrationPage({ workspaceId }: GitHubIntegrationPageProp
|
||||
}
|
||||
|
||||
function ReviewWatchSection({ workspaceId }: { workspaceId: string }) {
|
||||
const { t } = useTranslation();
|
||||
const { watches, create, update, previewReset, handleDelete, handleTrigger, handleReset } =
|
||||
useWatchActions(workspaceId);
|
||||
const { toast } = useToast();
|
||||
@@ -338,12 +348,12 @@ function ReviewWatchSection({ workspaceId }: { workspaceId: string }) {
|
||||
return (
|
||||
<>
|
||||
<SettingsSection
|
||||
title="Review Watches"
|
||||
description="Automatically create tasks for PRs that need your review."
|
||||
title={t("github:reviewWatches")}
|
||||
description={t("github:automaticallyCreateTasksForPrsThat")}
|
||||
action={
|
||||
<div className="flex items-center gap-2">
|
||||
<CleanupNowButton
|
||||
label="Clean up merged"
|
||||
label={t("github:cleanUpMerged")}
|
||||
run={() => cleanupMergedReviewTasks(workspaceId)}
|
||||
/>
|
||||
<Button
|
||||
@@ -355,7 +365,7 @@ function ReviewWatchSection({ workspaceId }: { workspaceId: string }) {
|
||||
className="cursor-pointer"
|
||||
>
|
||||
<IconPlus className="h-4 w-4 mr-1" />
|
||||
Add Watch
|
||||
{t("github:addWatch")}
|
||||
</Button>
|
||||
</div>
|
||||
}
|
||||
@@ -380,20 +390,20 @@ function ReviewWatchSection({ workspaceId }: { workspaceId: string }) {
|
||||
workspaceId={workspaceId}
|
||||
onCreate={async (req) => {
|
||||
await create(req);
|
||||
toast({ description: "Review watch created", variant: "success" });
|
||||
toast({ description: t("github:reviewWatchCreated"), variant: "success" });
|
||||
}}
|
||||
onUpdate={async (id, req) => {
|
||||
const watch = watches.find((item) => item.id === id);
|
||||
if (!watch) throw new Error("review watch not found");
|
||||
await update(id, watch.workspace_id, req);
|
||||
toast({ description: "Review watch updated", variant: "success" });
|
||||
toast({ description: t("github:reviewWatchUpdated"), variant: "success" });
|
||||
}}
|
||||
/>
|
||||
{resetCtrl.resetting && (
|
||||
<ResetWatchDialog
|
||||
open
|
||||
onOpenChange={resetCtrl.onOpenChange}
|
||||
integrationLabel="review watch"
|
||||
integrationLabel={t("github:reviewWatch")}
|
||||
previewLoader={resetCtrl.previewLoader}
|
||||
onConfirm={resetCtrl.confirmReset}
|
||||
/>
|
||||
@@ -403,6 +413,7 @@ function ReviewWatchSection({ workspaceId }: { workspaceId: string }) {
|
||||
}
|
||||
|
||||
function IssueWatchSection({ workspaceId }: { workspaceId: string }) {
|
||||
const { t } = useTranslation();
|
||||
const issueActions = useIssueWatchActions(workspaceId);
|
||||
const { toast } = useToast();
|
||||
const [dialogOpen, setDialogOpen] = useState(false);
|
||||
@@ -440,12 +451,12 @@ function IssueWatchSection({ workspaceId }: { workspaceId: string }) {
|
||||
return (
|
||||
<>
|
||||
<SettingsSection
|
||||
title="Issue Watches"
|
||||
description="Automatically create tasks for GitHub issues matching your criteria."
|
||||
title={t("github:issueWatches")}
|
||||
description={t("github:automaticallyCreateTasksForGithubIssues")}
|
||||
action={
|
||||
<div className="flex items-center gap-2">
|
||||
<CleanupNowButton
|
||||
label="Clean up closed"
|
||||
label={t("github:cleanUpClosed")}
|
||||
run={() => cleanupClosedIssueTasks(workspaceId)}
|
||||
/>
|
||||
<Button
|
||||
@@ -457,7 +468,7 @@ function IssueWatchSection({ workspaceId }: { workspaceId: string }) {
|
||||
className="cursor-pointer"
|
||||
>
|
||||
<IconPlus className="h-4 w-4 mr-1" />
|
||||
Add Watch
|
||||
{t("github:addWatch")}
|
||||
</Button>
|
||||
</div>
|
||||
}
|
||||
@@ -482,20 +493,20 @@ function IssueWatchSection({ workspaceId }: { workspaceId: string }) {
|
||||
workspaceId={workspaceId}
|
||||
onCreate={async (req) => {
|
||||
await issueActions.create(req);
|
||||
toast({ description: "Issue watch created", variant: "success" });
|
||||
toast({ description: t("github:issueWatchCreated"), variant: "success" });
|
||||
}}
|
||||
onUpdate={async (id, req) => {
|
||||
const watch = issueActions.watches.find((item) => item.id === id);
|
||||
if (!watch) throw new Error("issue watch not found");
|
||||
await issueActions.update(id, watch.workspace_id, req);
|
||||
toast({ description: "Issue watch updated", variant: "success" });
|
||||
toast({ description: t("github:issueWatchUpdated"), variant: "success" });
|
||||
}}
|
||||
/>
|
||||
{resetCtrl.resetting && (
|
||||
<ResetWatchDialog
|
||||
open
|
||||
onOpenChange={resetCtrl.onOpenChange}
|
||||
integrationLabel="issue watch"
|
||||
integrationLabel={t("github:issueWatch")}
|
||||
previewLoader={resetCtrl.previewLoader}
|
||||
onConfirm={resetCtrl.confirmReset}
|
||||
/>
|
||||
|
||||
@@ -37,22 +37,30 @@ import { GitHubAccessHelp } from "./github-access-help";
|
||||
import { GitHubPermissionsDialog } from "./github-permissions-dialog";
|
||||
import { GitHubRateLimitDisplay } from "./github-rate-limit";
|
||||
import { GitHubTaskAccessSummary } from "./github-task-credentials-section";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { TFunction } from "i18next";
|
||||
|
||||
const sourceLabels: Record<GitHubConnectionSource, string> = {
|
||||
pat: "Personal access token",
|
||||
gh_cli: "GitHub CLI",
|
||||
github_app_installation: "GitHub App",
|
||||
legacy_shared: "Legacy shared connection",
|
||||
// Keyed by the wire enum, which is never translated; only the label is copy.
|
||||
// Catalog keys rather than `t()` calls because this is module scope — a `t()`
|
||||
// here would freeze at the boot locale (see docs/i18n.md).
|
||||
const sourceLabelKeys: Record<GitHubConnectionSource, string> = {
|
||||
pat: "github:personalAccessToken",
|
||||
gh_cli: "github:githubCli",
|
||||
github_app_installation: "github:githubApp",
|
||||
legacy_shared: "github:legacySharedConnection",
|
||||
};
|
||||
|
||||
function connectionLabel(status: GitHubStatus): string {
|
||||
// `t` is threaded in rather than imported at module level so the label follows a
|
||||
// locale switch and stays a pure function of its arguments.
|
||||
function connectionLabel(t: TFunction, status: GitHubStatus): string {
|
||||
const connection = status.automation;
|
||||
if (!connection) return "";
|
||||
// The first three are GitHub account logins — data, never translated.
|
||||
return (
|
||||
connection.actor?.login ??
|
||||
connection.login ??
|
||||
connection.installation_account_login ??
|
||||
"GitHub App"
|
||||
t("github:githubApp")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -62,12 +70,13 @@ function automationActor(status: GitHubStatus): string | null {
|
||||
}
|
||||
|
||||
function StatusLine({ status }: { status: GitHubStatus }) {
|
||||
const { t } = useTranslation();
|
||||
const connection = status.automation;
|
||||
if (!connection) {
|
||||
return (
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<IconX className="h-4 w-4 shrink-0 text-destructive" />
|
||||
<span>No automation connection</span>
|
||||
<span>{t("github:noAutomationConnection")}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -82,10 +91,12 @@ function StatusLine({ status }: { status: GitHubStatus }) {
|
||||
)}
|
||||
<span className="min-w-0 break-words font-medium">
|
||||
{actor ??
|
||||
(connection.status === "active" ? "Authentication unavailable" : connectionLabel(status))}
|
||||
(connection.status === "active"
|
||||
? t("github:authenticationUnavailable")
|
||||
: connectionLabel(t, status))}
|
||||
</span>
|
||||
<Badge variant={active ? "secondary" : "destructive"}>
|
||||
{sourceLabels[connection.source]}
|
||||
{t(sourceLabelKeys[connection.source])}
|
||||
</Badge>
|
||||
{connection.status !== "active" && <Badge variant="outline">{connection.status}</Badge>}
|
||||
<GitHubRateLimitDisplay info={status.rate_limit} />
|
||||
@@ -93,10 +104,11 @@ function StatusLine({ status }: { status: GitHubStatus }) {
|
||||
);
|
||||
}
|
||||
|
||||
async function redirectFrom(start: () => Promise<{ url?: string; URL?: string }>) {
|
||||
async function redirectFrom(t: TFunction, start: () => Promise<{ url?: string; URL?: string }>) {
|
||||
const response = await start();
|
||||
const url = response.url ?? response.URL;
|
||||
if (!url) throw new Error("GitHub did not return a redirect URL");
|
||||
// Surfaced to the user through the caller's toast, so it is copy.
|
||||
if (!url) throw new Error(t("github:githubDidNotReturnARedirectUrl"));
|
||||
window.location.assign(url);
|
||||
}
|
||||
|
||||
@@ -132,31 +144,31 @@ function AutomationActorExplanation({
|
||||
status: GitHubStatus;
|
||||
appAutomation: boolean;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const actor = status.automation?.actor?.login;
|
||||
if (!status.authenticated || !actor) return null;
|
||||
const humanIdentity = status.effective_personal_actor?.kind === "human";
|
||||
return (
|
||||
<div className="flex items-start gap-1 text-xs text-muted-foreground">
|
||||
<GitHubAccessHelp
|
||||
label="Explain workspace GitHub identity"
|
||||
title="Workspace GitHub identity"
|
||||
description="Kandev uses this workspace connection for repository sync, watches, background jobs, and managed agent GitHub commands. With a PAT or GitHub CLI account, My GitHub and actions you trigger use the same human identity."
|
||||
label={t("github:explainWorkspaceGithubIdentity")}
|
||||
title={t("github:workspaceGithubIdentity")}
|
||||
description={t("github:kandevUsesThisWorkspaceConnectionFor")}
|
||||
/>
|
||||
<div className="min-w-0 space-y-1 pt-3 sm:pt-1">
|
||||
<p>
|
||||
{appAutomation
|
||||
? `Kandev-managed operations use the GitHub App installed for ${actor}.`
|
||||
: `Kandev-managed operations act as ${actor}.`}
|
||||
? t("github:kandevManagedOperationsUseTheGithub", { actor })
|
||||
: t("github:kandevManagedOperationsActAs", { actor })}
|
||||
</p>
|
||||
{!appAutomation && humanIdentity && (
|
||||
<p>This account also powers My GitHub and user-triggered actions.</p>
|
||||
)}
|
||||
{!appAutomation && humanIdentity && <p>{t("github:thisAccountAlsoPowersMyGithub")}</p>}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function AppRegistrationDetails({ app }: { app?: GitHubAppRegistrationCatalogItem }) {
|
||||
const { t } = useTranslation();
|
||||
if (!app) return null;
|
||||
return (
|
||||
<>
|
||||
@@ -166,14 +178,13 @@ function AppRegistrationDetails({ app }: { app?: GitHubAppRegistrationCatalogIte
|
||||
{app.visibility}
|
||||
</Badge>
|
||||
<Badge variant="outline" className="capitalize">
|
||||
Webhook {app.webhook_status}
|
||||
{t("github:webhook")} {app.webhook_status}
|
||||
</Badge>
|
||||
<span>{app.source === "managed" ? "Created by Kandev" : "Imported"}</span>
|
||||
<span>{app.source === "managed" ? t("github:createdByKandev") : t("github:imported")}</span>
|
||||
</div>
|
||||
{app.shared && (
|
||||
<p className="text-xs text-amber-600 dark:text-amber-400">
|
||||
This App registration is shared by {app.workspace_binding_count} workspaces. Registration
|
||||
changes affect every workspace using it; installation access remains workspace-specific.
|
||||
{t("github:thisAppRegistrationIsShared", { count: app.workspace_binding_count })}
|
||||
</p>
|
||||
)}
|
||||
</>
|
||||
@@ -202,6 +213,7 @@ function AutomationActions({
|
||||
onRefresh: () => void;
|
||||
taskAccess: TaskGitCredentialsState;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<GitHubPermissionsDialog status={status} />
|
||||
@@ -218,7 +230,7 @@ function AutomationActions({
|
||||
disabled={refreshing}
|
||||
aria-busy={refreshing}
|
||||
className="h-11 w-11 cursor-pointer"
|
||||
aria-label="Refresh GitHub connection"
|
||||
aria-label={t("github:refreshGithubConnection")}
|
||||
>
|
||||
<IconRefresh className={`h-4 w-4 ${refreshing ? "animate-spin" : ""}`} />
|
||||
</Button>
|
||||
@@ -230,7 +242,7 @@ function AutomationActions({
|
||||
className="h-11 cursor-pointer text-destructive"
|
||||
>
|
||||
<IconTrash className="mr-2 h-4 w-4" />
|
||||
Disconnect
|
||||
{t("github:disconnect")}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
@@ -238,6 +250,7 @@ function AutomationActions({
|
||||
}
|
||||
|
||||
export function GitHubAutomationSettings({ workspaceId }: { workspaceId: string }) {
|
||||
const { t } = useTranslation();
|
||||
const { status, loaded, loading, refresh } = useGitHubStatus(workspaceId);
|
||||
const appRegistrations = useGitHubAppRegistrations(workspaceId);
|
||||
const taskAccess = useTaskGitCredentials(workspaceId);
|
||||
@@ -247,11 +260,11 @@ export function GitHubAutomationSettings({ workspaceId }: { workspaceId: string
|
||||
setBusy(true);
|
||||
try {
|
||||
await disconnectGitHubWorkspace(workspaceId);
|
||||
toast({ description: "Workspace GitHub connection removed", variant: "success" });
|
||||
toast({ description: t("github:workspaceGithubConnectionRemoved"), variant: "success" });
|
||||
refresh();
|
||||
} catch (error) {
|
||||
toast({
|
||||
description: error instanceof Error ? error.message : "Disconnect failed",
|
||||
description: error instanceof Error ? error.message : t("github:disconnectFailed"),
|
||||
variant: "error",
|
||||
});
|
||||
} finally {
|
||||
@@ -299,6 +312,7 @@ function personalIdentityView(status: GitHubStatus): PersonalIdentityView {
|
||||
}
|
||||
|
||||
function PersonalIdentityStatus({ view }: { view: PersonalIdentityView }) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<div className="flex min-w-0 flex-wrap items-center gap-2 text-sm">
|
||||
{view.active ? (
|
||||
@@ -307,7 +321,7 @@ function PersonalIdentityStatus({ view }: { view: PersonalIdentityView }) {
|
||||
<IconX className="h-4 w-4 text-destructive" />
|
||||
)}
|
||||
<span className="break-words font-medium">{view.actor}</span>
|
||||
{view.personalActive && <Badge variant="secondary">Personal OAuth</Badge>}
|
||||
{view.personalActive && <Badge variant="secondary">{t("github:personalOauth")}</Badge>}
|
||||
{view.status && view.status !== "active" && (
|
||||
<Badge variant="destructive">{view.status}</Badge>
|
||||
)}
|
||||
@@ -326,12 +340,13 @@ function PersonalIdentityActions({
|
||||
onConnect: () => void;
|
||||
onDisconnect: () => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<div className="flex flex-col gap-2 sm:flex-row">
|
||||
{status.app_available && status.automation?.source === "github_app_installation" && (
|
||||
<Button disabled={busy} onClick={onConnect} className="h-11 cursor-pointer">
|
||||
<IconBrandGithub className="mr-2 h-4 w-4" />
|
||||
{status.personal ? "Reconnect identity" : "Connect identity"}
|
||||
{status.personal ? t("github:reconnectIdentity") : t("github:connectIdentity")}
|
||||
<IconExternalLink className="ml-2 h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
@@ -343,7 +358,7 @@ function PersonalIdentityActions({
|
||||
className="h-11 cursor-pointer text-destructive"
|
||||
>
|
||||
<IconTrash className="mr-2 h-4 w-4" />
|
||||
Disconnect
|
||||
{t("github:disconnect")}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
@@ -351,6 +366,7 @@ function PersonalIdentityActions({
|
||||
}
|
||||
|
||||
export function GitHubPersonalSettings({ workspaceId }: { workspaceId: string }) {
|
||||
const { t } = useTranslation();
|
||||
const { status, loaded, refresh } = useGitHubStatus(workspaceId);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const { toast } = useToast();
|
||||
@@ -363,11 +379,11 @@ export function GitHubPersonalSettings({ workspaceId }: { workspaceId: string })
|
||||
setBusy(true);
|
||||
try {
|
||||
await disconnectGitHubPersonal(workspaceId);
|
||||
toast({ description: "Personal GitHub identity disconnected", variant: "success" });
|
||||
toast({ description: t("github:personalGithubIdentityDisconnected"), variant: "success" });
|
||||
refresh();
|
||||
} catch (error) {
|
||||
toast({
|
||||
description: error instanceof Error ? error.message : "Disconnect failed",
|
||||
description: error instanceof Error ? error.message : t("github:disconnectFailed"),
|
||||
variant: "error",
|
||||
});
|
||||
} finally {
|
||||
@@ -375,17 +391,17 @@ export function GitHubPersonalSettings({ workspaceId }: { workspaceId: string })
|
||||
}
|
||||
};
|
||||
const connect = () => {
|
||||
void redirectFrom(() => startGitHubPersonalConnect(workspaceId)).catch((error: unknown) =>
|
||||
void redirectFrom(t, () => startGitHubPersonalConnect(workspaceId)).catch((error: unknown) =>
|
||||
toast({
|
||||
description: errorMessage(error, "Identity connection failed"),
|
||||
description: errorMessage(error, t("github:identityConnectionFailed")),
|
||||
variant: "error",
|
||||
}),
|
||||
);
|
||||
};
|
||||
return (
|
||||
<SettingsSection
|
||||
title="My GitHub identity"
|
||||
description="Optionally connect your GitHub user for My GitHub and human-attributed actions. This identity is never given to managed agents; workspace automation continues as the App."
|
||||
title={t("github:myGithubIdentity")}
|
||||
description={t("github:optionallyConnectYourGithubUserFor")}
|
||||
>
|
||||
<div className="space-y-4" data-testid="github-personal-identity">
|
||||
<PersonalIdentityStatus view={view} />
|
||||
@@ -404,10 +420,11 @@ export function GitHubPersonalSettings({ workspaceId }: { workspaceId: string })
|
||||
}
|
||||
|
||||
function LoadingStatus() {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<div className="flex min-h-11 items-center gap-2 text-sm text-muted-foreground">
|
||||
<Spinner className="h-4 w-4" />
|
||||
Checking GitHub connection...
|
||||
{t("github:checkingGithubConnection")}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,10 +4,13 @@ import { RadioGroup, RadioGroupItem } from "@kandev/ui/radio-group";
|
||||
import type { TaskGitCredentialsState } from "@/hooks/domains/github/use-task-git-credentials";
|
||||
import type { TaskGitCredentialsMode } from "@/lib/types/github";
|
||||
import { GitHubAccessHelp } from "./github-access-help";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
const taskAccessLabels: Record<TaskGitCredentialsMode, string> = {
|
||||
managed: "Managed workspace credentials",
|
||||
executor: "Inherit executor Git credentials",
|
||||
// Keyed by the wire mode, which is never translated. Catalog keys rather than
|
||||
// `t()` calls, because this is module scope (see docs/i18n.md).
|
||||
const taskAccessLabelKeys: Record<TaskGitCredentialsMode, string> = {
|
||||
managed: "github:managedWorkspaceCredentials",
|
||||
executor: "github:inheritExecutorGitCredentials",
|
||||
};
|
||||
|
||||
export function GitHubTaskAccessSummary({
|
||||
@@ -15,21 +18,22 @@ export function GitHubTaskAccessSummary({
|
||||
loading,
|
||||
error,
|
||||
}: Omit<TaskGitCredentialsState, "save">) {
|
||||
let value = taskAccessLabels[mode];
|
||||
if (loading) value = "Loading task access…";
|
||||
if (error) value = "Task access unavailable";
|
||||
const { t } = useTranslation();
|
||||
let value = t(taskAccessLabelKeys[mode]);
|
||||
if (loading) value = t("github:loadingTaskAccess");
|
||||
if (error) value = t("github:taskAccessUnavailable");
|
||||
return (
|
||||
<div
|
||||
className="flex items-center gap-1 text-xs text-muted-foreground"
|
||||
data-testid="github-task-access-summary"
|
||||
>
|
||||
<GitHubAccessHelp
|
||||
label="Explain task Git access"
|
||||
title="Task Git access"
|
||||
description="Controls how newly launched tasks authenticate to GitHub for Git HTTPS and gh commands. Managed workspace credentials use Kandev's workspace connection; executor credentials use the selected executor's Git or SSH setup."
|
||||
label={t("github:explainTaskGitAccess")}
|
||||
title={t("github:taskGitAccess")}
|
||||
description={t("github:controlsHowNewlyLaunchedTasksAuthenticate")}
|
||||
/>
|
||||
<span>
|
||||
<span className="font-medium text-foreground">Task access: </span>
|
||||
<span className="font-medium text-foreground">{t("github:taskAccess")} </span>
|
||||
{value}
|
||||
</span>
|
||||
</div>
|
||||
@@ -47,20 +51,20 @@ export function GitHubTaskAccessForm({
|
||||
onChange: (value: TaskGitCredentialsMode) => void;
|
||||
disabled?: boolean;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<section className="space-y-4 border-t pt-5" data-testid="github-task-access-settings">
|
||||
<div className="space-y-1">
|
||||
<div className="flex items-center gap-1">
|
||||
<h3 className="text-sm font-medium">Task Git access</h3>
|
||||
<h3 className="text-sm font-medium">{t("github:taskGitAccess")}</h3>
|
||||
<GitHubAccessHelp
|
||||
label="Explain how managed task credentials work"
|
||||
title="How managed task credentials work"
|
||||
description="With Managed workspace credentials, Kandev configures agentctl as Git's credential helper inside newly launched task processes. When Git requests credentials for an attached GitHub HTTPS repository, the helper redeems a task- and repository-scoped broker lease. The credential is returned to Git on demand and is not written to the repository or Git config. The gh command uses Kandev's broker-aware shim. Executor inheritance skips both and uses credentials visible in the selected executor. Changes apply to new task launches and the next resume, not already-running processes."
|
||||
label={t("github:explainHowManagedTaskCredentialsWork")}
|
||||
title={t("github:howManagedTaskCredentialsWork")}
|
||||
description={t("github:withManagedWorkspaceCredentialsKandevConfigures")}
|
||||
/>
|
||||
</div>
|
||||
<p className="text-xs leading-5 text-muted-foreground">
|
||||
Choose how newly launched tasks authenticate to GitHub. This does not change the workspace
|
||||
automation connection above.
|
||||
{t("github:chooseHowNewlyLaunchedTasksAuthenticate")}
|
||||
</p>
|
||||
</div>
|
||||
<RadioGroup
|
||||
@@ -75,10 +79,9 @@ export function GitHubTaskAccessForm({
|
||||
>
|
||||
<RadioGroupItem value="managed" className="mt-0.5" />
|
||||
<span>
|
||||
<span className="font-medium">Managed workspace credentials</span>
|
||||
<span className="font-medium">{t("github:managedWorkspaceCredentials")}</span>
|
||||
<span className="mt-1 block text-xs leading-5 text-muted-foreground">
|
||||
Kandev brokers the workspace PAT, named GitHub CLI account, or App identity to this
|
||||
task for GitHub HTTPS and gh.
|
||||
{t("github:kandevBrokersTheWorkspacePatNamed")}
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
@@ -88,20 +91,23 @@ export function GitHubTaskAccessForm({
|
||||
>
|
||||
<RadioGroupItem value="executor" className="mt-0.5" />
|
||||
<span>
|
||||
<span className="font-medium">Inherit executor Git credentials</span>
|
||||
<span className="font-medium">{t("github:inheritExecutorGitCredentials")}</span>
|
||||
<span className="mt-1 block text-xs leading-5 text-muted-foreground">
|
||||
Local and Worktree tasks use host-visible Git or SSH credentials. Docker, SSH, and
|
||||
cloud tasks use credentials configured in that executor.
|
||||
{t("github:localAndWorktreeTasksUseHost")}
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
</RadioGroup>
|
||||
<p className="text-xs leading-5 text-muted-foreground">
|
||||
An executor-profile GH_TOKEN or GITHUB_TOKEN overrides managed workspace credentials for
|
||||
that task.
|
||||
{/* Env var names are identifiers the user must type exactly, so they are
|
||||
interpolated rather than left for the pseudo-locale to mangle. */}
|
||||
{t("github:anExecutorProfileGhTokenOr", {
|
||||
ghToken: "GH_TOKEN",
|
||||
githubToken: "GITHUB_TOKEN",
|
||||
})}
|
||||
</p>
|
||||
{taskAccess.error && (
|
||||
<p className="text-sm text-destructive">Unable to load the current task access setting.</p>
|
||||
<p className="text-sm text-destructive">{t("github:unableToLoadTheCurrentTask")}</p>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
|
||||
@@ -12,6 +12,7 @@ import { Card, CardContent } from "@kandev/ui/card";
|
||||
import { Spinner } from "@kandev/ui/spinner";
|
||||
import { fetchGitHubStats } from "@/lib/api/domains/github-api";
|
||||
import type { PRStats } from "@/lib/types/github";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
type StatCardProps = {
|
||||
icon: React.ReactNode;
|
||||
@@ -82,36 +83,37 @@ function usePRStats(workspaceId: string | null) {
|
||||
}
|
||||
|
||||
function StatsGrid({ stats }: { stats: PRStats }) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<div className="grid grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
<StatCard
|
||||
icon={<IconGitPullRequest className="h-5 w-5" />}
|
||||
label="PRs Created"
|
||||
label={t("github:prsCreated")}
|
||||
value={stats.total_prs_created}
|
||||
/>
|
||||
<StatCard
|
||||
icon={<IconEye className="h-5 w-5" />}
|
||||
label="PRs Reviewed"
|
||||
label={t("github:prsReviewed")}
|
||||
value={stats.total_prs_reviewed}
|
||||
/>
|
||||
<StatCard
|
||||
icon={<IconMessage className="h-5 w-5" />}
|
||||
label="Comments"
|
||||
label={t("github:comments")}
|
||||
value={stats.total_comments}
|
||||
/>
|
||||
<StatCard
|
||||
icon={<IconCheck className="h-5 w-5" />}
|
||||
label="CI Pass Rate"
|
||||
label={t("github:ciPassRate")}
|
||||
value={formatPercent(stats.ci_pass_rate)}
|
||||
/>
|
||||
<StatCard
|
||||
icon={<IconCheck className="h-5 w-5" />}
|
||||
label="Approval Rate"
|
||||
label={t("github:approvalRate")}
|
||||
value={formatPercent(stats.approval_rate)}
|
||||
/>
|
||||
<StatCard
|
||||
icon={<IconClock className="h-5 w-5" />}
|
||||
label="Avg Time to Merge"
|
||||
label={t("github:avgTimeToMerge")}
|
||||
value={formatHours(stats.avg_time_to_merge_hours)}
|
||||
/>
|
||||
</div>
|
||||
@@ -119,12 +121,13 @@ function StatsGrid({ stats }: { stats: PRStats }) {
|
||||
}
|
||||
|
||||
function PRsByDayChart({ prsByDay }: { prsByDay: PRStats["prs_by_day"] }) {
|
||||
const { t } = useTranslation();
|
||||
if (!prsByDay || prsByDay.length === 0) return null;
|
||||
const maxCount = Math.max(...prsByDay.map((d) => d.count), 1);
|
||||
return (
|
||||
<Card>
|
||||
<CardContent className="p-4">
|
||||
<h4 className="text-sm font-medium mb-3">PRs by Day</h4>
|
||||
<h4 className="text-sm font-medium mb-3">{t("github:prsByDay")}</h4>
|
||||
<div className="flex items-end gap-1 h-24">
|
||||
{prsByDay.map((day) => {
|
||||
const height = Math.max((day.count / maxCount) * 100, 4);
|
||||
@@ -133,7 +136,7 @@ function PRsByDayChart({ prsByDay }: { prsByDay: PRStats["prs_by_day"] }) {
|
||||
key={day.date}
|
||||
className="flex-1 bg-primary/20 hover:bg-primary/40 rounded-t transition-colors"
|
||||
style={{ height: `${height}%` }}
|
||||
title={`${day.date}: ${day.count} PRs`}
|
||||
title={t("github:prsOnDay", { date: day.date, count: day.count })}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
@@ -150,6 +153,7 @@ function PRsByDayChart({ prsByDay }: { prsByDay: PRStats["prs_by_day"] }) {
|
||||
}
|
||||
|
||||
export function PRStatsPanel({ workspaceId }: { workspaceId: string | null }) {
|
||||
const { t } = useTranslation();
|
||||
const { stats, loading } = usePRStats(workspaceId);
|
||||
|
||||
if (loading) {
|
||||
@@ -162,7 +166,9 @@ export function PRStatsPanel({ workspaceId }: { workspaceId: string | null }) {
|
||||
|
||||
if (!stats) {
|
||||
return (
|
||||
<p className="text-sm text-muted-foreground text-center py-4">No stats available yet.</p>
|
||||
<p className="text-sm text-muted-foreground text-center py-4">
|
||||
{t("github:noStatsAvailableYet")}
|
||||
</p>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user