Merge pull request #26839 from RedlineTriad/bitbucket-server-scopes
Fix Bitbucket Cloud OAuth scopes being used for BitbucketServer in ScmAuth
This commit is contained in:
@@ -226,12 +226,63 @@ export class ScmAuth implements ScmAuthApi {
|
||||
bitbucketAuthApi: OAuthApi,
|
||||
options?: {
|
||||
host?: string;
|
||||
scopeMapping?: {
|
||||
default?: string[];
|
||||
repoWrite?: string[];
|
||||
};
|
||||
},
|
||||
): ScmAuth {
|
||||
const host = options?.host ?? 'bitbucket.org';
|
||||
const defaultScopes = options?.scopeMapping?.default ?? [
|
||||
'account',
|
||||
'team',
|
||||
'pullrequest',
|
||||
'snippet',
|
||||
'issue',
|
||||
];
|
||||
const repoWriteScopes = options?.scopeMapping?.repoWrite ?? [
|
||||
'pullrequest:write',
|
||||
'snippet:write',
|
||||
'issue:write',
|
||||
];
|
||||
return new ScmAuth('bitbucket', bitbucketAuthApi, host, {
|
||||
default: ['account', 'team', 'pullrequest', 'snippet', 'issue'],
|
||||
repoWrite: ['pullrequest:write', 'snippet:write', 'issue:write'],
|
||||
default: defaultScopes,
|
||||
repoWrite: repoWriteScopes,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user