Bitbucket repo visibility
This commit is contained in:
@@ -63,11 +63,14 @@ describe('Bitbucket Publisher', () => {
|
||||
),
|
||||
);
|
||||
|
||||
const publisher = await BitbucketPublisher.fromConfig({
|
||||
host: 'bitbucket.org',
|
||||
username: 'fake-user',
|
||||
appPassword: 'fake-token',
|
||||
});
|
||||
const publisher = await BitbucketPublisher.fromConfig(
|
||||
{
|
||||
host: 'bitbucket.org',
|
||||
username: 'fake-user',
|
||||
appPassword: 'fake-token',
|
||||
},
|
||||
{ repoVisibility: 'private' },
|
||||
);
|
||||
|
||||
const result = await publisher.publish({
|
||||
values: {
|
||||
@@ -122,10 +125,13 @@ describe('Bitbucket Publisher', () => {
|
||||
),
|
||||
);
|
||||
|
||||
const publisher = await BitbucketPublisher.fromConfig({
|
||||
host: 'bitbucket.mycompany.com',
|
||||
token: 'fake-token',
|
||||
});
|
||||
const publisher = await BitbucketPublisher.fromConfig(
|
||||
{
|
||||
host: 'bitbucket.mycompany.com',
|
||||
token: 'fake-token',
|
||||
},
|
||||
{ repoVisibility: 'private' },
|
||||
);
|
||||
|
||||
const result = await publisher.publish({
|
||||
values: {
|
||||
|
||||
@@ -21,17 +21,23 @@ import { BitbucketIntegrationConfig } from '@backstage/integration';
|
||||
import parseGitUrl from 'git-url-parse';
|
||||
import path from 'path';
|
||||
|
||||
export type RepoVisibilityOptions = 'private' | 'public';
|
||||
|
||||
// TODO(blam): We should probably start to use a bitbucket client here that we can change
|
||||
// the baseURL to point at on-prem or public bitbucket versions like we do for
|
||||
// github and ghe. There's to much logic and not enough types here for us to say that this way is better than using
|
||||
// a supported bitbucket client if one exists.
|
||||
export class BitbucketPublisher implements PublisherBase {
|
||||
static async fromConfig(config: BitbucketIntegrationConfig) {
|
||||
static async fromConfig(
|
||||
config: BitbucketIntegrationConfig,
|
||||
{ repoVisibility }: { repoVisibility: RepoVisibilityOptions },
|
||||
) {
|
||||
return new BitbucketPublisher({
|
||||
host: config.host,
|
||||
token: config.token,
|
||||
appPassword: config.appPassword,
|
||||
username: config.username,
|
||||
repoVisibility,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -41,6 +47,7 @@ export class BitbucketPublisher implements PublisherBase {
|
||||
token?: string;
|
||||
appPassword?: string;
|
||||
username?: string;
|
||||
repoVisibility: RepoVisibilityOptions;
|
||||
},
|
||||
) {}
|
||||
|
||||
@@ -101,6 +108,7 @@ export class BitbucketPublisher implements PublisherBase {
|
||||
body: JSON.stringify({
|
||||
scm: 'git',
|
||||
description: description,
|
||||
is_private: this.config.repoVisibility === 'private',
|
||||
}),
|
||||
headers: {
|
||||
Authorization: `Basic ${buffer.toString('base64')}`,
|
||||
@@ -144,6 +152,7 @@ export class BitbucketPublisher implements PublisherBase {
|
||||
body: JSON.stringify({
|
||||
name: name,
|
||||
description: description,
|
||||
is_private: this.config.repoVisibility === 'private',
|
||||
}),
|
||||
headers: {
|
||||
Authorization: `Bearer ${this.config.token}`,
|
||||
|
||||
@@ -16,10 +16,19 @@
|
||||
|
||||
import { Config } from '@backstage/config';
|
||||
import { PublisherBase, PublisherBuilder } from './types';
|
||||
import { GithubPublisher, RepoVisibilityOptions } from './github';
|
||||
import { GitlabPublisher } from './gitlab';
|
||||
import {
|
||||
GithubPublisher,
|
||||
RepoVisibilityOptions as GithubRepoVisibilityOptions,
|
||||
} from './github';
|
||||
import {
|
||||
GitlabPublisher,
|
||||
RepoVisibilityOptions as GitlabRepoVisibilityOptions,
|
||||
} from './gitlab';
|
||||
import { AzurePublisher } from './azure';
|
||||
import { BitbucketPublisher } from './bitbucket';
|
||||
import {
|
||||
BitbucketPublisher,
|
||||
RepoVisibilityOptions as BitbucketRepoVisibilityOptions,
|
||||
} from './bitbucket';
|
||||
import { Logger } from 'winston';
|
||||
import { ScmIntegrations } from '@backstage/integration';
|
||||
|
||||
@@ -74,7 +83,7 @@ export class Publishers implements PublisherBuilder {
|
||||
for (const integration of scm.github.list()) {
|
||||
const repoVisibility = (config.getOptionalString(
|
||||
'scaffolder.github.visibility',
|
||||
) ?? 'public') as RepoVisibilityOptions;
|
||||
) ?? 'public') as GithubRepoVisibilityOptions;
|
||||
|
||||
const publisher = await GithubPublisher.fromConfig(integration.config, {
|
||||
repoVisibility,
|
||||
@@ -100,7 +109,7 @@ export class Publishers implements PublisherBuilder {
|
||||
for (const integration of scm.gitlab.list()) {
|
||||
const repoVisibility = (config.getOptionalString(
|
||||
'scaffolder.gitlab.visibility',
|
||||
) ?? 'public') as RepoVisibilityOptions;
|
||||
) ?? 'public') as GitlabRepoVisibilityOptions;
|
||||
|
||||
const publisher = await GitlabPublisher.fromConfig(integration.config, {
|
||||
repoVisibility,
|
||||
@@ -125,7 +134,16 @@ export class Publishers implements PublisherBuilder {
|
||||
}
|
||||
|
||||
for (const integration of scm.bitbucket.list()) {
|
||||
const publisher = await BitbucketPublisher.fromConfig(integration.config);
|
||||
const repoVisibility = (config.getOptionalString(
|
||||
'scaffolder.bitbucket.visibility',
|
||||
) ?? 'public') as BitbucketRepoVisibilityOptions;
|
||||
|
||||
const publisher = await BitbucketPublisher.fromConfig(
|
||||
integration.config,
|
||||
{
|
||||
repoVisibility,
|
||||
},
|
||||
);
|
||||
|
||||
if (publisher) {
|
||||
publishers.register(integration.config.host, publisher);
|
||||
@@ -134,15 +152,19 @@ export class Publishers implements PublisherBuilder {
|
||||
|
||||
publishers.register(
|
||||
integration.config.host,
|
||||
await BitbucketPublisher.fromConfig({
|
||||
token: config.getOptionalString('scaffolder.bitbucket.token') ?? '',
|
||||
username:
|
||||
config.getOptionalString('scaffolder.bitbucket.username') ?? '',
|
||||
appPassword:
|
||||
config.getOptionalString('scaffolder.bitbucket.appPassword') ??
|
||||
'',
|
||||
host: integration.config.host,
|
||||
}),
|
||||
await BitbucketPublisher.fromConfig(
|
||||
{
|
||||
token:
|
||||
config.getOptionalString('scaffolder.bitbucket.token') ?? '',
|
||||
username:
|
||||
config.getOptionalString('scaffolder.bitbucket.username') ?? '',
|
||||
appPassword:
|
||||
config.getOptionalString('scaffolder.bitbucket.appPassword') ??
|
||||
'',
|
||||
host: integration.config.host,
|
||||
},
|
||||
{ repoVisibility },
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user