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