Skip to content

Commit db6e053

Browse files
authored
feat(github): route pull request operations across matching accounts (pingdotgg#11367)
1 parent 8b3ddf5 commit db6e053

36 files changed

Lines changed: 3297 additions & 147 deletions

‎apps/mobile/src/connection/storage.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
ConnectionTransientError,
1515
CredentialStore,
1616
ProfileStore,
17+
GitHubRoutingPermissions,
18+
makeGitHubRoutingPermissions,
1719
} from "@t3tools/client-runtime/connection";
1820
import * as Context from "effect/Context";
1921
import * as Effect from "effect/Effect";
@@ -39,6 +41,11 @@ function targetPersistenceError(
3941
export const connectionStorageLayer = Layer.effectContext(
4042
Effect.gen(function* () {
4143
const catalog = yield* CatalogStore.make();
44+
const githubRoutingPermissions = yield* makeGitHubRoutingPermissions({
45+
read: catalog.read.pipe(Effect.map((document) => document.githubRoutingPermissions ?? [])),
46+
write: (githubRoutingPermissions) =>
47+
catalog.update((document) => ({ ...document, githubRoutingPermissions })),
48+
});
4249

4350
const targetStore = ConnectionTargetStore.of({
4451
list: catalog.read.pipe(
@@ -138,6 +145,7 @@ export const connectionStorageLayer = Layer.effectContext(
138145
})),
139146
});
140147
return Context.make(ConnectionTargetStore, targetStore).pipe(
148+
Context.add(GitHubRoutingPermissions, githubRoutingPermissions),
141149
Context.add(ConnectionRegistrationStore, registrationStore),
142150
Context.add(ProfileStore.ConnectionProfileStore, profileStore),
143151
Context.add(CredentialStore.ConnectionCredentialStore, credentialStore),

‎apps/mobile/src/features/connection/ConnectionsRouteScreen.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { AppText as Text } from "../../components/AppText";
1111
import { cn } from "../../lib/cn";
1212
import { useRemoteConnections } from "../../state/use-remote-environment-registry";
1313
import { ConnectionEnvironmentRow } from "./ConnectionEnvironmentRow";
14+
import { GitHubRoutingSettings } from "./GitHubRoutingSettings";
1415

1516
export function ConnectionsRouteScreen() {
1617
const {
@@ -97,6 +98,7 @@ export function ConnectionsRouteScreen() {
9798
</Text>
9899
</View>
99100
)}
101+
<GitHubRoutingSettings />
100102
</ScrollView>
101103
</View>
102104
);
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import { useAtomValue } from "@effect/atom-react";
2+
import {
3+
connectionCatalogDisplayUrl,
4+
gitHubRoutingConnectionKey,
5+
gitHubRoutingPermissionFor,
6+
type GitHubRoutingPermission,
7+
} from "@t3tools/client-runtime/connection";
8+
import { useState } from "react";
9+
import { Alert, Pressable, View } from "react-native";
10+
11+
import { AppText as Text } from "../../components/AppText";
12+
import { SymbolView } from "../../components/AppSymbol";
13+
import { environmentCatalog } from "../../connection/catalog";
14+
import { useAtomCommand } from "../../state/use-atom-command";
15+
import { SettingsSection } from "../settings/components/SettingsSection";
16+
17+
const options: ReadonlyArray<{
18+
value: GitHubRoutingPermission;
19+
label: string;
20+
description: string;
21+
}> = [
22+
{ value: "off", label: "Off", description: "Keep GitHub requests on this environment." },
23+
{
24+
value: "read",
25+
label: "Read PRs",
26+
description: "Share PR data with other enabled environments.",
27+
},
28+
{
29+
value: "read-write",
30+
label: "Read and act",
31+
description: "Actions may use broader GitHub permissions than the original environment.",
32+
},
33+
];
34+
35+
export function GitHubRoutingSettings() {
36+
const catalog = useAtomValue(environmentCatalog.catalogValueAtom);
37+
const permissions = useAtomValue(environmentCatalog.githubRoutingPermissionsValueAtom);
38+
const update = useAtomCommand(environmentCatalog.setGitHubRoutingPermission);
39+
const [expanded, setExpanded] = useState<string | null>(null);
40+
const [saving, setSaving] = useState(false);
41+
if (catalog.entries.size === 0) return null;
42+
43+
return (
44+
<View className="mt-5 gap-3">
45+
<SettingsSection title="GitHub routing">
46+
{[...catalog.entries.values()].map((entry, index) => {
47+
const environmentId = entry.target.environmentId;
48+
const selected = gitHubRoutingPermissionFor(entry, permissions);
49+
const disabled = !catalog.isReady || saving || gitHubRoutingConnectionKey(entry) === null;
50+
return (
51+
<View
52+
key={environmentId}
53+
className={index === 0 ? undefined : "border-t border-border-subtle"}
54+
>
55+
<Pressable
56+
accessibilityRole="button"
57+
accessibilityLabel={`${entry.target.label} GitHub routing`}
58+
accessibilityState={{ expanded: expanded === environmentId }}
59+
className="flex-row items-center gap-3 p-4"
60+
onPress={() => setExpanded(expanded === environmentId ? null : environmentId)}
61+
>
62+
<View className="min-w-0 flex-1 gap-0.5">
63+
<Text className="text-base font-t3-bold text-foreground">
64+
{entry.target.label}
65+
</Text>
66+
<Text className="text-xs text-foreground-muted" numberOfLines={1}>
67+
{connectionCatalogDisplayUrl(entry) ?? "T3 Connect"}
68+
</Text>
69+
</View>
70+
<Text className="text-sm text-foreground-muted">
71+
{options.find((option) => option.value === selected)?.label}
72+
</Text>
73+
<SymbolView
74+
name={expanded === environmentId ? "chevron.up" : "chevron.down"}
75+
size={12}
76+
tintColorClassName="accent-icon-muted"
77+
/>
78+
</Pressable>
79+
{expanded === environmentId
80+
? options.map((option) => (
81+
<Pressable
82+
key={option.value}
83+
accessibilityRole="radio"
84+
accessibilityState={{ checked: selected === option.value, disabled }}
85+
disabled={disabled}
86+
className="flex-row items-center gap-4 border-t border-border-subtle p-4 disabled:opacity-50"
87+
onPress={() => {
88+
setSaving(true);
89+
void update({ environmentId, permission: option.value }).then((result) => {
90+
setSaving(false);
91+
if (result._tag === "Failure")
92+
Alert.alert(
93+
"Could not save GitHub routing permission",
94+
"Try again before leaving this screen.",
95+
);
96+
});
97+
}}
98+
>
99+
<View className="min-w-0 flex-1 gap-1">
100+
<Text className="text-base text-foreground">{option.label}</Text>
101+
<Text className="text-sm leading-normal text-foreground-muted">
102+
{option.description}
103+
</Text>
104+
</View>
105+
{selected === option.value ? (
106+
<SymbolView
107+
name="checkmark"
108+
size={18}
109+
tintColorClassName="accent-icon"
110+
weight="semibold"
111+
/>
112+
) : null}
113+
</Pressable>
114+
))
115+
: null}
116+
</View>
117+
);
118+
})}
119+
</SettingsSection>
120+
<Text className="px-2 text-sm text-foreground-muted">
121+
Choose environments you trust to share PR data and use each other's GitHub access. Enable
122+
both environments. This applies only to this client.
123+
</Text>
124+
</View>
125+
);
126+
}

‎apps/mobile/src/features/settings/SettingsEnvironmentsRouteScreen.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { AppText as Text } from "../../components/AppText";
1010
import { AndroidScreenHeader } from "../../components/AndroidScreenHeader";
1111
import { CloudEnvironmentRows } from "../connection/CloudEnvironmentRows";
1212
import { ConnectionEnvironmentRow } from "../connection/ConnectionEnvironmentRow";
13+
import { GitHubRoutingSettings } from "../connection/GitHubRoutingSettings";
1314
import { splitEnvironmentSections } from "../connection/environmentSections";
1415
import { cn } from "../../lib/cn";
1516
import { useUniwindTheme } from "../../lib/useUniwindTheme";
@@ -174,6 +175,7 @@ export function SettingsEnvironmentsRouteScreen() {
174175
}
175176
: {})}
176177
/>
178+
<GitHubRoutingSettings />
177179
</ScrollView>
178180
</View>
179181
);

‎apps/server/src/auth/RpcAuthorization.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ export const RPC_REQUIRED_SCOPES = {
6868
[WS_METHODS.pullRequestsList]: AuthOrchestrationReadScope,
6969
[WS_METHODS.pullRequestsListStats]: AuthOrchestrationReadScope,
7070
[WS_METHODS.pullRequestsSummary]: AuthOrchestrationReadScope,
71+
[WS_METHODS.pullRequestsRouting]: AuthOrchestrationReadScope,
72+
[WS_METHODS.pullRequestsRoutingIdentity]: AuthOrchestrationReadScope,
7173
[WS_METHODS.pullRequestsStack]: AuthOrchestrationReadScope,
7274
[WS_METHODS.pullRequestsLinkedThreads]: AuthOrchestrationReadScope,
7375
[WS_METHODS.pullRequestsDetail]: AuthOrchestrationReadScope,

0 commit comments

Comments
 (0)