feat: add publish:gitlab project settings support

Signed-off-by: Ilya Katlinski <ilya.katlinsky@gmail.com>
This commit is contained in:
Ilya Katlinski
2023-09-15 09:22:06 +02:00
parent 94cc96c932
commit 768d521c79
3 changed files with 76 additions and 1 deletions
@@ -68,4 +68,25 @@ export const examples: TemplateExample[] = [
],
}),
},
{
description: 'Initializes a git repository with additional settings.',
example: yaml.stringify({
steps: [
{
id: 'publish',
action: 'publish:gitlab',
name: 'Publish to GitLab',
input: {
repoUrl: 'gitlab.com?repo=project_name&owner=group_name',
settings: {
ci_config_path: '.gitlab-ci.yml',
visibility: 'public',
initialize_with_readme: true,
default_branch: 'main',
},
},
},
],
}),
},
];
@@ -77,6 +77,26 @@ describe('publish:gitlab', () => {
input: {
repoUrl: 'gitlab.com?repo=repo&owner=owner',
repoVisibility: 'private' as const,
settings: {
ci_config_path: '.gitlab-ci.yml',
},
},
workspacePath: 'lol',
logger: getVoidLogger(),
logStream: new PassThrough(),
output: jest.fn(),
createTemporaryDirectory: jest.fn(),
};
const mockContextWithOptions = {
input: {
repoUrl: 'gitlab.com?repo=repo&owner=owner',
repoVisibility: 'private' as const,
topics: ['topic'],
settings: {
ci_config_path: '.gitlab-ci.yml',
visibility: 'internal',
topics: ['topic1', 'topic2'],
},
},
workspacePath: 'lol',
logger: getVoidLogger(),
@@ -162,6 +182,7 @@ describe('publish:gitlab', () => {
namespace_id: 1234,
name: 'repo',
visibility: 'private',
ci_config_path: '.gitlab-ci.yml',
});
});
@@ -179,6 +200,26 @@ describe('publish:gitlab', () => {
namespace_id: 12345,
name: 'repo',
visibility: 'private',
ci_config_path: '.gitlab-ci.yml',
});
});
it('should call the correct Gitlab APIs when using project options with override of visibility and topics', async () => {
mockGitlabClient.Users.current.mockResolvedValue({ id: 12345 });
mockGitlabClient.Namespaces.show.mockResolvedValue({ id: 1234 });
mockGitlabClient.Projects.create.mockResolvedValue({
http_url_to_repo: 'http://mockurl.git',
});
await action.handler(mockContextWithOptions);
expect(mockGitlabClient.Namespaces.show).toHaveBeenCalledWith('owner');
expect(mockGitlabClient.Projects.create).toHaveBeenCalledWith({
namespace_id: 1234,
name: 'repo',
visibility: 'internal',
topics: ['topic1', 'topic2'],
ci_config_path: '.gitlab-ci.yml',
});
});
@@ -38,6 +38,7 @@ export function createPublishGitlabAction(options: {
return createTemplateAction<{
repoUrl: string;
defaultBranch?: string;
/** @deprecated in favour of settings field */
repoVisibility?: 'private' | 'internal' | 'public';
sourcePath?: string;
token?: string;
@@ -45,7 +46,9 @@ export function createPublishGitlabAction(options: {
gitAuthorName?: string;
gitAuthorEmail?: string;
setUserAsOwner?: boolean;
/** @deprecated in favour of settings field */
topics?: string[];
settings?: Record<string, any>;
}>({
id: 'publish:gitlab',
description:
@@ -63,6 +66,7 @@ export function createPublishGitlabAction(options: {
},
repoVisibility: {
title: 'Repository Visibility',
description: `Sets the visibility of the repository. The default value is 'private'. (deprecated, use settings instead)`,
type: 'string',
enum: ['private', 'public', 'internal'],
},
@@ -105,12 +109,19 @@ export function createPublishGitlabAction(options: {
},
topics: {
title: 'Topic labels',
description: 'Topic labels to apply on the repository.',
description:
'Topic labels to apply on the repository. (deprecated, use settings instead)',
type: 'array',
items: {
type: 'string',
},
},
settings: {
title: 'Project settings',
description:
'Additional project settings, based on https://docs.gitlab.com/ee/api/projects.html#create-project attributes',
type: 'object',
},
},
},
output: {
@@ -145,6 +156,7 @@ export function createPublishGitlabAction(options: {
gitAuthorEmail,
setUserAsOwner = false,
topics = [],
settings = {},
} = ctx.input;
const { owner, repo, host } = parseRepoUrl(repoUrl, integrations);
@@ -191,6 +203,7 @@ export function createPublishGitlabAction(options: {
name: repo,
visibility: repoVisibility,
...(topics.length ? { topics } : {}),
...(Object.keys(settings).length ? { ...settings } : {}),
});
// When setUserAsOwner is true the input token is expected to come from an unprivileged user GitLab