Skip to content

Commit 12c2b0e

Browse files
committed
fix(azure-devops): distinguish build restart from requeue
1 parent b9b5724 commit 12c2b0e

15 files changed

Lines changed: 893 additions & 205 deletions

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,38 @@ export function AzureBuildRequeueButton({
2323
);
2424
const run = useAtomCommand(composerPullRequests.runHostAction, { reportFailure: false });
2525
const pending = useRef(false);
26-
const [busy, setBusy] = useState(false);
26+
const [busyAction, setBusyAction] = useState<PullRequestCheck["buildAction"]>();
27+
const busy = busyAction !== undefined;
28+
const restart = (busyAction ?? check.buildAction) === "restart";
2729
const evaluationId = check.requeueEvaluationId;
28-
if (!evaluationId || !pr.capabilities.hostActions) return null;
2930
const reason = pr.viewerPermissions.deniedActions?.["requeue-policy"];
31+
if (
32+
!busy &&
33+
(!evaluationId || !pr.capabilities.hostActions || !allowed || reason || pr.state !== "open")
34+
)
35+
return null;
3036
return (
3137
<PullRequestPermissionButton
3238
tone="primary"
3339
reason={reason}
34-
label={busy ? "Requeueing…" : "Requeue"}
40+
label={restart ? (busy ? "Restarting…" : "Restart build") : busy ? "Requeueing…" : "Requeue"}
3541
disabled={busy || !allowed || pr.state !== "open"}
3642
onPress={() => {
37-
if (pending.current || busy || !allowed || reason || pr.state !== "open") return;
43+
if (!evaluationId || pending.current || busy || !allowed || reason || pr.state !== "open")
44+
return;
3845
pending.current = true;
39-
setBusy(true);
46+
setBusyAction(check.buildAction ?? "requeue");
4047
void Promise.resolve()
4148
.then(() =>
4249
run({
4350
...target,
4451
input: {
4552
...target.input,
46-
action: { type: "requeue-policy", evaluationId },
53+
action: {
54+
type: "requeue-policy",
55+
evaluationId,
56+
...(restart ? { restart: true } : {}),
57+
},
4758
},
4859
}),
4960
)
@@ -59,7 +70,7 @@ export function AzureBuildRequeueButton({
5970
)
6071
.finally(() => {
6172
pending.current = false;
62-
setBusy(false);
73+
setBusyAction(undefined);
6374
});
6475
}}
6576
/>

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

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ function Actions({ pr, params, children }: ActionsProps) {
262262
loading={query.isPending}
263263
denied={denied}
264264
disabled={disabled}
265+
allowed={allowed}
265266
feedback={feedback}
266267
operate={operate}
267268
hostAction={hostAction}
@@ -280,6 +281,7 @@ function AzureActionSheet({
280281
loading,
281282
denied,
282283
disabled,
284+
allowed,
283285
feedback,
284286
operate,
285287
hostAction,
@@ -292,6 +294,7 @@ function AzureActionSheet({
292294
loading: boolean;
293295
denied: Readonly<Record<string, string | undefined>>;
294296
disabled: boolean;
297+
allowed: boolean;
295298
feedback: ReactNode;
296299
operate: (run: () => Promise<unknown>) => Promise<void>;
297300
hostAction: (action: PullRequestHostAction) => Promise<void>;
@@ -309,8 +312,16 @@ function AzureActionSheet({
309312
const [completion, setCompletion] = useState(emptyAzureCompletionDraft);
310313
const [shareReceivers, setShareReceivers] = useState("");
311314
const [shareMessage, setShareMessage] = useState("");
315+
const [pendingBuild, setPendingBuild] = useState<Extract<
316+
PullRequestHostAction,
317+
{ type: "requeue-policy" }
318+
> | null>(null);
319+
const execute = (action: PullRequestHostAction) =>
320+
operate(() => {
321+
if (action.type === "requeue-policy") setPendingBuild(action);
322+
return hostAction(action).finally(() => setPendingBuild(null));
323+
});
312324
if (section === null) return null;
313-
const execute = (action: PullRequestHostAction) => operate(() => hostAction(action));
314325
const active = pr.state === "open";
315326
const allowedStrategies = details?.allowedMergeStrategies;
316327
const options = azureCompletionOptions(completion, allowedStrategies, pr.autoMergeMethod);
@@ -594,14 +605,27 @@ function AzureActionSheet({
594605
}}
595606
/>
596607
) : null}
597-
{policy.requeueable ? (
608+
{pendingBuild?.evaluationId === policy.id ||
609+
(policy.requeueable && active && allowed && !denied["requeue-policy"]) ? (
598610
<PullRequestPermissionButton
599611
tone="text"
600612
reason={denied["requeue-policy"]}
601-
label="Requeue"
613+
label={
614+
pendingBuild?.evaluationId === policy.id
615+
? pendingBuild.restart
616+
? "Restarting…"
617+
: "Requeueing…"
618+
: policy.buildAction === "restart"
619+
? "Restart build"
620+
: "Requeue"
621+
}
602622
disabled={disabled || !active}
603623
onPress={() =>
604-
void execute({ type: "requeue-policy", evaluationId: policy.id })
624+
void execute({
625+
type: "requeue-policy",
626+
evaluationId: policy.id,
627+
...(policy.buildAction === "restart" ? { restart: true } : {}),
628+
})
605629
}
606630
/>
607631
) : null}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,13 @@ export function PullRequestChecksRow(props: RowProps) {
160160
const status = checkStatus(check);
161161
const url = check.url;
162162
return (
163-
<View key={`${check.name}:${url}`}>
163+
<View
164+
key={
165+
check.kind === "azure-build" && check.policyEvaluationId
166+
? `azure-build:${check.policyEvaluationId}`
167+
: `${check.name}:${url}`
168+
}
169+
>
164170
<PullRequestCardRow
165171
title={check.name}
166172
icon={status.icon}
@@ -169,7 +175,8 @@ export function PullRequestChecksRow(props: RowProps) {
169175
detail={check.description ?? undefined}
170176
onPress={url ? () => void Linking.openURL(url) : undefined}
171177
/>
172-
{check.kind === "azure-build" && (check.requeueEvaluationId || url) ? (
178+
{check.kind === "azure-build" &&
179+
(check.policyEvaluationId || check.requeueEvaluationId || url) ? (
173180
<View className="flex-row flex-wrap gap-2 px-4 pb-2">
174181
<AzureBuildRequeueButton check={check} pr={props.pr} params={props.params} />
175182
{url ? (

0 commit comments

Comments
 (0)