Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

suggestAppAccess.ts

44 lines1.8 KB

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 { msg } from "gt-react-native";
9import { tryOpenExternalUrl } from "../../lib/openExternalUrl";
10​
11import * as Dialog from "../../components/ui/Dialog";
12import { 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 */
18export 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: target.appSignIn.appName }} access to ${{ owner }}`),
33 m(
34 msg`It isn't installed there, so GitHub requests for ${{ repository: target.input.repository }} use your own login and its lower rate limit.`,
35 ),
36 [
37 { text: m(msg("Not now")), style: "cancel" },
38 {
39 text: m(msg({ context: "verb, installs the GitHub app" })`Install`),
40 onPress: () => void tryOpenExternalUrl(target.appSignIn.installUrl, "provider-auth"),
41 },
42 ],
43 );