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

AzureDevOpsPullRequestProvider.ts

647 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 if (error._tag === "AzureDevOpsPullRequestNotFoundError") return { reason: "not-found" };
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({
287 changes: [],
288 truncated: false,
289 } as AzureDevOpsPullRequestCli.AzureDevOpsIterationChanges)
290 : cli.listIterationChanges({
291 cwd: input.cwd,
292 location: input.location,
293 number: input.number,
294 iterationId: latest.id,
295 });
296 };
297​
298 const provider: PullRequestProviderApi = {
299 kind: "azure-devops",
300 capabilities: CAPABILITIES,
301​
302 getViewer: (input) =>
303 cli.getViewer({ cwd: input.cwd }).pipe(Effect.mapError(fail("getViewer"))),
304​
305 // `input.query` is deliberately dropped: `az repos pr list` filters by status, creator,
306 // reviewer and branch, and has nothing that matches text. Sending it as one of those would
307 // narrow by the wrong thing, so the page comes back unnarrowed and the caller filters it.
308 listChangeRequests: (input) =>
309 cli
310 .listPullRequests({
311 cwd: input.cwd,
312 repository: input.repository,
313 state: input.state,
314 involvement: input.involvement,
315 viewer: input.viewer,
316 limit: input.limit,
317 cursor: input.cursor,
318 })
319 .pipe(
320 Effect.mapError(fail("listChangeRequests")),
321 Effect.map((batch) => ({
322 items: batch.items.map(toChangeRequest),
323 truncated: batch.truncated,
324 cursorAdvance: batch.cursorAdvance,
325 // Azure answers in one order whether or not it is being carried on from, so a slice
326 // can always be stepped past — by counting, which is all Azure offers.
327 continues: true,
328 })),
329 ),
330​
331 // The polled path a linked thread's row stays live on: one `az` read, no iterations or
332 // changes behind it, since the file count that would cost is not shown here.
333 getChangeRequestSummary: (input) =>
334 cli.getPullRequest({ cwd: input.cwd, number: input.number }).pipe(
335 Effect.mapError(fail("getChangeRequestSummary")),
336 Effect.map((pullRequest): ProviderChangeRequestSummary => ({
337 number: pullRequest.number,
338 title: pullRequest.title,
339 url: pullRequest.url,
340 author: pullRequest.author,
341 headBranch: pullRequest.headBranch,
342 baseBranch: pullRequest.baseBranch,
343 state: pullRequest.state,
344 isDraft: pullRequest.isDraft,
345 mergeability: pullRequest.mergeability,
346 closedAt: pullRequest.state === "closed" ? pullRequest.closedAt : null,
347 mergedAt: pullRequest.state === "merged" ? pullRequest.closedAt : null,
348 updatedAt: pullRequest.updatedAt,
349 })),
350 ),
351​
352 getChangeRequest: (input) =>
353 Effect.gen(function* () {
354 const pullRequest = yield* cli.getPullRequest({ cwd: input.cwd, number: input.number });
355 const location = pullRequest.location;
356 // The file count is two reads past the pull request itself, and it is the only thing
357 // riding on them, so a failure leaves it unknown rather than losing the whole detail.
358 const changedFiles =
359 location === null
360 ? 0
361 : yield* cli.listIterations({ cwd: input.cwd, location, number: input.number }).pipe(
362 Effect.flatMap((iterations) =>
363 listLatestChanges({
364 cwd: input.cwd,
365 location,
366 number: input.number,
367 iterations,
368 }),
369 ),
370 Effect.map((listed) => listed.changes.length),
371 Effect.orElseSucceed(() => 0),
372 );
373 const detail: ProviderChangeRequestDetail = {
374 ...toChangeRequest(pullRequest),
375 body: pullRequest.body,
376 changedFiles,
377 mergedAt: pullRequest.state === "merged" ? pullRequest.closedAt : null,
378 closedAt: pullRequest.state === "closed" ? pullRequest.closedAt : null,
379 reviewers: pullRequest.reviewers,
380 checks: [],
381 mergeCapabilities: { merge: true, squash: true, rebase: false },
382 viewerPermissions: AZURE_DEVOPS_VIEWER_PERMISSIONS,
383 autoMergeEnabled: pullRequest.autoMergeEnabled,
384 ...(pullRequest.autoMergeMethod === undefined
385 ? {}
386 : { autoMergeMethod: pullRequest.autoMergeMethod }),
387 };
388 return detail;
389 }).pipe(Effect.mapError(fail("getChangeRequest"))),
390​
391 getChangeRequestActivity: (input) =>
392 cli.getPullRequest({ cwd: input.cwd, number: input.number }).pipe(
393 Effect.mapError(fail("getChangeRequestActivity")),
394 Effect.flatMap((pullRequest) =>
395 (pullRequest.location === null
396 ? Effect.succeed({ comments: [], truncated: true })
397 : cli
398 .listThreads({
399 cwd: input.cwd,
400 location: pullRequest.location,
401 number: input.number,
402 })
403 .pipe(
404 Effect.map((comments) => ({ comments, truncated: false })),
405 Effect.orElseSucceed(() => ({ comments: [], truncated: true })),
406 )
407 ).pipe(
408 Effect.map((conversation): ProviderChangeRequestActivity => ({
409 comments: conversation.comments,
410 commentCount: conversation.comments.length,
411 commentsTruncated: conversation.truncated,
412 reviewThreads: [],
413 commits: [],
414 })),
415 ),
416 ),
417 ),
418​
419 // No request at all: Azure has nothing to say about the viewer that a pull request read can
420 // reach, so the answer is the same constant the detail carries.
421 getViewerPermissions: () => Effect.succeed(AZURE_DEVOPS_VIEWER_PERMISSIONS),
422​
423 // `input.commit` is deliberately dropped: Azure states no commit list on a pull request, so
424 // the Code tab has nothing to scope itself to and always asks for the whole change.
425 getDiff: (input) =>
426 Effect.gen(function* () {
427 const scope = yield* diffScope(input);
428 if (scope === null) return EMPTY_DIFF_SLICE;
429 const cursor = parseAzureDevOpsDiffCursor(input.cursor);
430 // Reading on stays with the push the first slice was taken against. A push landing
431 // mid-read would otherwise renumber the files and hand the reader one twice, or none.
432 const iteration =
433 cursor === null
434 ? scope.iterations.at(-1)
435 : scope.iterations.find((candidate) => candidate.id === cursor.iterationId);
436 if (iteration === undefined) return EMPTY_DIFF_SLICE;
437 const listed = yield* cli.listIterationChanges({
438 cwd: input.cwd,
439 location: scope.location,
440 number: input.number,
441 iterationId: iteration.id,
442 });
443 const changes = listed.changes;
444​
445 const sections: string[] = [];
446 let truncated = listed.truncated;
447 let bytes = 0;
448 let edits = 0;
449 let index = cursor?.fileIndex ?? 0;
450 let full = false;
451 // How many files to read at once. Every file costs a request a side, and everything read
452 // past the point the slice fills is thrown away and read again by the next slice, so the
453 // batch narrows as the budgets do: what is left of each, over what a file has spent of it
454 // on average so far, which is the only estimate there is before a file is read. At least
455 // one, so a file heavier than the whole budget still moves the cursor.
456 const batchWidth = () => {
457 if (sections.length === 0) return DIFF_FILE_CONCURRENCY;
458 const admits = (left: number, spent: number) =>
459 Math.ceil(left / Math.max(1, spent / sections.length));
460 return Math.max(
461 1,
462 Math.min(
463 DIFF_FILE_CONCURRENCY,
464 // The file budget needs no estimate: a file spends exactly one of it.
465 MAX_DIFF_SLICE_FILES - sections.length,
466 admits(MAX_DIFF_SLICE_BYTES - bytes, bytes),
467 admits(MAX_DIFF_SLICE_EDITS - MAX_FILE_DIFF_EDITS - edits, edits),
468 ),
469 );
470 };
471 while (!full && index < changes.length) {
472 const batch = changes.slice(index, index + batchWidth());
473 const read = yield* Effect.forEach(
474 batch,
475 (change) =>
476 // A pair Azure refuses is one file rather than the whole slice: an oversize blob or
477 // a path `az` will not carry through leaves that file listed without its hunks, and
478 // everything around it still renders.
479 readTexts({ cwd: input.cwd, location: scope.location, iteration, change }).pipe(
480 // Only what is this one file's problem. A signed-out CLI, a rate limit or no `az`
481 // at all is the read failing rather than the file, and belongs to the caller,
482 // which pauses the host rather than showing every file as unreadable.
483 Effect.catchTags({
484 AzureDevOpsPullRequestNotFoundError: () => Effect.succeed(null),
485 AzureDevOpsCommandFailedError: () => Effect.succeed(null),
486 AzureDevOpsPullRequestReadError: () => Effect.succeed(null),
487 }),
488 Effect.map((texts) => ({ change, texts })),
489 ),
490 { concurrency: DIFF_FILE_CONCURRENCY },
491 );
492 for (const { change, texts } of read) {
493 // The diff is synchronous and the reads no longer stand between one file and the next
494 // to let anything else on the server run, so the thread is handed back here.
495 yield* Effect.yieldNow;
496 const file =
497 texts === null
498 ? azureDevOpsUnreadableFilePatch(change)
499 : azureDevOpsFilePatch({ change, texts });
500 sections.push(file.section);
501 bytes += byteLength(file.section);
502 edits += file.edits;
503 truncated = truncated || file.truncated;
504 index += 1;
505 // A file whose diff was given up on spent the whole of what one file is allowed and
506 // has only a header to show for it, and a file the diff never ran on at all weighs
507 // almost nothing in either budget and still costs its two reads. So the file count
508 // bounds the request alongside the bytes.
509 // Checked after the file is added rather than before it, so every slice carries at
510 // least one: a section heavier than the whole budget would otherwise never be added,
511 // and the read would answer the same slice forever without moving the cursor.
512 if (
513 bytes >= MAX_DIFF_SLICE_BYTES ||
514 edits + MAX_FILE_DIFF_EDITS > MAX_DIFF_SLICE_EDITS ||
515 sections.length >= MAX_DIFF_SLICE_FILES ||
516 file.abandoned
517 ) {
518 full = true;
519 break;
520 }
521 }
522 }
523​
524 const slice: ProviderDiffSlice = {
525 patch: sections.join(""),
526 truncated,
527 nextCursor:
528 index >= changes.length
529 ? null
530 : formatAzureDevOpsDiffCursor({ iterationId: iteration.id, fileIndex: index }),
531 };
532 return slice;
533 }).pipe(Effect.mapError(fail("getDiff"))),
534​
535 // The patch is built from whole files, so opening the lines around a hunk is the same two
536 // reads over again rather than a wider request. Read against the latest iteration: nothing in
537 // the request says which push the reader is looking at, and expansion is stale after a
538 // mid-review push on every host here anyway.
539 getDiffFileContents: (input) =>
540 Effect.gen(function* () {
541 const scope = yield* diffScope(input);
542 const iteration = scope?.iterations.at(-1);
543 if (scope === null || iteration === undefined) return { oldContents: "", newContents: "" };
544 return yield* readTexts({
545 cwd: input.cwd,
546 location: scope.location,
547 iteration,
548 change: {
549 changeKind: input.changeType,
550 path: input.newPath,
551 oldPath: input.oldPath,
552 },
553 });
554 }).pipe(Effect.mapError(fail("getDiffFileContents"))),
555​
556 /**
557 * What the head has of each marked file, which is the blob Azure already names on the change
558 * it reports. One read covers every path, since the latest iteration lists the whole change.
559 *
560 * A path the change does not carry is at the empty revision, which is where a file the pull
561 * request deletes sits. When the change was too long to follow to its end, those paths are
562 * left out instead: reporting them as deleted would clear a file nobody has read.
563 */
564 getFileRevisions: (input) =>
565 Effect.gen(function* () {
566 const revisions = new Map<string, string>();
567 if (input.paths.length === 0) return { revisions };
568 const scope = yield* diffScope(input);
569 if (scope === null) return { revisions };
570 const listed = yield* listLatestChanges({
571 ...scope,
572 cwd: input.cwd,
573 number: input.number,
574 });
575 const marked = new Set(input.paths);
576 for (const change of listed.changes) {
577 if (!marked.has(change.path) || change.objectId === null) continue;
578 revisions.set(change.path, change.objectId);
579 }
580 if (!listed.truncated) {
581 for (const path of input.paths) {
582 if (!revisions.has(path)) revisions.set(path, "");
583 }
584 }
585 return { revisions };
586 }).pipe(Effect.mapError(fail("getFileRevisions"))),
587​
588 runAction: (input) =>
589 cli
590 .runPullRequestAction({
591 cwd: input.cwd,
592 number: input.number,
593 action: input.action,
594 ...(input.mergeMethod === undefined ? {} : { mergeMethod: input.mergeMethod }),
595 })
596 .pipe(Effect.mapError(fail("runAction"))),
597​
598 updateChangeRequest: (input) =>
599 cli
600 .updatePullRequest({
601 cwd: input.cwd,
602 number: input.number,
603 title: input.title,
604 body: input.body,
605 })
606 .pipe(Effect.mapError(fail("updateChangeRequest"))),
607​
608 // Never called: `capabilities.reviewers.listCandidates` is false, and the service refuses the
609 // list without it.
610 listReviewerCandidates: () =>
611 Effect.fail(
612 new PullRequestProviderError({
613 provider: "azure-devops",
614 operation: "listReviewerCandidates",
615 reason: "failed",
616 detail: "Azure DevOps cannot say who may review a pull request.",
617 }),
618 ),
619​
620 setReviewerRequest: (input) =>
621 cli
622 .setPullRequestReviewers({
623 cwd: input.cwd,
624 number: input.number,
625 // Azure names an identity by an email address or a guid, and has no team to ask, so a
626 // candidate's id is the whole of what it takes.
627 reviewers: input.reviewers.map((reviewer) => reviewer.id),
628 requested: input.requested,
629 })
630 .pipe(Effect.mapError(fail("setReviewerRequest"))),
631​
632 // Never called: `capabilities.comment` is false, and the service refuses a comment without it.
633 comment: () => unsupported("comment"),
634​
635 // Declared unsupported above, so the service refuses these before a provider is reached.
636 // They exist because every provider answers the whole port.
637 submitReview: () => unsupported("submitReview"),
638​
639 replyToThread: () => unsupported("replyToThread"),
640​
641 setThreadResolution: () => unsupported("setThreadResolution"),
642​
643 setReaction: () => unsupported("setReaction"),
644 };
645​
646 return provider;
647});