@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

main
ts 47 lines 1.8 KB
Raw
1 import type {
2 EnvironmentId,
3 SourceControlAppAccess,
4 SourceControlAppAccessInput,
5 } from "@t3tools/contracts";
6 import { appSignInTargetForRemote } from "@t3tools/client-runtime/source-control-clients";
7 import type { AtomCommandResult } from "@t3tools/client-runtime/state/runtime";
8 import { msg } from "gt-react-native";
9 import { tryOpenExternalUrl } from "../../lib/openExternalUrl";
10
11 import * as Dialog from "../../components/ui/Dialog";
12 import { m } from "../../i18n/messages";
13
14 /**
15 * After a clone, suggests installing the forge app on the repository's owner when the server is
16 * signed in with it but the app does not reach the repository.
17 */
18 export async function suggestAppAccessForRemote(
19 check: (value: {
20 readonly environmentId: EnvironmentId;
21 readonly input: SourceControlAppAccessInput;
22 }) => Promise<AtomCommandResult<SourceControlAppAccess, unknown>>,
23 environmentId: EnvironmentId,
24 remoteUrl: string,
25 ): Promise<void> {
26 const target = appSignInTargetForRemote(remoteUrl);
27 if (target === null) return;
28 const result = await check({ environmentId, input: target.input });
29 if (result._tag !== "Success" || result.value.status !== "not-covered") return;
30 const owner = target.input.repository.split("/")[0] ?? target.input.repository;
31 Dialog.alert(
32 m(msg("Give {app} access to {owner}", { app: target.appSignIn.appName, owner })),
33 m(
34 msg(
35 "It isn't installed there, so GitHub requests for {repository} use your own login and its lower rate limit.",
36 { repository: target.input.repository },
37 ),
38 ),
39 [
40 { text: m(msg("Not now")), style: "cancel" },
41 {
42 text: m(msg("Install", { $context: "verb, installs the GitHub app" })),
43 onPress: () => void tryOpenExternalUrl(target.appSignIn.installUrl, "provider-auth"),
44 },
45 ],
46 );
47 }