Skip to content

Commit 2ff9176

Browse files
committed
include browser IDs in build info and snapshot fetching
1 parent 6955360 commit 2ff9176

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

src/tools/percy-change.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export async function fetchPercyChanges(
2525
});
2626

2727
// Get build info (noBuilds, isFirstBuild, lastBuildId)
28-
const { noBuilds, isFirstBuild, lastBuildId, orgId } =
28+
const { noBuilds, isFirstBuild, lastBuildId, orgId, browserIds } =
2929
await getPercyBuildCount(percyToken);
3030

3131
if (noBuilds) {
@@ -55,6 +55,7 @@ export async function fetchPercyChanges(
5555
lastBuildId,
5656
config,
5757
orgId,
58+
browserIds,
5859
);
5960
logger.info(
6061
`Fetched ${snapshotIds.length} snapshot IDs for build: ${lastBuildId} as ${snapshotIds.join(", ")}`,

src/tools/review-agent-utils/build-counts.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,24 @@ export async function getPercyBuildCount(percyToken: string) {
2020
let isFirstBuild = false;
2121
let lastBuildId: string | undefined;
2222
let orgId: string | undefined;
23+
let browserIds: string[] = [];
2324

2425
if (builds.length === 0) {
2526
return {
2627
noBuilds: true,
2728
isFirstBuild: false,
2829
lastBuildId: undefined,
2930
orgId,
31+
browserIds: [],
3032
};
31-
} else if (builds.length === 1) {
32-
isFirstBuild = true;
33-
lastBuildId = builds[0].id;
3433
} else {
35-
isFirstBuild = false;
34+
isFirstBuild = builds.length === 1;
3635
lastBuildId = builds[0].id;
36+
37+
browserIds =
38+
builds[0]?.relationships?.browsers?.data
39+
?.map((b: any) => b.id)
40+
?.filter((id: any) => typeof id === "string") ?? [];
3741
}
3842

3943
// Extract orgId from the `included` projects block
@@ -42,5 +46,5 @@ export async function getPercyBuildCount(percyToken: string) {
4246
orgId = project.relationships.organization.data.id;
4347
}
4448

45-
return { noBuilds: false, isFirstBuild, lastBuildId, orgId };
49+
return { noBuilds: false, isFirstBuild, lastBuildId, orgId, browserIds };
4650
}

src/tools/review-agent-utils/percy-diffs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export async function getPercySnapshotDiff(
1111
percyToken: string,
1212
): Promise<PercySnapshotDiff[]> {
1313
const apiUrl = `https://percy.io/api/v1/snapshots/${snapshotId}`;
14-
14+
1515
const response = await fetch(apiUrl, {
1616
headers: {
1717
Authorization: `Token token=${percyToken}`,

src/tools/review-agent-utils/percy-snapshots.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export async function getChangedPercySnapshotIds(
77
buildId: string,
88
config: BrowserStackConfig,
99
orgId: string | undefined,
10+
browserIds: string[],
1011
): Promise<string[]> {
1112

1213
if (!buildId || !orgId) {
@@ -19,10 +20,10 @@ export async function getChangedPercySnapshotIds(
1920
buildId,
2021
orgId,
2122
category: ["changed"],
22-
subcategories: ["unreviewed","approved","changes_requested"],
23+
subcategories: ["unreviewed", "approved", "changes_requested"],
2324
groupSnapshotsBy: "similar_diff",
24-
browserIds: ["63", "64", "69", "70", "71"],
25-
widths: ["375","1280","1920"],
25+
browserIds,
26+
widths: ["375", "1280", "1920"],
2627
});
2728

2829
const authString = getBrowserStackAuth(config);
@@ -77,26 +78,29 @@ export function constructPercyBuildItemsUrl({
7778

7879
if (category && category.length > 0) {
7980
category.forEach((cat) =>
80-
url.searchParams.append("filter[category][]", sanitizeUrlParam(cat))
81+
url.searchParams.append("filter[category][]", sanitizeUrlParam(cat)),
8182
);
8283
}
8384
if (subcategories && subcategories.length > 0) {
8485
subcategories.forEach((sub) =>
85-
url.searchParams.append("filter[subcategories][]", sanitizeUrlParam(sub))
86+
url.searchParams.append("filter[subcategories][]", sanitizeUrlParam(sub)),
8687
);
8788
}
8889
if (browserIds && browserIds.length > 0) {
8990
browserIds.forEach((id) =>
90-
url.searchParams.append("filter[browser_ids][]", sanitizeUrlParam(id))
91+
url.searchParams.append("filter[browser_ids][]", sanitizeUrlParam(id)),
9192
);
9293
}
9394
if (widths && widths.length > 0) {
9495
widths.forEach((w) =>
95-
url.searchParams.append("filter[widths][]", sanitizeUrlParam(w))
96+
url.searchParams.append("filter[widths][]", sanitizeUrlParam(w)),
9697
);
9798
}
9899
if (groupSnapshotsBy) {
99-
url.searchParams.set("filter[group_snapshots_by]", sanitizeUrlParam(groupSnapshotsBy));
100+
url.searchParams.set(
101+
"filter[group_snapshots_by]",
102+
sanitizeUrlParam(groupSnapshotsBy),
103+
);
100104
}
101105
return url.toString();
102106
}

0 commit comments

Comments
 (0)