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

AzureDevOpsPullRequestProvider.ts

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