Skip to content

Commit ecec222

Browse files
committed
fix: address BugBot review — ApiError args, caching, and missing await
- Fix ApiError constructor: pass endpoint as 4th arg, not 3rd (detail) - Use ValidationError for local git failures (no remote, no matching repo) to avoid incorrect negative caching of repo integration status - Add missing await on expect().rejects.toThrow() in isolated test
1 parent 72c425e commit ecec222

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/lib/api/releases.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
updateAnOrganization_sRelease,
1717
} from "@sentry/api";
1818

19-
import { ApiError } from "../errors.js";
19+
import { ApiError, ValidationError } from "../errors.js";
2020
import { getHeadCommit, getRepositoryName } from "../git.js";
2121
import { resolveOrgRegion } from "../region.js";
2222
import {
@@ -285,6 +285,7 @@ export async function createReleaseDeploy(
285285
* @param cwd - Working directory to discover git remote and HEAD from
286286
* @returns Updated release detail with commit count
287287
* @throws {ApiError} When the org has no repository integrations (400)
288+
* @throws {ValidationError} When local git remote is missing or doesn't match any Sentry repo
288289
*/
289290
export async function setCommitsAuto(
290291
orgSlug: string,
@@ -293,19 +294,20 @@ export async function setCommitsAuto(
293294
): Promise<OrgReleaseResponse> {
294295
const repos = await listRepositories(orgSlug);
295296
if (repos.length === 0) {
297+
const endpoint = `organizations/${orgSlug}/releases/${encodeURIComponent(version)}/`;
296298
throw new ApiError(
297299
"No repository integrations configured for this organization.",
298300
400,
299-
`organizations/${orgSlug}/releases/${encodeURIComponent(version)}/`
301+
undefined,
302+
endpoint
300303
);
301304
}
302305

303306
const localRepo = getRepositoryName(cwd);
304307
if (!localRepo) {
305-
throw new ApiError(
308+
throw new ValidationError(
306309
"Could not determine repository name from local git remote.",
307-
400,
308-
`organizations/${orgSlug}/releases/${encodeURIComponent(version)}/`
310+
"repository"
309311
);
310312
}
311313

@@ -314,11 +316,10 @@ export async function setCommitsAuto(
314316
(r) => r.name.toLowerCase() === localRepo.toLowerCase()
315317
);
316318
if (!matchedRepo) {
317-
throw new ApiError(
319+
throw new ValidationError(
318320
`No Sentry repository matching '${localRepo}'. ` +
319321
`Available: ${repos.map((r) => r.name).join(", ")}`,
320-
400,
321-
`organizations/${orgSlug}/releases/${encodeURIComponent(version)}/`
322+
"repository"
322323
);
323324
}
324325

test/isolated/set-commits-auto.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ describe("setCommitsAuto", () => {
127127
})
128128
);
129129

130-
expect(setCommitsAuto("test-org", "1.0.0", "/tmp")).rejects.toThrow(
130+
await expect(setCommitsAuto("test-org", "1.0.0", "/tmp")).rejects.toThrow(
131131
/No repository integrations/
132132
);
133133
});

0 commit comments

Comments
 (0)