Skip to content

Commit be33a72

Browse files
committed
refactor: streamline browser ID extraction and update authentication handling in Percy integration
1 parent 2ff9176 commit be33a72

File tree

3 files changed

+9
-51
lines changed

3 files changed

+9
-51
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ export async function getPercyBuildCount(percyToken: string) {
3333
} else {
3434
isFirstBuild = builds.length === 1;
3535
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") ?? [];
4136
}
4237

38+
// Extract browserIds from the latest build if available
39+
browserIds =
40+
builds[0]?.relationships?.browsers?.data
41+
?.map((b: any) => b.id)
42+
?.filter((id: any) => typeof id === "string") ?? [];
43+
4344
// Extract orgId from the `included` projects block
4445
const project = included.find((item: any) => item.type === "projects");
4546
if (project?.relationships?.organization?.data?.id) {

src/tools/review-agent-utils/percy-approve-reject.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export async function approveOrDeclinePercyBuild(
99
const { buildId, action } = args;
1010

1111
// Get Basic Auth credentials
12-
const [username, accessKey] = getBrowserStackAuth(config).split(":");
13-
const authHeader = `Basic ${Buffer.from(`${username}:${accessKey}`).toString("base64")}`;
12+
const authString = getBrowserStackAuth(config);
13+
const auth = Buffer.from(authString).toString("base64");
1414

1515
// Prepare request body
1616
const body = {
@@ -28,7 +28,7 @@ export async function approveOrDeclinePercyBuild(
2828
method: "POST",
2929
headers: {
3030
"Content-Type": "application/json",
31-
Authorization: authHeader,
31+
Authorization: `Basic ${auth}`,
3232
},
3333
body: JSON.stringify(body),
3434
});

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

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)