Skip to content

Commit 743d01c

Browse files
committed
test(e2e): retry the sha lookup in apiUpdateFile
The update API needs the current blob sha, but the GET fetching it was neither retried nor status-checked: a transient 5xx or a 404 surfaced as a confusing JSON parse error instead of the retry helper's message. Wrap it like apiCreatePR does, reading the sha only when the response is ok. Assisted-by: Codet
1 parent 150e629 commit 743d01c

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

tests/e2e/utils.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,14 @@ export async function apiCreateFile(requestContext: APIRequestContext, owner: st
8989

9090
/** Update an existing file's content on a branch (fetches the current blob sha first, as the update API requires it). */
9191
export async function apiUpdateFile(requestContext: APIRequestContext, owner: string, repo: string, filepath: string, content: string, {branch, message}: {branch?: string; message?: string} = {}) {
92-
const getResponse = await requestContext.get(`${baseUrl()}/api/v1/repos/${owner}/${repo}/contents/${filepath}${branch ? `?ref=${encodeURIComponent(branch)}` : ''}`, {
93-
headers: apiHeaders(),
94-
});
95-
const {sha} = await getResponse.json();
92+
let sha = '';
93+
await apiRetry(async () => {
94+
const response = await requestContext.get(`${baseUrl()}/api/v1/repos/${owner}/${repo}/contents/${filepath}${branch ? `?ref=${encodeURIComponent(branch)}` : ''}`, {
95+
headers: apiHeaders(),
96+
});
97+
if (response.ok()) sha = (await response.json()).sha;
98+
return response;
99+
}, 'apiUpdateFile:getSha');
96100
await apiRetry(() => requestContext.put(`${baseUrl()}/api/v1/repos/${owner}/${repo}/contents/${filepath}`, {
97101
headers: apiHeaders(),
98102
data: {content: Buffer.from(content, 'utf8').toString('base64'), sha, branch, message},

0 commit comments

Comments
 (0)