fix(server): treat removed Bitbucket permissions endpoint as unknown, not blocking (#6525)
This commit is contained in:
1 parent
afca73d368
commit
75472802bc
2 files changed
+58
-1
No files matched your search
@@ -867,6 +867,46 @@ layer("BitbucketPullRequestApi.layer", (it) => {
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect(
|
||||
"reads a removed permissions endpoint as granted rather than failing the merge on it",
|
||||
() =>
|
||||
Effect.gen(function* () {
|
||||
// Bitbucket retired /user/permissions/repositories under CHANGE-2770: every account now
|
||||
// gets HTTP 410 here, whatever it may do.
|
||||
mockedRequest.mockReturnValue(
|
||||
Effect.fail(
|
||||
new BitbucketApi.BitbucketResponseError({
|
||||
operation: "request",
|
||||
status: 410,
|
||||
responseBodyLength: 0,
|
||||
}),
|
||||
),
|
||||
);
|
||||
const api = yield* BitbucketPullRequestApi.BitbucketPullRequestApi;
|
||||
|
||||
assert.isTrue(yield* api.getRepositoryPermission({ repository: "acme/web" }));
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("still fails the permission read on a failure that is not the removed endpoint", () =>
|
||||
Effect.gen(function* () {
|
||||
mockedRequest.mockReturnValue(
|
||||
Effect.fail(
|
||||
new BitbucketApi.BitbucketResponseError({
|
||||
operation: "request",
|
||||
status: 401,
|
||||
responseBodyLength: 0,
|
||||
}),
|
||||
),
|
||||
);
|
||||
const api = yield* BitbucketPullRequestApi.BitbucketPullRequestApi;
|
||||
|
||||
const error = yield* Effect.flip(api.getRepositoryPermission({ repository: "acme/web" }));
|
||||
|
||||
assert.strictEqual(error._tag, "BitbucketResponseError");
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("reads the workspace's people and marks whoever is already a reviewer", () =>
|
||||
Effect.gen(function* () {
|
||||
mockedRequest
|
||||
|
||||
@@ -107,6 +107,16 @@ export type BitbucketPullRequestApiError =
|
||||
| BitbucketRepositoryUnsupportedError
|
||||
| BitbucketDiffCommitError;
|
||||
|
||||
/**
|
||||
* `/user/permissions/repositories` answering CHANGE-2770's removal notice rather than a
|
||||
* permission — Bitbucket sends this for every account now, not only ones it would have refused.
|
||||
*/
|
||||
function isRepositoryPermissionRemovedError(
|
||||
error: BitbucketPullRequestApiError,
|
||||
): error is BitbucketApi.BitbucketResponseError {
|
||||
return error._tag === "BitbucketResponseError" && error.status === 410;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bitbucket's own ceiling. Asking for more does not fail — it answers with an empty page and no
|
||||
* error at all, so this is a number to respect rather than to push against.
|
||||
@@ -553,6 +563,13 @@ export const make = Effect.gen(function* () {
|
||||
// Nothing on the repository, the pull request or the workspace states what the credentials
|
||||
// may do, so this endpoint is the one request Bitbucket makes unavoidable. It is asked
|
||||
// alongside the reads the detail was already making, so it costs no round trip of its own.
|
||||
//
|
||||
// Bitbucket permanently removed this endpoint (CHANGE-2770): every account now gets HTTP 410
|
||||
// in place of an answer, whatever it may do. That is the deprecated-endpoint signal, not a
|
||||
// permission being refused, so it is read the same way an unreachable read already is
|
||||
// elsewhere — as a permission that could not be learned, which grants rather than blocks, and
|
||||
// leaves the actual merge or write to say why if the account may not do it. Any other failure
|
||||
// (a bad token, a network fault, an unreadable body) still fails as it did before.
|
||||
getRepositoryPermission: (input) =>
|
||||
withRepository(input.repository, () =>
|
||||
readPage({
|
||||
@@ -562,7 +579,7 @@ export const make = Effect.gen(function* () {
|
||||
)}`,
|
||||
decode: decodeRepositoryPermissionJson,
|
||||
}),
|
||||
),
|
||||
).pipe(Effect.catchIf(isRepositoryPermissionRemovedError, () => Effect.succeed(true))),
|
||||
|
||||
getPullRequestDiff: (input) =>
|
||||
input.commit !== undefined && !isCommitSha(input.commit)
|
||||
|
||||
Reference in new issue
Block a user