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