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

AzureDevOpsPullRequestCli.ts

732 lines24.8 KB

1import * as Context from "effect/Context";
2import * as Effect from "effect/Effect";
3import * as Layer from "effect/Layer";
4import * as Result from "effect/Result";
5import * as Schema from "effect/Schema";
6import type {
7 PullRequestAction,
8 PullRequestComment,
9 PullRequestInvolvement,
10 PullRequestListState,
11 PullRequestMergeMethod,
12} from "@t3tools/contracts";
13​
14import * as AzureDevOpsCli from "./AzureDevOpsCli.ts";
15import {
16 decodeItemContentJson,
17 decodeIterationChangesJson,
18 decodeIterationsJson,
19 decodePullRequestJson,
20 decodePullRequestListJson,
21 decodeThreadsJson,
22 decodeViewerJson,
23 type AzureDevOpsChangeEntry,
24 type AzureDevOpsItemContent,
25 type AzureDevOpsIteration,
26 type AzureDevOpsPullRequest,
27 type AzureDevOpsRepositoryLocation,
28} from "./azureDevOpsPullRequestJson.ts";
29import type { ProviderListCursor } from "@t3tools/source-control-core/server/PullRequestProvider";
30​
31export class AzureDevOpsPullRequestReadError extends Schema.TaggedError<AzureDevOpsPullRequestReadError>()(
32 "AzureDevOpsPullRequestReadError",
33 {
34 command: Schema.Literal("az"),
35 cwd: Schema.String,
36 operation: Schema.String,
37 cause: Schema.Defect(),
38 },
39) {
40 get detail(): string {
41 return `Azure CLI returned an unreadable ${this.operation} response.`;
42 }
43​
44 override get message(): string {
45 return `Azure CLI failed in ${this.operation}: ${this.detail}`;
46 }
48​
49export class AzureDevOpsViewerUnavailableError extends Schema.TaggedError<AzureDevOpsViewerUnavailableError>()(
50 "AzureDevOpsViewerUnavailableError",
51 {
52 command: Schema.Literal("az"),
53 cwd: Schema.String,
54 },
55) {
56 get detail(): string {
57 return "Azure CLI could not name the signed-in account. Run `az login` and retry.";
58 }
59​
60 override get message(): string {
61 return `Azure CLI failed in getViewer: ${this.detail}`;
62 }
64​
65export class AzureDevOpsPullRequestIncompleteError extends Schema.TaggedError<AzureDevOpsPullRequestIncompleteError>()(
66 "AzureDevOpsPullRequestIncompleteError",
67 {
68 command: Schema.Literal("az"),
69 cwd: Schema.String,
70 number: Schema.Int,
71 },
72) {
73 get detail(): string {
74 return "Azure DevOps returned no branch or link for the pull request.";
75 }
76​
77 override get message(): string {
78 return `Azure CLI failed in getPullRequest: ${this.detail}`;
79 }
81​
82export class AzureDevOpsReviewerNameError extends Schema.TaggedError<AzureDevOpsReviewerNameError>()(
83 "AzureDevOpsReviewerNameError",
84 {
85 command: Schema.Literal("az"),
86 cwd: Schema.String,
87 },
88) {
89 get detail(): string {
90 return "A reviewer is named by an email address or an identity id.";
91 }
92​
93 override get message(): string {
94 return `Azure CLI failed in setPullRequestReviewers: ${this.detail}`;
95 }
97​
98export type AzureDevOpsPullRequestCliError =
99 | AzureDevOpsCli.AzureDevOpsCliError
100 | AzureDevOpsPullRequestReadError
101 | AzureDevOpsPullRequestIncompleteError
102 | AzureDevOpsReviewerNameError
103 | AzureDevOpsViewerUnavailableError;
104​
105const REST_API_VERSION = "7.1";
106const PULL_REQUEST_LIST_MAX_OUTPUT_BYTES = 16 * 1024 * 1024;
107/**
108 * A full page of change entries is two thousand files, each carrying its path, its url and
109 * several object ids, which is past the megabyte a read is given by default.
110 */
111const CHANGE_ENTRIES_MAX_OUTPUT_BYTES = 8 * 1024 * 1024;
112/**
113 * Four times the megabyte of file the other hosts hand over, because Azure has no route that
114 * serves the bytes themselves: the file arrives inside a JSON envelope, escaped if it is text and
115 * base64 if it is not, and both are larger than the file they carry.
116 */
117const ITEM_CONTENT_MAX_OUTPUT_BYTES = 4 * 1024 * 1024;
118/**
119 * Neither route pages, so each answers with the whole of it at once and grows with how
120 * long the review ran rather than with how large the change is.
121 */
122const REVIEW_HISTORY_MAX_OUTPUT_BYTES = 8 * 1024 * 1024;
123​
124/** Azure's own ceiling for one page of an iteration's changes. */
125const CHANGE_ENTRIES_PER_PAGE = 2000;
126​
127/**
128 * Where following the pages stops, counted in the entries Azure was asked to skip rather than in
129 * the files that survived decoding: a page can be entirely folders and other entries a review has
130 * nothing to show for, and bounding on what was kept would follow such a change forever.
131 */
132const MAX_CHANGE_ENTRIES = 10_000;
133​
134export interface AzureDevOpsIterationChanges {
135 readonly changes: ReadonlyArray<AzureDevOpsChangeEntry>;
136 readonly truncated: boolean;
138​
139export class AzureDevOpsPullRequestCli extends Context.Service<
140 AzureDevOpsPullRequestCli,
141 {
142 readonly getViewer: (input: {
143 readonly cwd: string;
144 }) => Effect.Effect<string, AzureDevOpsPullRequestCliError>;
145​
146 readonly listPullRequests: (input: {
147 readonly cwd: string;
148 readonly repository: string;
149 readonly state: PullRequestListState;
150 readonly involvement: PullRequestInvolvement;
151 readonly viewer: string;
152 readonly limit: number;
153 /** Matched by `--creator`, which takes the email a row shows as its login. */
154 readonly author?: string | undefined;
155 /**
156 * Where to carry on from. Azure has no date filter for a pull request listing, so the only
157 * part of a cursor it can use is how many rows have already been handed over.
158 */
159 readonly cursor?: ProviderListCursor | undefined;
160 }) => Effect.Effect<
161 {
162 readonly items: ReadonlyArray<AzureDevOpsPullRequest>;
163 readonly truncated: boolean;
164 readonly cursorAdvance: number;
165 },
166 AzureDevOpsPullRequestCliError
167 >;
168​
169 readonly getPullRequest: (input: {
170 readonly cwd: string;
171 readonly number: number;
172 }) => Effect.Effect<AzureDevOpsPullRequest, AzureDevOpsPullRequestCliError>;
173​
174 /** Threads are not reachable through `az repos pr`, so they come from the REST API. */
175 readonly listThreads: (input: {
176 readonly cwd: string;
177 readonly location: AzureDevOpsRepositoryLocation;
178 readonly number: number;
179 }) => Effect.Effect<ReadonlyArray<PullRequestComment>, AzureDevOpsPullRequestCliError>;
180​
181 /**
182 * Azure hangs the changed files off an iteration rather than off the pull
183 * request, so reading a diff starts here.
184 */
185 readonly listIterations: (input: {
186 readonly cwd: string;
187 readonly location: AzureDevOpsRepositoryLocation;
188 readonly number: number;
189 }) => Effect.Effect<ReadonlyArray<AzureDevOpsIteration>, AzureDevOpsPullRequestCliError>;
190​
191 /**
192 * What one iteration changed, against the merge base rather than against the previous push,
193 * which is the whole of the pull request rather than the latest slice of it.
194 */
195 readonly listIterationChanges: (input: {
196 readonly cwd: string;
197 readonly location: AzureDevOpsRepositoryLocation;
198 readonly number: number;
199 readonly iterationId: number;
200 }) => Effect.Effect<AzureDevOpsIterationChanges, AzureDevOpsPullRequestCliError>;
201​
202 /**
203 * One file's text at one commit. Azure has no diff route that carries content, so both sides
204 * of every changed file are read this way and the patch is made from them here.
205 */
206 readonly readItemContent: (input: {
207 readonly cwd: string;
208 readonly location: AzureDevOpsRepositoryLocation;
209 readonly path: string;
210 readonly commit: string;
211 }) => Effect.Effect<AzureDevOpsItemContent, AzureDevOpsPullRequestCliError>;
212​
213 readonly runPullRequestAction: (input: {
214 readonly cwd: string;
215 readonly number: number;
216 readonly action: PullRequestAction;
217 readonly mergeMethod?: PullRequestMergeMethod;
218 }) => Effect.Effect<void, AzureDevOpsPullRequestCliError>;
219​
220 readonly updatePullRequest: (input: {
221 readonly cwd: string;
222 readonly number: number;
223 readonly title?: string | undefined;
224 readonly body?: string | undefined;
225 }) => Effect.Effect<void, AzureDevOpsPullRequestCliError>;
226​
227 /**
228 * `az repos pr reviewer` is the whole of what Azure offers here: it adds and removes named
229 * identities, and has no counterpart that says who could be named.
230 */
231 readonly setPullRequestReviewers: (input: {
232 readonly cwd: string;
233 readonly number: number;
234 readonly reviewers: ReadonlyArray<string>;
235 readonly requested: boolean;
236 }) => Effect.Effect<void, AzureDevOpsPullRequestCliError>;
237 }
238>()("@t3tools/source-control-azure-devops/server/AzureDevOpsPullRequestCli") {}
239​
240function statusArgs(state: PullRequestListState): ReadonlyArray<string> {
241 switch (state) {
242 case "open":
243 return ["--status", "active"];
244 case "merged":
245 return ["--status", "completed"];
246 case "closed":
247 return ["--status", "abandoned"];
248 case "all":
249 return ["--status", "all"];
250 }
252​
253function involvementArgs(input: {
254 readonly involvement: PullRequestInvolvement;
255 readonly viewer: string;
256}): ReadonlyArray<string> {
257 switch (input.involvement) {
258 case "authored":
259 return ["--creator", input.viewer];
260 case "reviewing":
261 return ["--reviewer", input.viewer];
262 case "all":
263 return [];
264 }
266​
267function actionArgs(
268 action: PullRequestAction,
269 mergeMethod: PullRequestMergeMethod | undefined,
270): ReadonlyArray<string> {
271 switch (action) {
272 case "merge":
273 return ["--status", "completed", "--squash", mergeMethod === "squash" ? "true" : "false"];
274 case "enable-auto-merge":
275 return [
276 "--auto-complete",
277 "true",
278 ...(mergeMethod === undefined
279 ? []
280 : ["--squash", mergeMethod === "squash" ? "true" : "false"]),
281 ];
282 case "disable-auto-merge":
283 return ["--auto-complete", "false"];
284 case "ready":
285 return ["--draft", "false"];
286 case "draft":
287 return ["--draft", "true"];
288 case "close":
289 return ["--status", "abandoned"];
290 case "update-branch":
291 return [];
292 case "reopen":
293 return ["--status", "active"];
294 case "revert":
295 case "approve-workflows":
296 case "delete-branch":
297 throw new Error(`Azure DevOps pull request action ${action} is unsupported`);
298 }
300​
301/**
302 * The dash is the whole point — these are argv, and a value that looks like a
303 * flag stops being a value.
304 */
305function isReviewerName(value: string): boolean {
306 const name = value.trim();
307 return name.length > 0 && !name.startsWith("-");
309​
310/** @public Service construction is part of the canonical Effect module API. */
311export const make = Effect.gen(function* () {
312 const azure = yield* AzureDevOpsCli.AzureDevOpsCli;
313​
314 // The remote takes three shapes and only `az` knows how to read all of them.
315 const detectArgs = ["--detect", "true"] as const;
316​
317 const executeJson = (input: {
318 readonly cwd: string;
319 readonly args: ReadonlyArray<string>;
320 readonly maxOutputBytes?: number;
321 }) =>
322 azure.execute({
323 cwd: input.cwd,
324 args: [...input.args, "--only-show-errors", "--output", "json"],
325 ...(input.maxOutputBytes === undefined ? {} : { maxOutputBytes: input.maxOutputBytes }),
326 });
327​
328 /**
329 * Used in place of `az rest` because it signs in the way the azure-devops extension does: `az
330 * rest` mints its own token against the tenant `az` defaults to, and an organisation in any
331 * other tenant answers that with a sign-in page, which arrives here as unreadable output
332 * rather than as a failure.
333 */
334 const invoke = <A>(input: {
335 readonly cwd: string;
336 readonly operation: string;
337 readonly resource: string;
338 readonly routeParameters: ReadonlyArray<string>;
339 readonly queryParameters?: ReadonlyArray<string>;
340 readonly maxOutputBytes?: number;
341 readonly decode: (raw: string) => Result.Result<A, unknown>;
342 }): Effect.Effect<A, AzureDevOpsPullRequestCliError> =>
343 executeJson({
344 cwd: input.cwd,
345 ...(input.maxOutputBytes === undefined ? {} : { maxOutputBytes: input.maxOutputBytes }),
346 args: [
347 "devops",
348 "invoke",
349 ...detectArgs,
350 "--area",
351 "git",
352 "--resource",
353 input.resource,
354 "--api-version",
355 REST_API_VERSION,
356 "--route-parameters",
357 ...input.routeParameters,
358 ...(input.queryParameters === undefined
359 ? []
360 : ["--query-parameters", ...input.queryParameters]),
361 ],
362 }).pipe(
363 Effect.flatMap((result) => {
364 const decoded = input.decode(result.stdout.trim());
365 return Result.isSuccess(decoded)
366 ? Effect.succeed(decoded.success)
367 : Effect.fail(
368 new AzureDevOpsPullRequestReadError({
369 command: "az",
370 cwd: input.cwd,
371 operation: input.operation,
372 cause: decoded.failure,
373 }),
374 );
375 }),
376 );
377​
378 /**
379 * Azure names its own items with a leading slash, which the repository paths carried around
380 * here have had taken off so they match the patch and the viewed mark. Put it back on the way
381 * out, because the items route is documented in Azure's own spelling.
382 */
383 const toItemPath = (path: string) => (path.startsWith("/") ? path : `/${path}`);
384​
385 const repositoryRoute = (location: AzureDevOpsRepositoryLocation): ReadonlyArray<string> => [
386 `project=${location.project}`,
387 `repositoryId=${location.repository}`,
388 ];
389​
390 const pullRequestRoute = (input: {
391 readonly location: AzureDevOpsRepositoryLocation;
392 readonly number: number;
393 }): ReadonlyArray<string> => [
394 ...repositoryRoute(input.location),
395 `pullRequestId=${input.number}`,
396 ];
397​
398 /**
399 * Azure pages by raw offset. Keep reading when malformed rows leave the decoded page short, and
400 * retain the raw count so the next public cursor skips every row this walk consumed.
401 */
402 const listPullRequestPage = (input: {
403 readonly cwd: string;
404 readonly repository: string;
405 readonly state: PullRequestListState;
406 readonly involvement: PullRequestInvolvement;
407 readonly viewer: string;
408 readonly author?: string | undefined;
409 readonly limit: number;
410 readonly skip: number;
411 readonly cursorAdvance: number;
412 readonly items: ReadonlyArray<AzureDevOpsPullRequest>;
413 }): Effect.Effect<
414 {
415 readonly items: ReadonlyArray<AzureDevOpsPullRequest>;
416 readonly truncated: boolean;
417 readonly cursorAdvance: number;
418 },
419 AzureDevOpsPullRequestCliError
420 > => {
421 const remaining = input.limit - input.items.length;
422 const top = remaining + 1;
423 return executeJson({
424 cwd: input.cwd,
425 maxOutputBytes: PULL_REQUEST_LIST_MAX_OUTPUT_BYTES,
426 args: [
427 "repos",
428 "pr",
429 "list",
430 ...detectArgs,
431 "--repository",
432 input.repository,
433 ...statusArgs(input.state),
434 ...involvementArgs(input),
435 ...(input.author === undefined || input.involvement === "authored"
436 ? []
437 : ["--creator", input.author]),
438 "--include-links",
439 ...(input.skip === 0 ? [] : ["--skip", String(input.skip)]),
440 "--top",
441 String(top),
442 ],
443 }).pipe(
444 Effect.flatMap((result) => {
445 const raw = result.stdout.trim();
446 if (raw.length === 0) {
447 return Effect.succeed({
448 items: input.items,
449 truncated: false,
450 cursorAdvance: input.cursorAdvance,
451 });
452 }
453 const decoded = decodePullRequestListJson(raw);
454 if (!Result.isSuccess(decoded)) {
455 return Effect.fail(
456 new AzureDevOpsPullRequestReadError({
457 command: "az",
458 cwd: input.cwd,
459 operation: "listPullRequests",
460 cause: decoded.failure,
461 }),
462 );
463 }
464​
465 const lastItemIndex = decoded.success.rawIndexes[remaining - 1];
466 if (lastItemIndex !== undefined) {
467 const consumed = lastItemIndex + 1;
468 return Effect.succeed({
469 items: [...input.items, ...decoded.success.items.slice(0, remaining)],
470 truncated: consumed < decoded.success.rawCount || decoded.success.rawCount === top,
471 cursorAdvance: input.cursorAdvance + consumed,
472 });
473 }
474​
475 const items = [...input.items, ...decoded.success.items];
476 if (decoded.success.rawCount < top) {
477 return Effect.succeed({
478 items,
479 truncated: false,
480 cursorAdvance: input.cursorAdvance + decoded.success.rawCount,
481 });
482 }
483 return listPullRequestPage({
484 ...input,
485 skip: input.skip + decoded.success.rawCount,
486 cursorAdvance: input.cursorAdvance + decoded.success.rawCount,
487 items,
488 });
489 }),
490 );
491 };
492​
493 return AzureDevOpsPullRequestCli.of({
494 getViewer: (input) =>
495 executeJson({ cwd: input.cwd, args: ["account", "show", "--query", "user"] }).pipe(
496 Effect.flatMap((result): Effect.Effect<string, AzureDevOpsPullRequestCliError> => {
497 const decoded = decodeViewerJson(`{"user":${result.stdout.trim() || "null"}}`);
498 if (!Result.isSuccess(decoded)) {
499 return Effect.fail(
500 new AzureDevOpsPullRequestReadError({
501 command: "az",
502 cwd: input.cwd,
503 operation: "getViewer",
504 cause: decoded.failure,
505 }),
506 );
507 }
508 return decoded.success === null
509 ? Effect.fail(new AzureDevOpsViewerUnavailableError({ command: "az", cwd: input.cwd }))
510 : Effect.succeed(decoded.success);
511 }),
512 // `az devops login` signs in with a personal access token, which `az account show` knows
513 // nothing about, and nothing in `az` prints whose token it is. `--creator me` is resolved
514 // by the extension itself, so the viewer's own pull request names them.
515 Effect.catchIf(
516 (error) => error._tag !== "AzureDevOpsCliUnavailableError",
517 () =>
518 executeJson({
519 cwd: input.cwd,
520 args: [
521 "repos",
522 "pr",
523 "list",
524 ...detectArgs,
525 "--creator",
526 "me",
527 "--status",
528 "all",
529 "--top",
530 "1",
531 ],
532 }).pipe(
533 Effect.flatMap((result): Effect.Effect<string, AzureDevOpsPullRequestCliError> => {
534 const decoded = decodePullRequestListJson(result.stdout.trim() || "[]");
535 const login = Result.isSuccess(decoded)
536 ? decoded.success.items[0]?.author?.login
537 : undefined;
538 return login === undefined
539 ? Effect.fail(
540 new AzureDevOpsViewerUnavailableError({ command: "az", cwd: input.cwd }),
541 )
542 : Effect.succeed(login);
543 }),
544 ),
545 ),
546 ),
547​
548 listPullRequests: (input) =>
549 listPullRequestPage({
550 cwd: input.cwd,
551 repository: input.repository,
552 state: input.state,
553 involvement: input.involvement,
554 viewer: input.viewer,
555 author: input.author,
556 limit: input.limit,
557 skip: input.cursor?.delivered ?? 0,
558 cursorAdvance: 0,
559 items: [],
560 }),
561​
562 getPullRequest: (input) =>
563 executeJson({
564 cwd: input.cwd,
565 args: ["repos", "pr", "show", ...detectArgs, "--id", String(input.number)],
566 }).pipe(
567 Effect.flatMap(
568 (result): Effect.Effect<AzureDevOpsPullRequest, AzureDevOpsPullRequestCliError> => {
569 const decoded = decodePullRequestJson(result.stdout.trim());
570 if (!Result.isSuccess(decoded)) {
571 return Effect.fail(
572 new AzureDevOpsPullRequestReadError({
573 command: "az",
574 cwd: input.cwd,
575 operation: "getPullRequest",
576 cause: decoded.failure,
577 }),
578 );
579 }
580 return decoded.success === null
581 ? Effect.fail(
582 new AzureDevOpsPullRequestIncompleteError({
583 command: "az",
584 cwd: input.cwd,
585 number: input.number,
586 }),
587 )
588 : Effect.succeed(decoded.success);
589 },
590 ),
591 ),
592​
593 listThreads: (input) =>
594 invoke({
595 cwd: input.cwd,
596 operation: "listThreads",
597 resource: "pullRequestThreads",
598 routeParameters: pullRequestRoute(input),
599 maxOutputBytes: REVIEW_HISTORY_MAX_OUTPUT_BYTES,
600 decode: decodeThreadsJson,
601 }),
602​
603 listIterations: (input) =>
604 invoke({
605 cwd: input.cwd,
606 operation: "listIterations",
607 resource: "pullRequestIterations",
608 routeParameters: pullRequestRoute(input),
609 maxOutputBytes: REVIEW_HISTORY_MAX_OUTPUT_BYTES,
610 decode: decodeIterationsJson,
611 }),
612​
613 listIterationChanges: (input) => {
614 const page = (skip: number) =>
615 invoke({
616 cwd: input.cwd,
617 operation: "listIterationChanges",
618 resource: "pullRequestIterationChanges",
619 routeParameters: [...pullRequestRoute(input), `iterationId=${input.iterationId}`],
620 queryParameters: [`$top=${CHANGE_ENTRIES_PER_PAGE}`, `$skip=${skip}`],
621 maxOutputBytes: CHANGE_ENTRIES_MAX_OUTPUT_BYTES,
622 decode: decodeIterationChangesJson,
623 });
624 const from = (
625 skip: number,
626 collected: ReadonlyArray<AzureDevOpsChangeEntry>,
627 ): Effect.Effect<AzureDevOpsIterationChanges, AzureDevOpsPullRequestCliError> =>
628 page(skip).pipe(
629 Effect.flatMap((answer) => {
630 const changes = [...collected, ...answer.changes];
631 if (answer.nextSkip === null) return Effect.succeed({ changes, truncated: false });
632 return answer.nextSkip <= skip || answer.nextSkip >= MAX_CHANGE_ENTRIES
633 ? Effect.succeed({ changes, truncated: true })
634 : from(answer.nextSkip, changes);
635 }),
636 );
637 return from(0, []);
638 },
639​
640 readItemContent: (input) =>
641 invoke({
642 cwd: input.cwd,
643 operation: "readItemContent",
644 resource: "items",
645 routeParameters: repositoryRoute(input.location),
646 queryParameters: [
647 `path=${toItemPath(input.path)}`,
648 "versionDescriptor.versionType=commit",
649 `versionDescriptor.version=${input.commit}`,
650 "includeContent=true",
651 // Azure leaves `contentMetadata` out unless this is asked for, and with it goes its own
652 // word on whether the file is binary, which is the only reliable one, since a binary
653 // file arrives encoded rather than as the bytes it is on the host.
654 "includeContentMetadata=true",
655 // Without this Azure answers with the file's own bytes rather than with a JSON
656 // envelope, and `az devops invoke` refuses anything it cannot parse as JSON.
657 "$format=json",
658 ],
659 maxOutputBytes: ITEM_CONTENT_MAX_OUTPUT_BYTES,
660 decode: decodeItemContentJson,
661 }),
662​
663 setPullRequestReviewers: (input) =>
664 input.reviewers.some((reviewer) => !isReviewerName(reviewer))
665 ? Effect.fail(new AzureDevOpsReviewerNameError({ command: "az", cwd: input.cwd }))
666 : azure
667 .execute({
668 cwd: input.cwd,
669 args: [
670 "repos",
671 "pr",
672 "reviewer",
673 input.requested ? "add" : "remove",
674 ...detectArgs,
675 "--id",
676 String(input.number),
677 // One `--reviewers` takes them all, because az reads the flag as a list and a
678 // second one would replace the first rather than add to it.
679 "--reviewers",
680 ...input.reviewers,
681 "--only-show-errors",
682 "--output",
683 "json",
684 ],
685 })
686 .pipe(Effect.asVoid),
687​
688 runPullRequestAction: (input) =>
689 azure
690 .execute({
691 cwd: input.cwd,
692 args: [
693 "repos",
694 "pr",
695 "update",
696 ...detectArgs,
697 "--id",
698 String(input.number),
699 ...actionArgs(input.action, input.mergeMethod),
700 "--only-show-errors",
701 "--output",
702 "json",
703 ],
704 })
705 .pipe(Effect.asVoid),
706​
707 updatePullRequest: (input) =>
708 azure
709 .execute({
710 cwd: input.cwd,
711 args: [
712 "repos",
713 "pr",
714 "update",
715 ...detectArgs,
716 "--id",
717 String(input.number),
718 // One argument rather than a flag and a value beside it: a description usually opens
719 // with a bullet, and az reads a dash in the next argv slot as a flag of its own.
720 // `--description` also takes several strings, and this keeps the whole text as one.
721 ...(input.title === undefined ? [] : [`--title=${input.title}`]),
722 ...(input.body === undefined ? [] : [`--description=${input.body}`]),
723 "--only-show-errors",
724 "--output",
725 "json",
726 ],
727 })
728 .pipe(Effect.asVoid),
729 });
730});
731​
732export const layer = Layer.effect(AzureDevOpsPullRequestCli, make);