Skip to content

Commit dd3b029

Browse files
Merge remote-tracking branch 'origin/main' into fix/issue-26674
2 parents f7c3dc1 + e34067e commit dd3b029

25 files changed

Lines changed: 639 additions & 23 deletions

‎apps/mobile/src/components/ui/AndroidScreenHeader.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface AndroidHeaderAction {
2121
readonly disabled?: boolean;
2222
readonly loading?: boolean;
2323
readonly selected?: boolean;
24+
readonly subtitle?: string;
2425
readonly destructive?: boolean;
2526
readonly overflowOnly?: boolean;
2627
}
@@ -178,10 +179,11 @@ export function AndroidScreenHeader(props: {
178179
actions={overflowActions.map((action, index) => ({
179180
id: String(index),
180181
title: action.accessibilityLabel,
182+
subtitle: action.subtitle,
183+
state: action.selected ? "on" : undefined,
181184
attributes: {
182185
disabled: Boolean(action.disabled),
183186
destructive: action.destructive,
184-
state: action.selected ? "on" : undefined,
185187
},
186188
}))}
187189
onPressAction={({ nativeEvent }) =>

‎apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ import {
111111
PullRequestReadStatus,
112112
} from "./PullRequestPresentation";
113113
import { usePullRequestFilesSection } from "./PullRequestFiles";
114+
import { usePullRequestMaintainerEdits } from "./usePullRequestMaintainerEdits";
114115
import { PullRequestDescription } from "./PullRequestDescription";
115116
import { PullRequestMediaVisibleContext } from "./PullRequestMedia";
116117
import { PullRequestMarkdownRepository } from "./PullRequestMarkdown";
@@ -416,6 +417,11 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
416417
const terminology = sourceControlClients.get(identity?.provider).changeRequest;
417418
const permissions = usePullRequestPermissions(params, pr);
418419
const action = usePullRequestAction(params, pr);
420+
const maintainerEdits = usePullRequestMaintainerEdits(
421+
params,
422+
pr,
423+
permissions.canEditMaintainerEdits,
424+
);
419425
const showsDeleteBranch = pr !== null && canPerformPullRequestAction(pr, "delete-branch");
420426
const confirmDeleteBranch = () =>
421427
pr &&
@@ -517,6 +523,19 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
517523
},
518524
]
519525
: []),
526+
...(maintainerEdits.visible
527+
? [
528+
{
529+
accessibilityLabel: "Allow edits from maintainers",
530+
icon: "pencil" as const,
531+
selected: maintainerEdits.value,
532+
disabled: maintainerEdits.saving,
533+
subtitle: maintainerEdits.subtitle,
534+
overflowOnly: true,
535+
onPress: maintainerEdits.toggle,
536+
},
537+
]
538+
: []),
520539
...(identity
521540
? [
522541
{
@@ -597,6 +616,17 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
597616
<Toolbar.Label>Edit description</Toolbar.Label>
598617
</Toolbar.MenuAction>
599618
) : null}
619+
{maintainerEdits.visible ? (
620+
<Toolbar.MenuAction
621+
icon="pencil"
622+
isOn={maintainerEdits.value}
623+
disabled={maintainerEdits.saving}
624+
subtitle={maintainerEdits.subtitle}
625+
onPress={maintainerEdits.toggle}
626+
>
627+
<Toolbar.Label>Allow edits from maintainers</Toolbar.Label>
628+
</Toolbar.MenuAction>
629+
) : null}
600630
{identity ? (
601631
<Toolbar.MenuAction
602632
icon="arrow.up.right"
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { useAtomRefresh } from "@effect/atom-react";
2+
import {
3+
maintainerEditsChoiceInForce,
4+
type MaintainerEditsChoice,
5+
} from "@t3tools/client-runtime/pull-request-editing";
6+
import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
7+
import type { PullRequestDetail } from "@t3tools/contracts";
8+
import { AsyncResult } from "effect/reactivity";
9+
import { useRef, useState } from "react";
10+
import * as Dialog from "../../components/ui/Dialog";
11+
import { composerPullRequests } from "../../state/pull-requests";
12+
import { useAtomCommand } from "../../state/use-atom-command";
13+
import { pullRequestTarget, type PullRequestParams } from "./usePullRequestDiff";
14+
15+
export function usePullRequestMaintainerEdits(
16+
params: PullRequestParams,
17+
pr: PullRequestDetail | null,
18+
canEdit: boolean,
19+
) {
20+
const target = pullRequestTarget(params);
21+
const update = useAtomCommand(composerPullRequests.update, { reportFailure: false });
22+
const refreshDetail = useAtomRefresh(composerPullRequests.detail(target));
23+
const pending = useRef(false);
24+
const [saving, setSaving] = useState(false);
25+
const [choice, setChoice] = useState<MaintainerEditsChoice | null>(null);
26+
const kept = maintainerEditsChoiceInForce(choice, pr?.url ?? "", pr?.observedAt, saving);
27+
if (kept !== choice) {
28+
setChoice(kept);
29+
}
30+
const value = kept?.value ?? pr?.maintainerCanModify === true;
31+
const save = async (next: boolean) => {
32+
if (pending.current || pr === null || !canEdit) return;
33+
pending.current = true;
34+
const previousChoice = choice;
35+
setSaving(true);
36+
setChoice({ key: pr.url, observedAt: pr.observedAt, value: next });
37+
const response = await update({
38+
...target,
39+
input: { ...target.input, maintainerCanModify: next },
40+
});
41+
pending.current = false;
42+
setSaving(false);
43+
if (AsyncResult.isFailure(response)) {
44+
setChoice(previousChoice);
45+
const cause = squashAtomCommandFailure(response);
46+
Dialog.alert(
47+
"Could not save maintainer access",
48+
cause instanceof Error ? cause.message : "Try again.",
49+
);
50+
return;
51+
}
52+
refreshDetail();
53+
};
54+
return {
55+
visible: canEdit,
56+
value,
57+
saving,
58+
subtitle: saving
59+
? "Saving…"
60+
: "Maintainers can push to this branch. If your fork has workflows, this can also give access to its secrets.",
61+
toggle: () => void save(!value),
62+
};
63+
}

‎apps/mobile/src/features/pull-requests/usePullRequestPermissions.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useAtomValue } from "@effect/atom-react";
22
import {
33
canEditPullRequestChangeRequest,
44
canEditPullRequestComment,
5+
canEditPullRequestMaintainerEdits,
56
} from "@t3tools/client-runtime/pull-request-editing";
67
import type { PullRequestComment, PullRequestDetail } from "@t3tools/contracts";
78
import { usePullRequestConnected } from "./usePullRequestConnected";
@@ -49,6 +50,8 @@ export function usePullRequestPermissions(params: PullRequestParams, pr: PullReq
4950
canWrite: connected && canWrite,
5051
canEditChangeRequest:
5152
connected && canUpdate && pr !== null && canEditPullRequestChangeRequest(pr),
53+
canEditMaintainerEdits:
54+
connected && canUpdate && pr !== null && canEditPullRequestMaintainerEdits(pr),
5255
canEditComment: (comment: Pick<PullRequestComment, "author" | "canEdit" | "kind">) =>
5356
connected && canUpdateComment && pr !== null && canEditPullRequestComment(pr, comment),
5457
canReact: connected && canSetReaction && pr?.capabilities.reactions === true,

‎apps/mobile/src/features/threads/thread-list-v2-items.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,8 +1327,9 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
13271327
>
13281328
<View
13291329
className={cn(
1330-
"min-h-[44px] flex-row items-center gap-2.5 py-2",
1331-
sidebarPane ? "px-3" : "px-5",
1330+
THREAD_LIST_V2_ROW_CONTENT_CLASS_NAME,
1331+
"min-h-[44px] flex-row items-center gap-2 py-2",
1332+
sidebarPane && "px-3",
13321333
)}
13331334
>
13341335
{props.project ? (

‎apps/server/src/pullRequest/PullRequestService.test.ts‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,65 @@ function hostedChangeRequest(body: string, additions = 1) {
116116
};
117117
}
118118

119+
it.effect("reads maintainer edits and changes them through the update command", () =>
120+
Effect.gen(function* () {
121+
let enabled = true;
122+
const provider = fakePullRequestProvider(SourceControlProviderKind.make("github"), {
123+
getChangeRequest: () =>
124+
Effect.succeed({ ...hostedChangeRequest("Body"), maintainerCanModify: enabled }),
125+
updateChangeRequest: (input) =>
126+
Effect.sync(() => {
127+
assert.strictEqual(input.title, undefined);
128+
assert.strictEqual(input.body, undefined);
129+
enabled = input.maintainerCanModify!;
130+
}),
131+
});
132+
const service = yield* makeService({
133+
projects: [project({ id: "p1", title: "web", workspaceRoot: "/w", repository: "acme/web" })],
134+
providers: [
135+
{
136+
...provider,
137+
capabilities: {
138+
...provider.capabilities,
139+
edit: { changeRequest: true, comment: true, maintainerEdits: true },
140+
},
141+
},
142+
],
143+
});
144+
const ref = { projectId: "p1" as ProjectId, repository: "acme/web", number: 1 };
145+
assert.strictEqual((yield* service.detail(ref)).maintainerCanModify, true);
146+
yield* service.update({ ...ref, maintainerCanModify: false });
147+
assert.strictEqual((yield* service.detail(ref)).maintainerCanModify, false);
148+
}),
149+
);
150+
151+
it.effect("refuses maintainer edits on a host without the capability", () =>
152+
Effect.gen(function* () {
153+
let writes = 0;
154+
const service = yield* makeService({
155+
projects: [project({ id: "p1", title: "web", workspaceRoot: "/w", repository: "acme/web" })],
156+
providers: [
157+
fakePullRequestProvider(SourceControlProviderKind.make("github"), {
158+
updateChangeRequest: () =>
159+
Effect.sync(() => {
160+
writes += 1;
161+
}),
162+
}),
163+
],
164+
});
165+
const result = yield* service
166+
.update({
167+
projectId: "p1" as ProjectId,
168+
repository: "acme/web",
169+
number: 1,
170+
maintainerCanModify: false,
171+
})
172+
.pipe(Effect.flip);
173+
assert.strictEqual(result._tag, "PullRequestOperationError");
174+
assert.strictEqual(writes, 0);
175+
}),
176+
);
177+
119178
it.effect("does not wait for an in-flight detail read to display a preview", () =>
120179
Effect.gen(function* () {
121180
const detailStarted = yield* Deferred.make<void>();

‎apps/server/src/pullRequest/PullRequestService.ts‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1753,6 +1753,9 @@ export const make = Effect.gen(function* () {
17531753
...(changeRequest.autoMergeMethod === undefined
17541754
? {}
17551755
: { autoMergeMethod: changeRequest.autoMergeMethod }),
1756+
...(changeRequest.maintainerCanModify === undefined
1757+
? {}
1758+
: { maintainerCanModify: changeRequest.maintainerCanModify }),
17561759
...(changeRequest.workflowApprovalsRequired === undefined
17571760
? {}
17581761
: { workflowApprovalsRequired: changeRequest.workflowApprovalsRequired }),
@@ -2138,7 +2141,22 @@ export const make = Effect.gen(function* () {
21382141
}),
21392142
);
21402143
}
2141-
if (input.title === undefined && input.body === undefined) {
2144+
if (
2145+
input.maintainerCanModify !== undefined &&
2146+
project.api.capabilities.edit?.maintainerEdits !== true
2147+
) {
2148+
return Effect.fail(
2149+
new PullRequestOperationError({
2150+
operation: "update",
2151+
detail: "This host does not support maintainer edits.",
2152+
}),
2153+
);
2154+
}
2155+
if (
2156+
input.title === undefined &&
2157+
input.body === undefined &&
2158+
input.maintainerCanModify === undefined
2159+
) {
21422160
return Effect.fail(
21432161
new PullRequestOperationError({
21442162
operation: "update",
@@ -2151,6 +2169,9 @@ export const make = Effect.gen(function* () {
21512169
repository: project.repository,
21522170
host: project.host,
21532171
number: input.number,
2172+
...(input.maintainerCanModify === undefined
2173+
? {}
2174+
: { maintainerCanModify: input.maintainerCanModify }),
21542175
...(input.title === undefined ? {} : { title: input.title }),
21552176
...(input.body === undefined ? {} : { body: input.body }),
21562177
}).pipe(Effect.mapError(toPullRequestError("update")));

‎apps/web/src/components/ContextChip.tsx‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ const contextChipVariants = cva(
1212
variants: {
1313
kind: {
1414
neutral: "[--context-chip-accent:currentColor]",
15-
image:
16-
"rounded-lg border border-(--context-chip-accent)/30 bg-(--context-chip-accent)/10 px-1.5 [--context-chip-accent:var(--context-chip-image)]",
15+
image: "[--context-chip-accent:var(--context-chip-image)]",
1716
video: "[--context-chip-accent:var(--context-chip-video)]",
1817
file: "[--context-chip-accent:var(--context-chip-file)]",
1918
mention: "[--context-chip-accent:var(--context-chip-mention)]",

0 commit comments

Comments
 (0)