Bitbucket server requires username to be set

Signed-off-by: Nicolas Torres <nicolast@backbase.com>
This commit is contained in:
Nicolas Torres
2021-04-08 17:06:50 +02:00
parent f240b09965
commit d840d30bcd
6 changed files with 41 additions and 3 deletions
+14
View File
@@ -0,0 +1,14 @@
---
'@backstage/plugin-scaffolder-backend': patch
---
Bitbucket server needs username to be set as well as the token or appPassword for the publishing process to work.
```yaml
integrations:
bitbucket:
- host: bitbucket.mycompany.com
apiBaseUrl: https://bitbucket.mycompany.com/rest/api/1.0
token: token
username: username
```
+3
View File
@@ -38,3 +38,6 @@ a structure with up to four elements:
- `apiBaseUrl` (optional): The URL of the Bitbucket API. For self-hosted
installations, it is commonly at `https://<host>/rest/api/1.0`. For
bitbucket.org, this configuration is not needed as it can be inferred.
> Note: If you are using Bitbucket server you MUST set the username as well as
> the token or appPassword.
@@ -97,6 +97,19 @@ describe('Bitbucket Publisher', () => {
});
describe('publish: createRemoteInBitbucketServer', () => {
it('should throw an error if no username present', async () => {
await expect(
BitbucketPublisher.fromConfig(
{
host: 'bitbucket.mycompany.com',
token: 'fake-token',
},
{ repoVisibility: 'private' },
),
).rejects.toThrow(
'Bitbucket server requires the username to be set in your config',
);
});
it('should create repo in bitbucket server', async () => {
server.use(
rest.post(
@@ -128,6 +141,7 @@ describe('Bitbucket Publisher', () => {
const publisher = await BitbucketPublisher.fromConfig(
{
host: 'bitbucket.mycompany.com',
username: 'foo',
token: 'fake-token',
},
{ repoVisibility: 'private' },
@@ -151,7 +165,7 @@ describe('Bitbucket Publisher', () => {
expect(initRepoAndPush).toHaveBeenCalledWith({
dir: resultPath,
remoteUrl: 'https://bitbucket.mycompany.com/scm/project/repo',
auth: { username: 'x-token-auth', password: 'fake-token' },
auth: { username: 'foo', password: 'fake-token' },
logger: logger,
});
});
@@ -32,6 +32,11 @@ export class BitbucketPublisher implements PublisherBase {
config: BitbucketIntegrationConfig,
{ repoVisibility }: { repoVisibility: RepoVisibilityOptions },
) {
if (config.host !== 'bitbucket.org' && !config.username)
throw new Error(
'Bitbucket server requires the username to be set in your config',
);
return new BitbucketPublisher({
host: config.host,
token: config.token,
@@ -76,7 +76,9 @@ describe('Publishers', () => {
const publishers = await Publishers.fromConfig(
new ConfigReader({
integrations: {
bitbucket: [{ host: 'bitbucket.com', token: 'blob' }],
bitbucket: [
{ host: 'bitbucket.com', username: 'foo', token: 'blob' },
],
},
}),
{
+1 -1
View File
@@ -4236,7 +4236,7 @@
dependencies:
"@octokit/openapi-types" "^5.3.2"
"@octokit/types@^6.13.0":
"@octokit/types@^6.13.0", "@octokit/types@^6.8.2":
version "6.13.0"
resolved "https://registry.npmjs.org/@octokit/types/-/types-6.13.0.tgz#779e5b7566c8dde68f2f6273861dd2f0409480d0"
integrity sha512-W2J9qlVIU11jMwKHUp5/rbVUeErqelCsO5vW5PKNb7wAXQVUz87Rc+imjlEvpvbH8yUb+KHmv8NEjVZdsdpyxA==