Skip to content

Commit d6fd2aa

Browse files
committed
fix(azure-devops): policy checks keep the names Azure gives them
Adding the policy id only when two names collided renamed a check once a second policy with its name showed up, such as after a draft was published. A watch holding the old name for approval then waited on a check that no longer existed and never sent checks-passed. Names now stay as Azure reports them. Two policies that share a name are tracked as one, which a stable check id in the contract would fix for every provider.
1 parent ea7f5a7 commit d6fd2aa

3 files changed

Lines changed: 5 additions & 46 deletions

File tree

‎packages/source-control-azure-devops/src/server/AzureDevOpsPullRequestCli.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ import {
2424
decodePullRequestListJson,
2525
decodeThreadsJson,
2626
decodeViewerJson,
27-
namePolicyChecksApart,
2827
type AzureDevOpsChangeEntry,
2928
type AzureDevOpsItemContent,
30-
type AzureDevOpsPolicyCheck,
3129
type AzureDevOpsIteration,
3230
type AzureDevOpsPullRequest,
3331
type AzureDevOpsRepositoryLocation,
@@ -569,7 +567,7 @@ export const make = Effect.gen(function* () {
569567
operation: "listPolicyChecks",
570568
cause,
571569
});
572-
const checks: AzureDevOpsPolicyCheck[] = [];
570+
const checks: PullRequestCheck[] = [];
573571
for (let skip = 0; skip < MAX_POLICY_EVALUATIONS; skip += POLICY_EVALUATIONS_PER_PAGE) {
574572
const result = yield* executeJson({
575573
cwd: input.cwd,
@@ -591,9 +589,7 @@ export const make = Effect.gen(function* () {
591589
const page = decodePolicyChecksJson(result.stdout.trim(), { isDraft: input.isDraft });
592590
if (!Result.isSuccess(page)) return yield* unreadable(page.failure);
593591
checks.push(...page.success.checks);
594-
if (page.success.rawCount < POLICY_EVALUATIONS_PER_PAGE) {
595-
return sortChecks(namePolicyChecksApart(checks));
596-
}
592+
if (page.success.rawCount < POLICY_EVALUATIONS_PER_PAGE) return sortChecks(checks);
597593
}
598594
return yield* unreadable("Policy evaluations exceeded the read limit");
599595
}),

‎packages/source-control-azure-devops/src/server/azureDevOpsPullRequestJson.test.ts‎

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
decodeIterationChangesJson,
77
decodeIterationsJson,
88
decodePolicyChecksJson,
9-
namePolicyChecksApart,
109
decodePullRequestJson,
1110
decodePullRequestListJson,
1211
decodeThreadsJson,
@@ -543,7 +542,7 @@ describe("decodePolicyChecksJson", () => {
543542
});
544543

545544
const decodeOne = (value: unknown, isDraft = false) =>
546-
expectSuccess(decodePolicyChecksJson(asJson([value]), { isDraft })).checks[0]?.check;
545+
expectSuccess(decodePolicyChecksJson(asJson([value]), { isDraft })).checks[0];
547546

548547
it.each([
549548
["approved", "success"],
@@ -646,23 +645,6 @@ describe("decodePolicyChecksJson", () => {
646645
});
647646
});
648647

649-
// Watches and client rows tell checks apart by name, and path-filtered copies of one pipeline share it.
650-
it("names policies that share a name apart by their policy id", () => {
651-
const named = (id: number, displayName: string) =>
652-
evaluation("approved", null, { displayName }, { id });
653-
const { checks } = expectSuccess(
654-
decodePolicyChecksJson(
655-
asJson([named(54, "PR validation"), named(61, "PR validation"), named(70, "Lint")]),
656-
{ isDraft: false },
657-
),
658-
);
659-
expect(namePolicyChecksApart(checks).map((check) => check.name)).toEqual([
660-
"PR validation (#54)",
661-
"PR validation (#61)",
662-
"Lint",
663-
]);
664-
});
665-
666648
it("fails the page on a row it cannot read, which could be a required check", () => {
667649
const rows = asJson([evaluation("rejected", null), { status: 7 }]);
668650
expect(Result.isFailure(decodePolicyChecksJson(rows, { isDraft: false }))).toBe(true);

‎packages/source-control-azure-devops/src/server/azureDevOpsPullRequestJson.ts‎

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ const RawPolicyEvaluationSchema = Schema.Struct({
116116
),
117117
),
118118
configuration: Schema.Struct({
119-
id: Schema.optional(Schema.NullOr(Schema.Int)),
120119
url: Schema.optional(Schema.NullOr(Schema.String)),
121120
isBlocking: Schema.optional(Schema.NullOr(Schema.Boolean)),
122121
isEnabled: Schema.optional(Schema.NullOr(Schema.Boolean)),
@@ -435,13 +434,8 @@ function toPolicyCheck(raw: RawPolicyEvaluation, isDraft: boolean): PullRequestC
435434
};
436435
}
437436

438-
export interface AzureDevOpsPolicyCheck {
439-
readonly check: PullRequestCheck;
440-
readonly policyId: number | null;
441-
}
442-
443437
export interface AzureDevOpsPolicyCheckPage {
444-
readonly checks: ReadonlyArray<AzureDevOpsPolicyCheck>;
438+
readonly checks: ReadonlyArray<PullRequestCheck>;
445439
/** Evaluations of every policy type, so filtered rows cannot hide a next page. */
446440
readonly rawCount: number;
447441
}
@@ -456,25 +450,12 @@ export function decodePolicyChecksJson(
456450
return Result.succeed({
457451
checks: decoded.success.flatMap((evaluation) => {
458452
const check = toPolicyCheck(evaluation, input.isDraft);
459-
return check === null ? [] : [{ check, policyId: evaluation.configuration.id ?? null }];
453+
return check === null ? [] : [check];
460454
}),
461455
rawCount: decoded.success.length,
462456
});
463457
}
464458

465-
/** Watches and client rows tell checks apart by name, which path-filtered copies of one pipeline share. */
466-
export function namePolicyChecksApart(
467-
entries: ReadonlyArray<AzureDevOpsPolicyCheck>,
468-
): ReadonlyArray<PullRequestCheck> {
469-
const counts = new Map<string, number>();
470-
for (const { check } of entries) counts.set(check.name, (counts.get(check.name) ?? 0) + 1);
471-
return entries.map(({ check, policyId }) =>
472-
policyId === null || counts.get(check.name) === 1
473-
? check
474-
: { ...check, name: `${check.name} (#${policyId})` },
475-
);
476-
}
477-
478459
const RawIterationSchema = Schema.Struct({
479460
id: Schema.Int,
480461
sourceRefCommit: Schema.optional(

0 commit comments

Comments
 (0)