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

sourceControlAppAccessToast.ts

46 lines1.8 KB

1import type { EnvironmentId } from "@t3tools/contracts";
2import { appSignInTargetForRemote } from "@t3tools/client-runtime/source-control-clients";
3import { runAtomCommand } from "@t3tools/client-runtime/state/runtime";
4import { msg } from "gt-react";
5​
6import { m } from "../i18n/messages";
7import { appAtomRegistry } from "../rpc/atomRegistry";
8import { sourceControlEnvironment } from "../state/sourceControl";
9import { 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 */
15export 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 });