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