Open History to see the last commit
1import {
2 trimOptionalString as trimmed,
3 normalizeRefName,
4} from "@t3tools/source-control-core/server/pullRequestUtils";
5import * as Cause from "effect/Cause";
6import * as Exit from "effect/Exit";
7import * as Result from "effect/Result";
8import * as Schema from "effect/Schema";
9import type {
10 PullRequestActor,
11 PullRequestCheck,
12 PullRequestComment,
13 PullRequestMergeMethod,
14 PullRequestMergeability,
15 PullRequestState,
16} from "@t3tools/contracts";
17import { TrimmedNonEmptyString } from "@t3tools/contracts";
18import { decodeJsonResult } from "@t3tools/shared/schemaJson";
19
20import { azureDevOpsPullRequestWebUrl } from "./azureDevOpsPullRequests.ts";
21
22// CLI fields vary by command; unknown enum values must not fail the payload.
23const RawIdentitySchema = Schema.Struct({
24 displayName: Schema.optional(Schema.NullOr(Schema.String)),
25 uniqueName: Schema.optional(Schema.NullOr(Schema.String)),
26 imageUrl: Schema.optional(Schema.NullOr(Schema.String)),
27});
28
29const RawPullRequestSchema = Schema.Struct({
30 pullRequestId: Schema.Int,
31 title: Schema.String,
32 description: Schema.optional(Schema.NullOr(Schema.String)),
33 status: Schema.optional(Schema.NullOr(Schema.String)),
34 isDraft: Schema.optional(Schema.NullOr(Schema.Boolean)),
35 /** This identity's presence indicates auto-complete. */
36 autoCompleteSetBy: Schema.optional(Schema.NullOr(RawIdentitySchema)),
37 completionOptions: Schema.optional(
38 Schema.NullOr(
39 Schema.Struct({
40 mergeStrategy: Schema.optional(Schema.NullOr(Schema.String)),
41 squashMerge: Schema.optional(Schema.NullOr(Schema.Boolean)),
42 }),
43 ),
44 ),
45 mergeStatus: Schema.optional(Schema.NullOr(Schema.String)),
46 createdBy: Schema.optional(Schema.NullOr(RawIdentitySchema)),
47 reviewers: Schema.optional(Schema.NullOr(Schema.Array(RawIdentitySchema))),
48 sourceRefName: TrimmedNonEmptyString,
49 targetRefName: TrimmedNonEmptyString,
50 creationDate: TrimmedNonEmptyString,
51 closedDate: Schema.optional(Schema.NullOr(Schema.String)),
52 url: Schema.optional(Schema.NullOr(Schema.String)),
53 repository: Schema.optional(
54 Schema.NullOr(
55 Schema.Struct({
56 name: Schema.optional(Schema.NullOr(Schema.String)),
57 webUrl: Schema.optional(Schema.NullOr(Schema.String)),
58 project: Schema.optional(
59 Schema.NullOr(Schema.Struct({ name: Schema.optional(Schema.NullOr(Schema.String)) })),
60 ),
61 }),
62 ),
63 ),
64 _links: Schema.optional(
65 Schema.NullOr(
66 Schema.Struct({
67 web: Schema.optional(
68 Schema.NullOr(Schema.Struct({ href: Schema.optional(Schema.String) })),
69 ),
70 }),
71 ),
72 ),
73});
74
75const RawThreadSchema = Schema.Struct({
76 id: Schema.Int,
77 isDeleted: Schema.optional(Schema.NullOr(Schema.Boolean)),
78 threadContext: Schema.optional(
79 Schema.NullOr(Schema.Struct({ filePath: Schema.optional(Schema.NullOr(Schema.String)) })),
80 ),
81 comments: Schema.optional(
82 Schema.NullOr(
83 Schema.Array(
84 Schema.Struct({
85 id: Schema.optional(Schema.NullOr(Schema.Int)),
86 content: Schema.optional(Schema.NullOr(Schema.String)),
87 author: Schema.optional(Schema.NullOr(RawIdentitySchema)),
88 publishedDate: Schema.optional(Schema.NullOr(Schema.String)),
89 isDeleted: Schema.optional(Schema.NullOr(Schema.Boolean)),
90 commentType: Schema.optional(Schema.NullOr(Schema.String)),
91 }),
92 ),
93 ),
94 ),
95});
96
97const RawThreadPageSchema = Schema.Struct({
98 value: Schema.Array(Schema.Unknown),
99});
100
101const RawViewerSchema = Schema.Struct({
102 user: Schema.optional(
103 Schema.NullOr(Schema.Struct({ name: Schema.optional(Schema.NullOr(Schema.String)) })),
104 ),
105});
106
107const RawPolicyEvaluationSchema = Schema.Struct({
108 status: Schema.String,
109 context: Schema.optional(
110 Schema.NullOr(
111 Schema.Struct({
112 buildId: Schema.optional(Schema.NullOr(Schema.Int)),
113 buildDefinitionName: Schema.optional(Schema.NullOr(Schema.String)),
114 isExpired: Schema.optional(Schema.NullOr(Schema.Boolean)),
115 }),
116 ),
117 ),
118 configuration: Schema.Struct({
119 url: Schema.optional(Schema.NullOr(Schema.String)),
120 isBlocking: Schema.optional(Schema.NullOr(Schema.Boolean)),
121 isEnabled: Schema.optional(Schema.NullOr(Schema.Boolean)),
122 isDeleted: Schema.optional(Schema.NullOr(Schema.Boolean)),
123 type: Schema.Struct({
124 id: Schema.String,
125 displayName: Schema.optional(Schema.NullOr(Schema.String)),
126 }),
127 settings: Schema.optional(
128 Schema.NullOr(
129 Schema.Struct({
130 displayName: Schema.optional(Schema.NullOr(Schema.String)),
131 defaultDisplayName: Schema.optional(Schema.NullOr(Schema.String)),
132 statusName: Schema.optional(Schema.NullOr(Schema.String)),
133 manualQueueOnly: Schema.optional(Schema.NullOr(Schema.Boolean)),
134 }),
135 ),
136 ),
137 }),
138});
139
140export interface AzureDevOpsRepositoryLocation {
141 readonly project: string;
142 readonly repository: string;
143}
144
145export interface AzureDevOpsPullRequest {
146 readonly number: number;
147 readonly title: string;
148 readonly url: string;
149 readonly author: PullRequestActor | null;
150 readonly headBranch: string;
151 readonly baseBranch: string;
152 readonly state: PullRequestState;
153 readonly isDraft: boolean;
154 readonly mergeability: PullRequestMergeability;
155 readonly createdAt: string;
156 readonly updatedAt: string;
157 readonly closedAt: string | null;
158 readonly body: string;
159 readonly reviewRequestLogins: ReadonlyArray<string>;
160 readonly reviewers: ReadonlyArray<PullRequestActor>;
161 readonly location: AzureDevOpsRepositoryLocation | null;
162 readonly autoMergeEnabled: boolean;
163 readonly autoMergeMethod?: PullRequestMergeMethod;
164}
165
166/** Logins must match the email from `az account show`. */
167function toActor(raw: Schema.Schema.Type<typeof RawIdentitySchema> | null | undefined) {
168 const login = trimmed(raw?.uniqueName) ?? trimmed(raw?.displayName);
169 return login === null
170 ? null
171 : { login, name: trimmed(raw?.displayName), avatarUrl: trimmed(raw?.imageUrl) };
172}
173
174function toState(raw: Schema.Schema.Type<typeof RawPullRequestSchema>): PullRequestState {
175 switch (raw.status?.trim().toLowerCase()) {
176 case "completed":
177 return "merged";
178 case "abandoned":
179 return "closed";
180 default:
181 return "open";
182 }
183}
184
185function toMergeability(value: string | null | undefined): PullRequestMergeability {
186 switch (value?.trim().toLowerCase()) {
187 case "succeeded":
188 return "mergeable";
189 case "conflicts":
190 case "failure":
191 case "rejectedbypolicy":
192 return "conflicting";
193 default:
194 return "unknown";
195 }
196}
197
198function toLocation(
199 raw: Schema.Schema.Type<typeof RawPullRequestSchema>,
200): AzureDevOpsRepositoryLocation | null {
201 const project = trimmed(raw.repository?.project?.name);
202 const repository = trimmed(raw.repository?.name);
203 if (project === null || repository === null) return null;
204 return { project, repository };
205}
206
207function toAutoMergeMethod(
208 raw: Schema.Schema.Type<typeof RawPullRequestSchema>,
209): PullRequestMergeMethod | undefined {
210 if (raw.autoCompleteSetBy == null) return undefined;
211 switch (raw.completionOptions?.mergeStrategy?.trim().toLowerCase()) {
212 case "squash":
213 return "squash";
214 case "rebase":
215 case "rebasemerge":
216 return "rebase";
217 case "nofastforward":
218 return "merge";
219 default:
220 return raw.completionOptions?.squashMerge === true ? "squash" : undefined;
221 }
222}
223
224function toPullRequest(
225 raw: Schema.Schema.Type<typeof RawPullRequestSchema>,
226): AzureDevOpsPullRequest | null {
227 const autoMergeMethod = toAutoMergeMethod(raw);
228 const reviewers = (raw.reviewers ?? []).flatMap((reviewer) => {
229 const actor = toActor(reviewer);
230 return actor === null ? [] : [actor];
231 });
232 const closedAt = trimmed(raw.closedDate);
233 const url = trimmed(
234 azureDevOpsPullRequestWebUrl({
235 pullRequestId: raw.pullRequestId,
236 webLink: raw._links?.web?.href,
237 repositoryWebUrl: raw.repository?.webUrl,
238 restApiUrl: raw.url,
239 projectName: raw.repository?.project?.name,
240 repositoryName: raw.repository?.name,
241 }),
242 );
243 const headBranch = trimmed(normalizeRefName(raw.sourceRefName));
244 const baseBranch = trimmed(normalizeRefName(raw.targetRefName));
245 if (url === null || headBranch === null || baseBranch === null) return null;
246 return {
247 number: raw.pullRequestId,
248 title: raw.title,
249 url,
250 author: toActor(raw.createdBy),
251 headBranch,
252 baseBranch,
253 state: toState(raw),
254 isDraft: raw.isDraft ?? false,
255 mergeability: toMergeability(raw.mergeStatus),
256 createdAt: raw.creationDate,
257 updatedAt: closedAt ?? raw.creationDate,
258 closedAt,
259 body: raw.description ?? "",
260 reviewRequestLogins: reviewers.map((reviewer) => reviewer.login),
261 reviewers,
262 location: toLocation(raw),
263 autoMergeEnabled: (raw.autoCompleteSetBy ?? null) !== null,
264 ...(autoMergeMethod === undefined ? {} : { autoMergeMethod }),
265 };
266}
267
268const decodeUnknownList = decodeJsonResult(Schema.Array(Schema.Unknown));
269const decodePullRequestEntry = Schema.decodeUnknownExit(RawPullRequestSchema);
270const decodePullRequest = decodeJsonResult(RawPullRequestSchema);
271const decodeThreadPage = decodeJsonResult(RawThreadPageSchema);
272const decodeThreadEntry = Schema.decodeUnknownExit(RawThreadSchema);
273const decodeViewer = decodeJsonResult(RawViewerSchema);
274const decodePolicyEvaluations = decodeJsonResult(Schema.Array(RawPolicyEvaluationSchema));
275
276type DecodeFailure = Cause.Cause<Schema.SchemaError>;
277
278export interface AzureDevOpsPullRequestBatch {
279 readonly items: ReadonlyArray<AzureDevOpsPullRequest>;
280 readonly rawIndexes: ReadonlyArray<number>;
281 /** Count before decoding to avoid ending pagination on skipped rows. */
282 readonly rawCount: number;
283}
284
285export function decodePullRequestListJson(
286 raw: string,
287): Result.Result<AzureDevOpsPullRequestBatch, DecodeFailure> {
288 const decoded = decodeUnknownList(raw);
289 if (!Result.isSuccess(decoded)) {
290 return Result.fail(decoded.failure);
291 }
292 const items: AzureDevOpsPullRequest[] = [];
293 const rawIndexes: number[] = [];
294 for (const [rawIndex, entry] of decoded.success.entries()) {
295 const item = decodePullRequestEntry(entry);
296 if (Exit.isFailure(item)) continue;
297 const pullRequest = toPullRequest(item.value);
298 if (pullRequest !== null) {
299 items.push(pullRequest);
300 rawIndexes.push(rawIndex);
301 }
302 }
303 return Result.succeed({ items, rawIndexes, rawCount: decoded.success.length });
304}
305
306/** Null means Azure returned insufficient data. */
307export function decodePullRequestJson(
308 raw: string,
309): Result.Result<AzureDevOpsPullRequest | null, DecodeFailure> {
310 const decoded = decodePullRequest(raw);
311 return Result.isSuccess(decoded)
312 ? Result.succeed(toPullRequest(decoded.success))
313 : Result.fail(decoded.failure);
314}
315
316export function decodeViewerJson(raw: string): Result.Result<string | null, DecodeFailure> {
317 const decoded = decodeViewer(raw);
318 return Result.isSuccess(decoded)
319 ? Result.succeed(trimmed(decoded.success.user?.name))
320 : Result.fail(decoded.failure);
321}
322
323export function decodeThreadsJson(
324 raw: string,
325): Result.Result<ReadonlyArray<PullRequestComment>, DecodeFailure> {
326 const decoded = decodeThreadPage(raw);
327 if (!Result.isSuccess(decoded)) {
328 return Result.fail(decoded.failure);
329 }
330 const comments: PullRequestComment[] = [];
331 for (const entry of decoded.success.value) {
332 const decodedThread = decodeThreadEntry(entry);
333 if (Exit.isFailure(decodedThread)) continue;
334 const thread = decodedThread.value;
335 if (thread.isDeleted === true) continue;
336 const path = toRepositoryPath(thread.threadContext?.filePath);
337 for (const comment of thread.comments ?? []) {
338 const publishedDate = trimmed(comment.publishedDate);
339 if (
340 comment.isDeleted === true ||
341 comment.commentType?.trim().toLowerCase() === "system" ||
342 (comment.content ?? "").trim().length === 0 ||
343 publishedDate === null
344 ) {
345 continue;
346 }
347 comments.push({
348 id: `${thread.id}:${comment.id ?? 0}`,
349 kind: path === null ? "issue-comment" : "review-comment",
350 author: toActor(comment.author),
351 body: comment.content ?? "",
352 createdAt: publishedDate,
353 url: null,
354 path,
355 reviewState: null,
356 });
357 }
358 }
359 return Result.succeed(
360 comments.toSorted((left, right) => left.createdAt.localeCompare(right.createdAt)),
361 );
362}
363
364type RawPolicyEvaluation = Schema.Schema.Type<typeof RawPolicyEvaluationSchema>;
365
366const BUILD_POLICY_TYPE = "0609b952-1397-4640-95ec-e00a01b2c241";
367const STATUS_POLICY_TYPE = "cbdc66da-9728-4af8-aada-9a5a32e4a226";
368// Other policy types wait on people or restrict pushes, so they would read as checks that never end.
369const CHECK_POLICY_TYPES = new Set([BUILD_POLICY_TYPE, STATUS_POLICY_TYPE]);
370
371/** Azure reports `queued` for a build that will never start on its own, so name those apart. */
372function toPolicyCheckProgress(
373 raw: RawPolicyEvaluation,
374): Pick<PullRequestCheck, "status" | "description"> {
375 const settled = (status: PullRequestCheck["status"]) => ({ status, description: null });
376 switch (raw.status.trim().toLowerCase()) {
377 case "approved":
378 return settled("success");
379 case "rejected":
380 case "broken":
381 return settled("failure");
382 case "running":
383 return settled("pending");
384 case "notapplicable":
385 return settled("skipped");
386 case "queued":
387 break;
388 default:
389 // A watch counts anything settled as passed, so an unknown status cannot be.
390 return settled("pending");
391 }
392 const expired = raw.context?.isExpired === true;
393 if (!expired && raw.configuration.settings?.manualQueueOnly !== true) return settled("pending");
394 // Only a blocking build holds the pull request; an optional one nobody queues never runs.
395 return {
396 status: raw.configuration.isBlocking === true ? "action-required" : "skipped",
397 description: expired ? "Expired. Queue it again on Azure DevOps." : "Queue it on Azure DevOps.",
398 };
399}
400
401/** The evaluation's configuration URL opens at the project the policy belongs to. */
402function toPolicyCheckUrl(raw: RawPolicyEvaluation): string | null {
403 const buildId = raw.context?.buildId;
404 const [projectUrl, rest] = (raw.configuration.url ?? "").split("/_apis/", 2);
405 return buildId == null || rest === undefined
406 ? null
407 : `${projectUrl}/_build/results?buildId=${buildId}`;
408}
409
410function toPolicyCheck(raw: RawPolicyEvaluation, isDraft: boolean): PullRequestCheck | null {
411 const { configuration, context } = raw;
412 if (
413 !CHECK_POLICY_TYPES.has(configuration.type.id.toLowerCase()) ||
414 configuration.isEnabled === false ||
415 configuration.isDeleted === true
416 ) {
417 return null;
418 }
419 // A build Azure holds back on a draft stays out, as nothing would ever finish it.
420 if (isDraft && raw.status.trim().toLowerCase() === "queued" && context?.buildId == null) {
421 return null;
422 }
423 return {
424 name:
425 trimmed(configuration.settings?.displayName) ??
426 trimmed(configuration.settings?.defaultDisplayName) ??
427 trimmed(context?.buildDefinitionName) ??
428 trimmed(configuration.settings?.statusName) ??
429 trimmed(configuration.type.displayName) ??
430 "Policy",
431 ...toPolicyCheckProgress(raw),
432 url: toPolicyCheckUrl(raw),
433 required: configuration.isBlocking === true,
434 };
435}
436
437export interface AzureDevOpsPolicyCheckPage {
438 readonly checks: ReadonlyArray<PullRequestCheck>;
439 /** Evaluations of every policy type, so filtered rows cannot hide a next page. */
440 readonly rawCount: number;
441}
442
443/** Unlike the tolerant decoders above, one bad row fails the page: a lost required check reads as passed. */
444export function decodePolicyChecksJson(
445 raw: string,
446 input: { readonly isDraft: boolean },
447): Result.Result<AzureDevOpsPolicyCheckPage, DecodeFailure> {
448 const decoded = decodePolicyEvaluations(raw);
449 if (!Result.isSuccess(decoded)) return Result.fail(decoded.failure);
450 return Result.succeed({
451 checks: decoded.success.flatMap((evaluation) => {
452 const check = toPolicyCheck(evaluation, input.isDraft);
453 return check === null ? [] : [check];
454 }),
455 rawCount: decoded.success.length,
456 });
457}
458
459const RawIterationSchema = Schema.Struct({
460 id: Schema.Int,
461 sourceRefCommit: Schema.optional(
462 Schema.NullOr(Schema.Struct({ commitId: Schema.optional(Schema.NullOr(Schema.String)) })),
463 ),
464 commonRefCommit: Schema.optional(
465 Schema.NullOr(Schema.Struct({ commitId: Schema.optional(Schema.NullOr(Schema.String)) })),
466 ),
467});
468
469const RawIterationPageSchema = Schema.Struct({ value: Schema.Array(Schema.Unknown) });
470
471const RawChangeEntrySchema = Schema.Struct({
472 changeType: Schema.optional(Schema.NullOr(Schema.String)),
473 sourceServerItem: Schema.optional(Schema.NullOr(Schema.String)),
474 originalPath: Schema.optional(Schema.NullOr(Schema.String)),
475 item: Schema.optional(
476 Schema.NullOr(
477 Schema.Struct({
478 path: Schema.optional(Schema.NullOr(Schema.String)),
479 objectId: Schema.optional(Schema.NullOr(Schema.String)),
480 originalObjectId: Schema.optional(Schema.NullOr(Schema.String)),
481 isFolder: Schema.optional(Schema.NullOr(Schema.Boolean)),
482 gitObjectType: Schema.optional(Schema.NullOr(Schema.String)),
483 }),
484 ),
485 ),
486});
487
488const RawChangePageSchema = Schema.Struct({
489 changeEntries: Schema.Array(Schema.Unknown),
490 nextSkip: Schema.optional(Schema.NullOr(Schema.Number)),
491});
492
493const RawItemContentSchema = Schema.Struct({
494 content: Schema.optional(Schema.NullOr(Schema.String)),
495 contentMetadata: Schema.optional(
496 Schema.NullOr(Schema.Struct({ isBinary: Schema.optional(Schema.NullOr(Schema.Boolean)) })),
497 ),
498});
499
500export interface AzureDevOpsIteration {
501 readonly id: number;
502 readonly headCommit: string;
503 readonly mergeBaseCommit: string;
504}
505
506export interface AzureDevOpsChangeEntry {
507 readonly path: string;
508 readonly oldPath: string;
509 readonly changeKind: "new" | "deleted" | "change" | "rename-pure" | "rename-changed";
510 readonly objectId: string | null;
511 readonly originalObjectId: string | null;
512}
513
514export interface AzureDevOpsChangePage {
515 readonly changes: ReadonlyArray<AzureDevOpsChangeEntry>;
516 readonly nextSkip: number | null;
517}
518
519export interface AzureDevOpsItemContent {
520 readonly contents: string;
521 readonly isBinary: boolean;
522}
523
524const decodeIterationPage = decodeJsonResult(RawIterationPageSchema);
525const decodeIterationEntry = Schema.decodeUnknownExit(RawIterationSchema);
526const decodeChangePage = decodeJsonResult(RawChangePageSchema);
527const decodeChangeEntry = Schema.decodeUnknownExit(RawChangeEntrySchema);
528const decodeItemContent = decodeJsonResult(RawItemContentSchema);
529
530/** Preserve whitespace to match patch paths and viewed marks. */
531function toRepositoryPath(value: string | null | undefined): string | null {
532 if (value === undefined || value === null) return null;
533 const path = value.replace(/^\/+/, "");
534 return path.length === 0 ? null : path;
535}
536
537function toChangeKind(
538 raw: string | null | undefined,
539 renamed: boolean,
540): AzureDevOpsChangeEntry["changeKind"] {
541 const parts = new Set(
542 (raw ?? "")
543 .toLowerCase()
544 .split(",")
545 .map((part) => part.trim())
546 .filter((part) => part.length > 0),
547 );
548 if (parts.has("delete")) return "deleted";
549 if (renamed || parts.has("rename")) return parts.has("edit") ? "rename-changed" : "rename-pure";
550 if (parts.has("add")) return "new";
551 return "change";
552}
553
554export function decodeIterationsJson(
555 raw: string,
556): Result.Result<ReadonlyArray<AzureDevOpsIteration>, DecodeFailure> {
557 const decoded = decodeIterationPage(raw);
558 if (!Result.isSuccess(decoded)) return Result.fail(decoded.failure);
559 const iterations: AzureDevOpsIteration[] = [];
560 for (const entry of decoded.success.value) {
561 const decodedIteration = decodeIterationEntry(entry);
562 if (Exit.isFailure(decodedIteration)) continue;
563 const iteration = decodedIteration.value;
564 const headCommit = trimmed(iteration.sourceRefCommit?.commitId);
565 const mergeBaseCommit = trimmed(iteration.commonRefCommit?.commitId);
566 if (headCommit === null || mergeBaseCommit === null) continue;
567 iterations.push({ id: iteration.id, headCommit, mergeBaseCommit });
568 }
569 return Result.succeed(iterations.toSorted((left, right) => left.id - right.id));
570}
571
572export function decodeIterationChangesJson(
573 raw: string,
574): Result.Result<AzureDevOpsChangePage, DecodeFailure> {
575 const decoded = decodeChangePage(raw);
576 if (!Result.isSuccess(decoded)) return Result.fail(decoded.failure);
577 const changes: AzureDevOpsChangeEntry[] = [];
578 for (const entry of decoded.success.changeEntries) {
579 const decodedChange = decodeChangeEntry(entry);
580 if (Exit.isFailure(decodedChange)) continue;
581 const change = decodedChange.value;
582 const path = toRepositoryPath(change.item?.path);
583 if (path === null) continue;
584 if (change.item?.isFolder === true) continue;
585 if ((change.item?.gitObjectType ?? "blob").toLowerCase() !== "blob") continue;
586 // Azure uses either field for renames, depending on route/version.
587 const oldPath =
588 toRepositoryPath(change.sourceServerItem) ?? toRepositoryPath(change.originalPath) ?? path;
589 changes.push({
590 path,
591 oldPath,
592 changeKind: toChangeKind(change.changeType, oldPath !== path),
593 objectId: trimmed(change.item?.objectId),
594 originalObjectId: trimmed(change.item?.originalObjectId),
595 });
596 }
597 const nextSkip = decoded.success.nextSkip ?? null;
598 return Result.succeed({
599 changes,
600 nextSkip: nextSkip !== null && Number.isSafeInteger(nextSkip) && nextSkip > 0 ? nextSkip : null,
601 });
602}
603
604/** Azure returns an empty body for absent files. Binary status comes from its metadata. */
605export function decodeItemContentJson(
606 raw: string,
607): Result.Result<AzureDevOpsItemContent, DecodeFailure> {
608 const decoded = decodeItemContent(raw);
609 return Result.isSuccess(decoded)
610 ? Result.succeed({
611 contents: decoded.success.content ?? "",
612 isBinary: decoded.success.contentMetadata?.isBinary === true,
613 })
614 : Result.fail(decoded.failure);
615}