From f69821a0f86da6c6a80d452085192791eb70ae1a Mon Sep 17 00:00:00 2001 From: RedlineTriad <39059512+RedlineTriad@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:23:28 +0200 Subject: [PATCH] feat: add `ScmAuth` provider for Bitbucket Server This fixes a bug where it used the same scopes as Bitbucket Cloud, even though they are incompatible with Bitbucket Server. Fixes #26803 Signed-off-by: RedlineTriad <39059512+RedlineTriad@users.noreply.github.com> --- packages/integration-react/report.api.md | 10 ++++++ packages/integration-react/src/api/ScmAuth.ts | 35 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/packages/integration-react/report.api.md b/packages/integration-react/report.api.md index ee6eb0f40a..8d02c46010 100644 --- a/packages/integration-react/report.api.md +++ b/packages/integration-react/report.api.md @@ -61,6 +61,16 @@ export class ScmAuth implements ScmAuthApi { }; }, ): ScmAuth; + static forBitbucketServer( + bitbucketAuthApi: OAuthApi, + options: { + host: string; + scopeMapping?: { + default?: string[]; + repoWrite?: string[]; + }; + }, + ): ScmAuth; static forGithub( githubAuthApi: OAuthApi, options?: { diff --git a/packages/integration-react/src/api/ScmAuth.ts b/packages/integration-react/src/api/ScmAuth.ts index a751e43ce4..4042088fd5 100644 --- a/packages/integration-react/src/api/ScmAuth.ts +++ b/packages/integration-react/src/api/ScmAuth.ts @@ -251,6 +251,41 @@ export class ScmAuth implements ScmAuthApi { }); } + /** + * Creates a new ScmAuth instance that handles authentication towards Bitbucket Server. + * + * The host option determines which URLs that are handled by this instance. + * + * The default scopes are: + * + * `PUBLIC_REPOS REPOS_READ` + * + * If the additional `repoWrite` permission is requested, these scopes are added: + * + * `REPO_WRITE` + */ + static forBitbucketServer( + bitbucketAuthApi: OAuthApi, + options: { + host: string; + scopeMapping?: { + default?: string[]; + repoWrite?: string[]; + }; + }, + ): ScmAuth { + return this.forBitbucket(bitbucketAuthApi, { + host: options.host, + scopeMapping: { + default: options.scopeMapping?.default ?? [ + 'PUBLIC_REPOS', + 'REPOS_READ', + ], + repoWrite: options.scopeMapping?.repoWrite ?? ['REPO_WRITE'], + }, + }); + } + /** * Merges together multiple ScmAuth instances into one that * routes requests to the correct instance based on the URL.