From 3b43fc3ab8671327662753d6119aa05a10b178a3 Mon Sep 17 00:00:00 2001 From: Crevil Date: Wed, 16 Jun 2021 16:49:45 +0200 Subject: [PATCH] Lowercase topics Signed-off-by: Crevil --- .../actions/builtin/publish/github.test.ts | 33 +++++++++++++++++++ .../actions/builtin/publish/github.ts | 3 +- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts index c59ba18bea..3dae202643 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts @@ -374,6 +374,39 @@ describe('publish:github', () => { }); }); + it('should lowercase topics when provided', async () => { + mockGithubClient.users.getByUsername.mockResolvedValue({ + data: { type: 'User' }, + }); + + mockGithubClient.repos.createForAuthenticatedUser.mockResolvedValue({ + data: { + clone_url: 'https://github.com/clone/url.git', + html_url: 'https://github.com/html/url', + }, + }); + + mockGithubClient.repos.replaceAllTopics.mockResolvedValue({ + data: { + names: ['backstage'], + }, + }); + + await action.handler({ + ...mockContext, + input: { + ...mockContext.input, + topics: ['BACKSTAGE'], + }, + }); + + expect(mockGithubClient.repos.replaceAllTopics).toHaveBeenCalledWith({ + owner: 'owner', + repo: 'repo', + names: ['backstage'], + }); + }); + it('should call output with the remoteUrl and the repoContentsUrl', async () => { mockGithubClient.users.getByUsername.mockResolvedValue({ data: { type: 'User' }, diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts index d7beabe0db..613cbe86d7 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts @@ -102,7 +102,6 @@ export function createPublishGithubAction(options: { }, topics: { title: 'Topics', - description: 'Uppercase letters no allowed', type: 'array', items: { type: 'string', @@ -230,7 +229,7 @@ export function createPublishGithubAction(options: { await client.repos.replaceAllTopics({ owner, repo, - names: topics, + names: topics.map(t => t.toLowerCase()), }); } catch (e) { ctx.logger.warn(`Skipping topics ${topics.join(' ')}, ${e.message}`);