@@ -107,6 +107,16 @@ export type BitbucketPullRequestApiError =
107107 | BitbucketRepositoryUnsupportedError
108108 | BitbucketDiffCommitError ;
109109
110+ /**
111+ * `/user/permissions/repositories` answering CHANGE-2770's removal notice rather than a
112+ * permission — Bitbucket sends this for every account now, not only ones it would have refused.
113+ */
114+ function isRepositoryPermissionRemovedError (
115+ error : BitbucketPullRequestApiError ,
116+ ) : error is BitbucketApi . BitbucketResponseError {
117+ return error . _tag === "BitbucketResponseError" && error . status === 410 ;
118+ }
119+
110120/**
111121 * Bitbucket's own ceiling. Asking for more does not fail — it answers with an empty page and no
112122 * 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* () {
553563 // Nothing on the repository, the pull request or the workspace states what the credentials
554564 // may do, so this endpoint is the one request Bitbucket makes unavoidable. It is asked
555565 // alongside the reads the detail was already making, so it costs no round trip of its own.
566+ //
567+ // Bitbucket permanently removed this endpoint (CHANGE-2770): every account now gets HTTP 410
568+ // in place of an answer, whatever it may do. That is the deprecated-endpoint signal, not a
569+ // permission being refused, so it is read the same way an unreachable read already is
570+ // elsewhere — as a permission that could not be learned, which grants rather than blocks, and
571+ // leaves the actual merge or write to say why if the account may not do it. Any other failure
572+ // (a bad token, a network fault, an unreadable body) still fails as it did before.
556573 getRepositoryPermission : ( input ) =>
557574 withRepository ( input . repository , ( ) =>
558575 readPage ( {
@@ -562,7 +579,7 @@ export const make = Effect.gen(function* () {
562579 ) } `,
563580 decode : decodeRepositoryPermissionJson ,
564581 } ) ,
565- ) ,
582+ ) . pipe ( Effect . catchIf ( isRepositoryPermissionRemovedError , ( ) => Effect . succeed ( true ) ) ) ,
566583
567584 getPullRequestDiff : ( input ) =>
568585 input . commit !== undefined && ! isCommitSha ( input . commit )
0 commit comments