Convert repoVisibility into template parameter

Co-authored-by: Ben Lambert <ben@blam.sh>
Signed-off-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
Johan Haals
2021-02-25 13:15:39 +01:00
parent 664f336c42
commit ec5c3b82bf
4 changed files with 28 additions and 12 deletions
@@ -145,12 +145,12 @@ const getAuthorizationHeader = (config: BitbucketIntegrationConfig) => {
export function createPublishBitbucketAction(options: {
integrations: ScmIntegrations;
repoVisibility: 'private' | 'public';
}): TemplateAction<{
repoUrl: string;
description: string;
repoVisibility: 'private' | 'public';
}> {
const { integrations, repoVisibility } = options;
const { integrations } = options;
return {
id: 'publish:bitbucket',
@@ -167,6 +167,11 @@ export function createPublishBitbucketAction(options: {
title: 'Repository Description',
type: 'string',
},
repoVisibility: {
title: 'Repository Visiblity',
type: 'string',
enum: ['private', 'public'],
},
},
},
output: {
@@ -184,7 +189,11 @@ export function createPublishBitbucketAction(options: {
},
},
async handler(ctx) {
const { repoUrl, description } = ctx.parameters;
const {
repoUrl,
description,
repoVisibility = 'private',
} = ctx.parameters;
const { owner, repo, host } = parseRepoUrl(repoUrl);
@@ -26,13 +26,13 @@ import { parseRepoUrl } from './util';
export function createPublishGithubAction(options: {
integrations: ScmIntegrations;
repoVisibility: 'private' | 'internal' | 'public';
}): TemplateAction<{
repoUrl: string;
description?: string;
access?: string;
repoVisibility: 'private' | 'internal' | 'public';
}> {
const { integrations, repoVisibility } = options;
const { integrations } = options;
const credentialsProviders = new Map(
integrations.github.list().map(integration => {
@@ -60,6 +60,11 @@ export function createPublishGithubAction(options: {
title: 'Repository Access',
type: 'string',
},
repoVisibility: {
title: 'Repository Visiblity',
type: 'string',
enum: ['private', 'public', 'internal'],
},
},
},
output: {
@@ -77,7 +82,7 @@ export function createPublishGithubAction(options: {
},
},
async handler(ctx) {
const { repoUrl, description, access } = ctx.parameters;
const { repoUrl, description, access, repoVisibility } = ctx.parameters;
const { owner, repo, host } = parseRepoUrl(repoUrl);
@@ -23,11 +23,11 @@ import { parseRepoUrl } from './util';
export function createPublishGitlabAction(options: {
integrations: ScmIntegrations;
repoVisibility: 'private' | 'internal' | 'public';
}): TemplateAction<{
repoUrl: string;
repoVisibility: 'private' | 'internal' | 'public';
}> {
const { integrations, repoVisibility } = options;
const { integrations } = options;
return {
id: 'publish:gitlab',
@@ -40,6 +40,11 @@ export function createPublishGitlabAction(options: {
title: 'Repository Location',
type: 'string',
},
repoVisibility: {
title: 'Repository Visiblity',
type: 'string',
enum: ['private', 'public', 'internal'],
},
},
},
output: {
@@ -57,7 +62,7 @@ export function createPublishGitlabAction(options: {
},
},
async handler(ctx) {
const { repoUrl } = ctx.parameters;
const { repoUrl, repoVisibility = 'private' } = ctx.parameters;
const { owner, repo, host } = parseRepoUrl(repoUrl);
@@ -152,20 +152,17 @@ export async function createRouter(
actionRegistry.register(
createPublishGithubAction({
integrations,
repoVisibility: 'public',
}),
);
actionRegistry.register(
createPublishGitlabAction({
integrations,
repoVisibility: 'public',
}),
);
actionRegistry.register(
createPublishBitbucketAction({
integrations,
repoVisibility: 'public',
}),
);