@@ -112,14 +112,14 @@ export type BitbucketPullRequestApiError =
112112 | BitbucketRepositoryUnsupportedError
113113 | BitbucketDiffCommitError ;
114114
115- /**
116- * `/user/permissions/repositories` answering CHANGE-2770's removal notice rather than a
117- * permission — Bitbucket sends this for every account now, not only ones it would have refused.
118- */
119- function isRepositoryPermissionRemovedError (
115+ /** The permissions endpoint refusing or missing for these credentials, rather than answering. */
116+ function isRepositoryPermissionUnavailableError (
120117 error : BitbucketPullRequestApiError ,
121118) : error is BitbucketApi . BitbucketResponseError {
122- return error . _tag === "BitbucketResponseError" && error . status === 410 ;
119+ return (
120+ error . _tag === "BitbucketResponseError" &&
121+ ( error . status === 403 || error . status === 404 || error . status === 410 )
122+ ) ;
123123}
124124
125125/**
@@ -412,16 +412,19 @@ export const make = Effect.gen(function* () {
412412 const bitbucket = yield * BitbucketApi . BitbucketApi ;
413413
414414 /**
415- * The repository's own path, and the workspace above it — which the people who may review are
416- * kept on rather than on the repository, so both are handed over at once.
415+ * The repository's API path and normalized segments, used for workspace reads and filters.
417416 */
418417 const withRepository = < A > (
419418 repository : string ,
420- use : ( path : string , workspace : string ) => Effect . Effect < A , BitbucketPullRequestApiError > ,
419+ use : (
420+ path : string ,
421+ workspace : string ,
422+ slug : string ,
423+ ) => Effect . Effect < A , BitbucketPullRequestApiError > ,
421424 ) : Effect . Effect < A , BitbucketPullRequestApiError > => {
422425 const segments = repositorySegments ( repository ) ;
423426 return Result . isSuccess ( segments )
424- ? use ( repositoryPathOf ( segments . success ) , segments . success . workspace )
427+ ? use ( repositoryPathOf ( segments . success ) , segments . success . workspace , segments . success . slug )
425428 : Effect . fail ( segments . failure ) ;
426429 } ;
427430
@@ -656,26 +659,23 @@ export const make = Effect.gen(function* () {
656659 } ) ,
657660 ) ,
658661
659- // Nothing on the repository, the pull request or the workspace states what the credentials
660- // may do, so this endpoint is the one request Bitbucket makes unavoidable. It is asked
661- // alongside the reads the detail was already making, so it costs no round trip of its own.
662+ // Ask for the caller's effective permission within this workspace. The full name identifies
663+ // the repository by its slug, even when its display name differs.
662664 //
663- // Bitbucket permanently removed this endpoint (CHANGE-2770): every account now gets HTTP 410
664- // in place of an answer, whatever it may do. That is the deprecated-endpoint signal, not a
665- // permission being refused, so it is read the same way an unreachable read already is
666- // elsewhere — as a permission that could not be learned, which grants rather than blocks, and
667- // leaves the actual merge or write to say why if the account may not do it. Any other failure
668- // (a bad token, a network fault, an unreadable body) still fails as it did before.
665+ // Bitbucket has retired permission endpoints before (CHANGE-2770), and some credentials may
666+ // not reach `/user` endpoints at all. A 403, 404 or 410 here is read as a permission that
667+ // could not be learned, the same as an empty page: it grants, and the write itself says why
668+ // if the account may not do it. Other failures (a bad token, a network fault) still fail.
669669 getRepositoryPermission : ( input ) =>
670- withRepository ( input . repository , ( ) =>
670+ withRepository ( input . repository , ( _path , workspace , slug ) =>
671671 readPage ( {
672672 operation : "getRepositoryPermission" ,
673- url : `/user/permissions/repositories?q=${ encodeURIComponent (
674- `repository.full_name="${ filterLiteral ( input . repository . trim ( ) ) } "` ,
673+ url : `/user/workspaces/ ${ encodeURIComponent ( workspace ) } / permissions/repositories?q=${ encodeURIComponent (
674+ `repository.full_name="${ filterLiteral ( ` ${ workspace } / ${ slug } ` ) } "` ,
675675 ) } `,
676676 decode : decodeRepositoryPermissionJson ,
677677 } ) ,
678- ) . pipe ( Effect . catchIf ( isRepositoryPermissionRemovedError , ( ) => Effect . succeed ( true ) ) ) ,
678+ ) . pipe ( Effect . catchIf ( isRepositoryPermissionUnavailableError , ( ) => Effect . succeed ( true ) ) ) ,
679679
680680 getPullRequestDiff : pullRequestDiff ,
681681
0 commit comments