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

AzureDevOpsPullRequestProvider.ts

646 lines27.2 KB

1import * as Effect from "effect/Effect";
2import * as Semaphore from "effect/Semaphore";
3import type { PullRequestCapabilities, PullRequestViewerPermissions } from "@t3tools/contracts";
4​
5import * as AzureDevOpsPullRequestCli from "./AzureDevOpsPullRequestCli.ts";
6import {
7 azureDevOpsFilePatch,
8 azureDevOpsUnreadableFilePatch,
9 formatAzureDevOpsDiffCursor,
10 parseAzureDevOpsDiffCursor,
11 MAX_DIFF_SLICE_BYTES,
12 MAX_DIFF_SLICE_EDITS,
13 MAX_DIFF_SLICE_FILES,
14 byteLength,
15 MAX_FILE_DIFF_EDITS,
16 type AzureDevOpsFileTexts,
17} from "./azureDevOpsDiff.ts";
18import {
19 PullRequestProviderError,
20 type PullRequestProviderFailure,
21 type ProviderChangeRequest,
22 type ProviderChangeRequestActivity,
23 type ProviderChangeRequestDetail,
24 type ProviderChangeRequestSummary,
25 type ProviderDiffSlice,
26 type PullRequestProviderApi,
27} from "./PullRequestProvider.ts";
28import type {
29 AzureDevOpsChangeEntry,
30 AzureDevOpsItemContent,
31 AzureDevOpsIteration,
32 AzureDevOpsPullRequest,
33 AzureDevOpsRepositoryLocation,
34} from "./azureDevOpsPullRequestJson.ts";
35​
36/**
37 * How many of a slice's files are read at once. Every file is two `az` invocations, each paying a
38 * Python interpreter's start-up, so reading them one after another is most of what the Code tab
39 * waits for. Four files means eight processes at once: the fan-out the GitHub CLI reads its
40 * per-file stats with here, and low enough not to swamp the host's throttling or the machine.
41 */
42const DIFF_FILE_CONCURRENCY = 4;
43​
44/**
45 * How many `az` processes this build will have out at once, counted across every reader rather
46 * than per request. The fan-out above bounds one Code tab, so two people opening two Azure reviews
47 * had sixteen Python interpreters starting at once and nothing above them. Held at what one
48 * request at full width spends, so a second reader waits behind the first instead of adding to it.
49 */
50export const MAX_DIFF_SPAWNS = 2 * DIFF_FILE_CONCURRENCY;
51​
52/** How many pull requests' repository locations one provider remembers at once. */
53export const LOCATION_CACHE_CAPACITY = 128;
54​
55const CAPABILITIES: PullRequestCapabilities = {
56 // Azure serves no patch of its own, so the one the Code tab reads is built here out of the
57 // files an iteration changed and both sides of each of them.
58 diff: true,
59 // Reading a conversation is a plain REST read, but posting one is not something this can
60 // claim without having run it, so the composer stays hidden.
61 comment: false,
62 actions: [
63 "merge",
64 "ready",
65 "draft",
66 "close",
67 "reopen",
68 "enable-auto-merge",
69 "disable-auto-merge",
70 ],
71 // Azure squashes as a completion option; it has no rebase strategy of its own.
72 mergeMethods: ["merge", "squash"],
73 // `az repos pr list` filters by status, creator, reviewer and branch, and by no text at all.
74 search: false,
75 reactions: false,
76 // The patch has lines to write against, but writing a remark at all is what Azure is not
77 // offered for here, so nothing in a review is either.
78 review: { inlineComment: false, reply: false, resolve: false, verdicts: [] },
79 // `az repos pr reviewer add` and `remove` name identities, and nothing anywhere in `az repos`
80 // lists the ones this repository could name — that lives behind the identity and graph APIs, a
81 // different service with its own permissions. So the page takes a name here rather than being
82 // handed a menu built out of a guess.
83 reviewers: { request: true, listCandidates: false },
84 // A new title and description travel on the same `az repos pr update` that moves a pull request.
85 // Rewriting a remark is false for the same reason posting one is: this cannot put a remark on
86 // Azure DevOps at all, so there is nothing here it could rewrite either.
87 edit: { changeRequest: true, comment: false },
88 // Azure does keep a viewed record of its own, but only behind the undocumented contribution
89 // endpoint its web UI talks to, keyed on an iteration so a push would drop every mark anyway.
90 // So they are kept here instead, and the client says whose they are rather than implying the
91 // Azure DevOps page will show them.
92 viewedFiles: "environment",
93};
94​
95/**
96 * Everything this host offers, granted to whoever is signed in. Azure DevOps states no permission
97 * anywhere `az repos pr show` or `az repos pr list` reach: the answer lives in the security
98 * namespaces, behind identity descriptors and token paths that would be several calls per pull
99 * request to resolve.
100 *
101 * So the actions stay live and a viewer who may not take one is told so by Azure, at the moment
102 * they try. That is the safer half of an unknown: hiding a control from someone entitled to it
103 * leaves them no way through and no reason given.
104 */
105const AZURE_DEVOPS_VIEWER_PERMISSIONS: PullRequestViewerPermissions = {
106 actions: CAPABILITIES.actions,
107 comment: CAPABILITIES.comment,
108 resolve: CAPABILITIES.review.resolve,
109 verdicts: CAPABILITIES.review.verdicts,
110 requestReviewers: CAPABILITIES.reviewers.request,
111};
112​
113/** The CLI tags that mean the tool itself is unusable, rather than one request failing. */
114export function azureDevOpsProviderFailure(
115 error: AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCliError,
116): PullRequestProviderFailure {
117 if (error._tag === "AzureDevOpsCliUnavailableError") return { reason: "missing-tool" };
118 if (error._tag === "AzureDevOpsCliAuthenticationError") return { reason: "unauthenticated" };
119 if (error._tag === "AzureDevOpsCliRateLimitError") return { reason: "rate-limited" };
120 return { reason: "failed" };
122​
123function toChangeRequest(pullRequest: AzureDevOpsPullRequest): ProviderChangeRequest {
124 return {
125 number: pullRequest.number,
126 title: pullRequest.title,
127 url: pullRequest.url,
128 author: pullRequest.author,
129 headBranch: pullRequest.headBranch,
130 baseBranch: pullRequest.baseBranch,
131 state: pullRequest.state,
132 isDraft: pullRequest.isDraft,
133 mergeability: pullRequest.mergeability,
134 // Azure counts a pull request's files but never its lines, and counting them here would mean
135 // reading every file on both sides of every row of a listing.
136 additions: 0,
137 deletions: 0,
138 createdAt: pullRequest.createdAt,
139 closedAt: pullRequest.state === "closed" ? pullRequest.closedAt : null,
140 mergedAt: pullRequest.state === "merged" ? pullRequest.closedAt : null,
141 updatedAt: pullRequest.updatedAt,
142 reviewRequestLogins: pullRequest.reviewRequestLogins,
143 // Azure keeps labels on work items rather than on the pull request.
144 labels: [],
145 };
147​
148export const make = Effect.gen(function* () {
149 const cli = yield* AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli;
150 // Made once with the provider, which the registry builds once, so this is the whole build's
151 // allowance rather than one request's.
152 const diffSpawns = yield* Semaphore.make(MAX_DIFF_SPAWNS);
153 const readItemContent = (input: Parameters<typeof cli.readItemContent>[0]) =>
154 diffSpawns.withPermits(1)(cli.readItemContent(input));
155​
156 const fail =
157 (operation: string) => (error: AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCliError) =>
158 new PullRequestProviderError({
159 provider: "azure-devops",
160 operation,
161 ...azureDevOpsProviderFailure(error),
162 detail: error.detail,
163 cause: error,
164 });
165​
166 /** Refuses what the capabilities already say this host cannot do. */
167 const unsupported = (operation: string) =>
168 Effect.fail(
169 new PullRequestProviderError({
170 provider: "azure-devops",
171 operation,
172 reason: "failed",
173 detail: "Azure DevOps reviews cannot be written from here yet.",
174 }),
175 );
176​
177 /** A pull request Azure could not place has no diff to read, which reads as an empty one. */
178 const EMPTY_DIFF_SLICE: ProviderDiffSlice = { patch: "", truncated: false, nextCursor: null };
179​
180 /**
181 * Where a pull request's repository lives, which is the route every other read of it needs and
182 * the one thing only the pull request itself states. A pull request cannot move between
183 * repositories, so it is remembered rather than re-read: the marks alone would otherwise pay for
184 * a whole pull request read every time they checked whether a file had been pushed to. Least
185 * recently used, so a listing walking cold pull requests cannot evict the one being read.
186 */
187 const locations = new Map<string, AzureDevOpsRepositoryLocation>();
188​
189 const locationOf = (input: { readonly cwd: string; readonly number: number }) => {
190 const key = `${input.cwd} ${input.number}`;
191 const held = locations.get(key);
192 if (held !== undefined) {
193 locations.delete(key);
194 locations.set(key, held);
195 return Effect.succeed(held);
196 }
197 return cli.getPullRequest({ cwd: input.cwd, number: input.number }).pipe(
198 Effect.map((pullRequest) => {
199 const location = pullRequest.location;
200 if (location === null) return null;
201 if (locations.size >= LOCATION_CACHE_CAPACITY) {
202 const oldest = locations.keys().next().value;
203 if (oldest !== undefined) locations.delete(oldest);
204 }
205 locations.set(key, location);
206 return location;
207 }),
208 );
209 };
210​
211 /**
212 * Everything a diff read needs before it can ask for a file: where the repository lives, and
213 * which pushes the pull request has had. A client names neither, and the iterations are read
214 * afresh every time because the newest one is what a push adds.
215 */
216 const diffScope = (input: { readonly cwd: string; readonly number: number }) =>
217 Effect.gen(function* () {
218 const location = yield* locationOf(input);
219 if (location === null) return null;
220 const iterations = yield* cli.listIterations({
221 cwd: input.cwd,
222 location,
223 number: input.number,
224 });
225 return { location, iterations };
226 });
227​
228 const EMPTY_ITEM: AzureDevOpsItemContent = { contents: "", isBinary: false };
229​
230 /**
231 * Both sides of one changed file, read at once because neither answer depends on the other and
232 * `az` pays a Python interpreter's start-up for each. Only the sides a change actually has are
233 * asked for: Azure answers for a file that is not at a commit with a failure rather than with
234 * nothing.
235 */
236 const readTexts = (input: {
237 readonly cwd: string;
238 readonly location: AzureDevOpsRepositoryLocation;
239 readonly iteration: AzureDevOpsIteration;
240 readonly change: Pick<AzureDevOpsChangeEntry, "changeKind" | "path" | "oldPath">;
241 }) =>
242 Effect.all(
243 [
244 input.change.changeKind === "new"
245 ? Effect.succeed(EMPTY_ITEM)
246 : readItemContent({
247 cwd: input.cwd,
248 location: input.location,
249 path: input.change.oldPath,
250 commit: input.iteration.mergeBaseCommit,
251 }),
252 input.change.changeKind === "deleted"
253 ? Effect.succeed(EMPTY_ITEM)
254 : readItemContent({
255 cwd: input.cwd,
256 location: input.location,
257 path: input.change.path,
258 commit: input.iteration.headCommit,
259 }),
260 ],
261 { concurrency: 2 },
262 ).pipe(
263 Effect.map(([oldItem, newItem]): AzureDevOpsFileTexts => ({
264 oldContents: oldItem.contents,
265 newContents: newItem.contents,
266 // Azure hands a file it calls binary over in an encoding of its own, so its own word on
267 // that is taken rather than looked for in bytes it may never have sent verbatim.
268 binary: oldItem.isBinary || newItem.isBinary,
269 })),
270 );
271​
272 /**
273 * What the whole pull request changed, taken from its latest push. An iteration's changes are
274 * reported against the merge base rather than against the push before it, so the newest one is
275 * the whole of the change rather than the last slice of it.
276 */
277 const listLatestChanges = (input: {
278 readonly cwd: string;
279 readonly location: AzureDevOpsRepositoryLocation;
280 readonly number: number;
281 readonly iterations: ReadonlyArray<AzureDevOpsIteration>;
282 }) => {
283 const latest = input.iterations.at(-1);
284 return latest === undefined
285 ? Effect.succeed({
286 changes: [],
287 truncated: false,
288 } as AzureDevOpsPullRequestCli.AzureDevOpsIterationChanges)
289 : cli.listIterationChanges({
290 cwd: input.cwd,
291 location: input.location,
292 number: input.number,
293 iterationId: latest.id,
294 });
295 };
296​
297 const provider: PullRequestProviderApi = {
298 kind: "azure-devops",
299 capabilities: CAPABILITIES,
300​
301 getViewer: (input) =>
302 cli.getViewer({ cwd: input.cwd }).pipe(Effect.mapError(fail("getViewer"))),
303​
304 // `input.query` is deliberately dropped: `az repos pr list` filters by status, creator,
305 // reviewer and branch, and has nothing that matches text. Sending it as one of those would
306 // narrow by the wrong thing, so the page comes back unnarrowed and the caller filters it.
307 listChangeRequests: (input) =>
308 cli
309 .listPullRequests({
310 cwd: input.cwd,
311 repository: input.repository,
312 state: input.state,
313 involvement: input.involvement,
314 viewer: input.viewer,
315 limit: input.limit,
316 cursor: input.cursor,
317 })
318 .pipe(
319 Effect.mapError(fail("listChangeRequests")),
320 Effect.map((batch) => ({
321 items: batch.items.map(toChangeRequest),
322 truncated: batch.truncated,
323 cursorAdvance: batch.cursorAdvance,
324 // Azure answers in one order whether or not it is being carried on from, so a slice
325 // can always be stepped past — by counting, which is all Azure offers.
326 continues: true,
327 })),
328 ),
329​
330 // The polled path a linked thread's row stays live on: one `az` read, no iterations or
331 // changes behind it, since the file count that would cost is not shown here.
332 getChangeRequestSummary: (input) =>
333 cli.getPullRequest({ cwd: input.cwd, number: input.number }).pipe(
334 Effect.mapError(fail("getChangeRequestSummary")),
335 Effect.map((pullRequest): ProviderChangeRequestSummary => ({
336 number: pullRequest.number,
337 title: pullRequest.title,
338 url: pullRequest.url,
339 author: pullRequest.author,
340 headBranch: pullRequest.headBranch,
341 baseBranch: pullRequest.baseBranch,
342 state: pullRequest.state,
343 isDraft: pullRequest.isDraft,
344 mergeability: pullRequest.mergeability,
345 closedAt: pullRequest.state === "closed" ? pullRequest.closedAt : null,
346 mergedAt: pullRequest.state === "merged" ? pullRequest.closedAt : null,
347 updatedAt: pullRequest.updatedAt,
348 })),
349 ),
350​
351 getChangeRequest: (input) =>
352 Effect.gen(function* () {
353 const pullRequest = yield* cli.getPullRequest({ cwd: input.cwd, number: input.number });
354 const location = pullRequest.location;
355 // The file count is two reads past the pull request itself, and it is the only thing
356 // riding on them, so a failure leaves it unknown rather than losing the whole detail.
357 const changedFiles =
358 location === null
359 ? 0
360 : yield* cli.listIterations({ cwd: input.cwd, location, number: input.number }).pipe(
361 Effect.flatMap((iterations) =>
362 listLatestChanges({
363 cwd: input.cwd,
364 location,
365 number: input.number,
366 iterations,
367 }),
368 ),
369 Effect.map((listed) => listed.changes.length),
370 Effect.orElseSucceed(() => 0),
371 );
372 const detail: ProviderChangeRequestDetail = {
373 ...toChangeRequest(pullRequest),
374 body: pullRequest.body,
375 changedFiles,
376 mergedAt: pullRequest.state === "merged" ? pullRequest.closedAt : null,
377 closedAt: pullRequest.state === "closed" ? pullRequest.closedAt : null,
378 reviewers: pullRequest.reviewers,
379 checks: [],
380 mergeCapabilities: { merge: true, squash: true, rebase: false },
381 viewerPermissions: AZURE_DEVOPS_VIEWER_PERMISSIONS,
382 autoMergeEnabled: pullRequest.autoMergeEnabled,
383 ...(pullRequest.autoMergeMethod === undefined
384 ? {}
385 : { autoMergeMethod: pullRequest.autoMergeMethod }),
386 };
387 return detail;
388 }).pipe(Effect.mapError(fail("getChangeRequest"))),
389​
390 getChangeRequestActivity: (input) =>
391 cli.getPullRequest({ cwd: input.cwd, number: input.number }).pipe(
392 Effect.mapError(fail("getChangeRequestActivity")),
393 Effect.flatMap((pullRequest) =>
394 (pullRequest.location === null
395 ? Effect.succeed({ comments: [], truncated: true })
396 : cli
397 .listThreads({
398 cwd: input.cwd,
399 location: pullRequest.location,
400 number: input.number,
401 })
402 .pipe(
403 Effect.map((comments) => ({ comments, truncated: false })),
404 Effect.orElseSucceed(() => ({ comments: [], truncated: true })),
405 )
406 ).pipe(
407 Effect.map((conversation): ProviderChangeRequestActivity => ({
408 comments: conversation.comments,
409 commentCount: conversation.comments.length,
410 commentsTruncated: conversation.truncated,
411 reviewThreads: [],
412 commits: [],
413 })),
414 ),
415 ),
416 ),
417​
418 // No request at all: Azure has nothing to say about the viewer that a pull request read can
419 // reach, so the answer is the same constant the detail carries.
420 getViewerPermissions: () => Effect.succeed(AZURE_DEVOPS_VIEWER_PERMISSIONS),
421​
422 // `input.commit` is deliberately dropped: Azure states no commit list on a pull request, so
423 // the Code tab has nothing to scope itself to and always asks for the whole change.
424 getDiff: (input) =>
425 Effect.gen(function* () {
426 const scope = yield* diffScope(input);
427 if (scope === null) return EMPTY_DIFF_SLICE;
428 const cursor = parseAzureDevOpsDiffCursor(input.cursor);
429 // Reading on stays with the push the first slice was taken against. A push landing
430 // mid-read would otherwise renumber the files and hand the reader one twice, or none.
431 const iteration =
432 cursor === null
433 ? scope.iterations.at(-1)
434 : scope.iterations.find((candidate) => candidate.id === cursor.iterationId);
435 if (iteration === undefined) return EMPTY_DIFF_SLICE;
436 const listed = yield* cli.listIterationChanges({
437 cwd: input.cwd,
438 location: scope.location,
439 number: input.number,
440 iterationId: iteration.id,
441 });
442 const changes = listed.changes;
443​
444 const sections: string[] = [];
445 let truncated = listed.truncated;
446 let bytes = 0;
447 let edits = 0;
448 let index = cursor?.fileIndex ?? 0;
449 let full = false;
450 // How many files to read at once. Every file costs a request a side, and everything read
451 // past the point the slice fills is thrown away and read again by the next slice, so the
452 // batch narrows as the budgets do: what is left of each, over what a file has spent of it
453 // on average so far, which is the only estimate there is before a file is read. At least
454 // one, so a file heavier than the whole budget still moves the cursor.
455 const batchWidth = () => {
456 if (sections.length === 0) return DIFF_FILE_CONCURRENCY;
457 const admits = (left: number, spent: number) =>
458 Math.ceil(left / Math.max(1, spent / sections.length));
459 return Math.max(
460 1,
461 Math.min(
462 DIFF_FILE_CONCURRENCY,
463 // The file budget needs no estimate: a file spends exactly one of it.
464 MAX_DIFF_SLICE_FILES - sections.length,
465 admits(MAX_DIFF_SLICE_BYTES - bytes, bytes),
466 admits(MAX_DIFF_SLICE_EDITS - MAX_FILE_DIFF_EDITS - edits, edits),
467 ),
468 );
469 };
470 while (!full && index < changes.length) {
471 const batch = changes.slice(index, index + batchWidth());
472 const read = yield* Effect.forEach(
473 batch,
474 (change) =>
475 // A pair Azure refuses is one file rather than the whole slice: an oversize blob or
476 // a path `az` will not carry through leaves that file listed without its hunks, and
477 // everything around it still renders.
478 readTexts({ cwd: input.cwd, location: scope.location, iteration, change }).pipe(
479 // Only what is this one file's problem. A signed-out CLI, a rate limit or no `az`
480 // at all is the read failing rather than the file, and belongs to the caller,
481 // which pauses the host rather than showing every file as unreadable.
482 Effect.catchTags({
483 AzureDevOpsPullRequestNotFoundError: () => Effect.succeed(null),
484 AzureDevOpsCommandFailedError: () => Effect.succeed(null),
485 AzureDevOpsPullRequestReadError: () => Effect.succeed(null),
486 }),
487 Effect.map((texts) => ({ change, texts })),
488 ),
489 { concurrency: DIFF_FILE_CONCURRENCY },
490 );
491 for (const { change, texts } of read) {
492 // The diff is synchronous and the reads no longer stand between one file and the next
493 // to let anything else on the server run, so the thread is handed back here.
494 yield* Effect.yieldNow;
495 const file =
496 texts === null
497 ? azureDevOpsUnreadableFilePatch(change)
498 : azureDevOpsFilePatch({ change, texts });
499 sections.push(file.section);
500 bytes += byteLength(file.section);
501 edits += file.edits;
502 truncated = truncated || file.truncated;
503 index += 1;
504 // A file whose diff was given up on spent the whole of what one file is allowed and
505 // has only a header to show for it, and a file the diff never ran on at all weighs
506 // almost nothing in either budget and still costs its two reads. So the file count
507 // bounds the request alongside the bytes.
508 // Checked after the file is added rather than before it, so every slice carries at
509 // least one: a section heavier than the whole budget would otherwise never be added,
510 // and the read would answer the same slice forever without moving the cursor.
511 if (
512 bytes >= MAX_DIFF_SLICE_BYTES ||
513 edits + MAX_FILE_DIFF_EDITS > MAX_DIFF_SLICE_EDITS ||
514 sections.length >= MAX_DIFF_SLICE_FILES ||
515 file.abandoned
516 ) {
517 full = true;
518 break;
519 }
520 }
521 }
522​
523 const slice: ProviderDiffSlice = {
524 patch: sections.join(""),
525 truncated,
526 nextCursor:
527 index >= changes.length
528 ? null
529 : formatAzureDevOpsDiffCursor({ iterationId: iteration.id, fileIndex: index }),
530 };
531 return slice;
532 }).pipe(Effect.mapError(fail("getDiff"))),
533​
534 // The patch is built from whole files, so opening the lines around a hunk is the same two
535 // reads over again rather than a wider request. Read against the latest iteration: nothing in
536 // the request says which push the reader is looking at, and expansion is stale after a
537 // mid-review push on every host here anyway.
538 getDiffFileContents: (input) =>
539 Effect.gen(function* () {
540 const scope = yield* diffScope(input);
541 const iteration = scope?.iterations.at(-1);
542 if (scope === null || iteration === undefined) return { oldContents: "", newContents: "" };
543 return yield* readTexts({
544 cwd: input.cwd,
545 location: scope.location,
546 iteration,
547 change: {
548 changeKind: input.changeType,
549 path: input.newPath,
550 oldPath: input.oldPath,
551 },
552 });
553 }).pipe(Effect.mapError(fail("getDiffFileContents"))),
554​
555 /**
556 * What the head has of each marked file, which is the blob Azure already names on the change
557 * it reports. One read covers every path, since the latest iteration lists the whole change.
558 *
559 * A path the change does not carry is at the empty revision, which is where a file the pull
560 * request deletes sits. When the change was too long to follow to its end, those paths are
561 * left out instead: reporting them as deleted would clear a file nobody has read.
562 */
563 getFileRevisions: (input) =>
564 Effect.gen(function* () {
565 const revisions = new Map<string, string>();
566 if (input.paths.length === 0) return { revisions };
567 const scope = yield* diffScope(input);
568 if (scope === null) return { revisions };
569 const listed = yield* listLatestChanges({
570 ...scope,
571 cwd: input.cwd,
572 number: input.number,
573 });
574 const marked = new Set(input.paths);
575 for (const change of listed.changes) {
576 if (!marked.has(change.path) || change.objectId === null) continue;
577 revisions.set(change.path, change.objectId);
578 }
579 if (!listed.truncated) {
580 for (const path of input.paths) {
581 if (!revisions.has(path)) revisions.set(path, "");
582 }
583 }
584 return { revisions };
585 }).pipe(Effect.mapError(fail("getFileRevisions"))),
586​
587 runAction: (input) =>
588 cli
589 .runPullRequestAction({
590 cwd: input.cwd,
591 number: input.number,
592 action: input.action,
593 ...(input.mergeMethod === undefined ? {} : { mergeMethod: input.mergeMethod }),
594 })
595 .pipe(Effect.mapError(fail("runAction"))),
596​
597 updateChangeRequest: (input) =>
598 cli
599 .updatePullRequest({
600 cwd: input.cwd,
601 number: input.number,
602 title: input.title,
603 body: input.body,
604 })
605 .pipe(Effect.mapError(fail("updateChangeRequest"))),
606​
607 // Never called: `capabilities.reviewers.listCandidates` is false, and the service refuses the
608 // list without it.
609 listReviewerCandidates: () =>
610 Effect.fail(
611 new PullRequestProviderError({
612 provider: "azure-devops",
613 operation: "listReviewerCandidates",
614 reason: "failed",
615 detail: "Azure DevOps cannot say who may review a pull request.",
616 }),
617 ),
618​
619 setReviewerRequest: (input) =>
620 cli
621 .setPullRequestReviewers({
622 cwd: input.cwd,
623 number: input.number,
624 // Azure names an identity by an email address or a guid, and has no team to ask, so a
625 // candidate's id is the whole of what it takes.
626 reviewers: input.reviewers.map((reviewer) => reviewer.id),
627 requested: input.requested,
628 })
629 .pipe(Effect.mapError(fail("setReviewerRequest"))),
630​
631 // Never called: `capabilities.comment` is false, and the service refuses a comment without it.
632 comment: () => unsupported("comment"),
633​
634 // Declared unsupported above, so the service refuses these before a provider is reached.
635 // They exist because every provider answers the whole port.
636 submitReview: () => unsupported("submitReview"),
637​
638 replyToThread: () => unsupported("replyToThread"),
639​
640 setThreadResolution: () => unsupported("setThreadResolution"),
641​
642 setReaction: () => unsupported("setReaction"),
643 };
644​
645 return provider;
646});