The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import type { EnvironmentId } from "@t3tools/contracts"; |
| 2 | import { appSignInTargetForRemote } from "@t3tools/client-runtime/source-control-clients"; |
| 3 | import { runAtomCommand } from "@t3tools/client-runtime/state/runtime"; |
| 4 | import { msg } from "gt-react"; |
| 5 | |
| 6 | import { m } from "../i18n/messages"; |
| 7 | import { appAtomRegistry } from "../rpc/atomRegistry"; |
| 8 | import { sourceControlEnvironment } from "../state/sourceControl"; |
| 9 | import { toastManager } from "./ui/toast"; |
| 10 | |
| 11 | /** |
| 12 | * After a clone, suggests installing the forge app on the repository's owner when the server is |
| 13 | * signed in with it but the app does not reach the repository. |
| 14 | */ |
| 15 | export async function suggestAppAccessForRemote( |
| 16 | environmentId: EnvironmentId, |
| 17 | remoteUrl: string, |
| 18 | ): Promise<void> { |
| 19 | const target = appSignInTargetForRemote(remoteUrl); |
| 20 | if (target === null) return; |
| 21 | const result = await runAtomCommand( |
| 22 | appAtomRegistry, |
| 23 | sourceControlEnvironment.checkAppAccess, |
| 24 | { environmentId, input: target.input }, |
| 25 | { label: "check app access", reportFailure: false, reportDefect: false }, |
| 26 | ); |
| 27 | if (result._tag !== "Success" || result.value.status !== "not-covered") return; |
| 28 | const owner = target.input.repository.split("/")[0] ?? target.input.repository; |
| 29 | const id = toastManager.add({ |
| 30 | type: "info", |
| 31 | title: m(msg("Give {appName} access to {owner}", { appName: target.appSignIn.appName, owner })), |
| 32 | description: m( |
| 33 | msg( |
| 34 | "It isn't installed there, so GitHub requests for {repository} use your own login and its lower rate limit.", |
| 35 | { repository: target.input.repository }, |
| 36 | ), |
| 37 | ), |
| 38 | actionProps: { |
| 39 | children: m(msg("Install")), |
| 40 | onClick: () => { |
| 41 | toastManager.close(id); |
| 42 | window.open(target.appSignIn.installUrl, "_blank", "noopener,noreferrer"); |
| 43 | }, |
| 44 | }, |
| 45 | }); |
| 46 | } |