Merge pull request #5257 from ntgussoni/fix/4208_bitbucket_server_requires_username
Bitbucket server requires username to be set
This commit is contained in:
@@ -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' },
|
||||
],
|
||||
},
|
||||
}),
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user