Skip to content

Commit ff2bea3

Browse files
fix(review): capture latest deployment status from first statuses page only
Avoid a redundant page-1 refetch after pagination and satisfy exactOptionalPropertyTypes for latestState. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent e116874 commit ff2bea3

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

src/review/visual/preview-url.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,27 +148,26 @@ export async function getLatestDeploymentStatus(params: {
148148
}
149149
return null;
150150
};
151-
const fetchLatestDeploymentStatusState = async (deploymentId: number): Promise<string | undefined> => {
152-
try {
153-
const statuses = await githubJson<DeploymentStatus[]>(`${base}/deployments/${deploymentId}/statuses?per_page=10`, opts);
154-
return statuses[0]?.state;
155-
} catch (error) {
156-
console.log(JSON.stringify({ event: "deployment_status_error", deployment: deploymentId, message: String(error).slice(0, 200) }));
157-
return undefined;
158-
}
159-
};
160151
const inspectDeploymentStatuses = async (deploymentId: number): Promise<{ url: string | null; latestState?: string }> => {
152+
let latestState: string | undefined;
153+
let capturedLatest = false;
161154
const url = await findAcrossPages<DeploymentStatus, string>(
162155
`${base}/deployments/${deploymentId}/statuses?per_page=10`,
163156
opts,
164157
selectStatuses,
165-
probeStatusesForUrl,
158+
(statuses) => {
159+
if (!capturedLatest) {
160+
latestState = statuses[0]?.state;
161+
capturedLatest = true;
162+
}
163+
return probeStatusesForUrl(statuses);
164+
},
166165
).catch((error) => {
167166
console.log(JSON.stringify({ event: "deployment_status_error", deployment: deploymentId, message: String(error).slice(0, 200) }));
168167
return null;
169168
});
170169
if (url) return { url };
171-
return { url: null, latestState: await fetchLatestDeploymentStatusState(deploymentId) };
170+
return latestState !== undefined ? { url: null, latestState } : { url: null };
172171
};
173172
let sawFailure = false;
174173
let sawPending = false;

0 commit comments

Comments
 (0)