Skip to content
Source
Sign inSign up

pullRequestLink.ts

22 lines862 Bytes

1import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
2import { Platform, Share } from "react-native";
3import { copyTextWithHaptic } from "../../lib/copyTextWithHaptic";
4​
5interface PullRequestLink {
6 readonly url: string;
7 readonly title: string;
8 readonly provider: string;
9}
10​
11export function copyPullRequestLink(pr: PullRequestLink) {
12 copyTextWithHaptic(pr.url, {
13 target: `${sourceControlClients.get(pr.provider).changeRequest.singular} link`,
14 });
16​
17export function sharePullRequestLink(pr: PullRequestLink) {
18 // Android ignores `url`; iOS turns a `message` URL into plain text instead of a link preview.
19 Share.share(
20 Platform.OS === "ios" ? { url: pr.url, title: pr.title } : { message: pr.url, title: pr.title },
21 ).catch((cause: unknown) => console.error("Failed to share pull request link.", cause));