From 761a8aed663d51c4c842810b3f1392bb663f7e4b Mon Sep 17 00:00:00 2001 From: Josh Maxwell Date: Mon, 24 Oct 2022 22:53:49 -0600 Subject: [PATCH 1/7] Adding optional string array of topics to publish gitlab action Signed-off-by: Josh Maxwell --- .../src/scaffolder/actions/builtin/publish/gitlab.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts index 9fc95b1b5e..376667fffc 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts @@ -44,6 +44,7 @@ export function createPublishGitlabAction(options: { gitAuthorName?: string; gitAuthorEmail?: string; setUserAsOwner?: boolean; + topics?: string[]; }>({ id: 'publish:gitlab', description: @@ -99,6 +100,14 @@ export function createPublishGitlabAction(options: { description: 'Set the token user as owner of the newly created repository. Requires a token authorized to do the edit in the integration configuration for the matching host', }, + topics: { + title: 'Topic labels', + description: 'Topic labels to apply on the repository.', + type: 'array', + items: { + type: 'string', + }, + }, }, }, output: { @@ -128,6 +137,7 @@ export function createPublishGitlabAction(options: { gitAuthorName, gitAuthorEmail, setUserAsOwner = false, + topics = [], } = ctx.input; const { owner, repo, host } = parseRepoUrl(repoUrl, integrations); @@ -175,6 +185,8 @@ export function createPublishGitlabAction(options: { visibility: repoVisibility, }); + await client.Projects.edit(projectId, {topics}); + // When setUserAsOwner is true the input token is expected to come from an unprivileged user GitLab // OAuth flow. In this case GitLab works in a way that allows the unprivileged user to // create the repository, but not to push the default protected branch (e.g. master). From 840ff77576e577c6ea2b22913530084827d22c9f Mon Sep 17 00:00:00 2001 From: Josh Maxwell Date: Mon, 24 Oct 2022 23:03:35 -0600 Subject: [PATCH 2/7] Checking for topics before trying to add them to Project Signed-off-by: Josh Maxwell --- .../src/scaffolder/actions/builtin/publish/gitlab.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts index 376667fffc..e4f1b759a8 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts @@ -185,7 +185,9 @@ export function createPublishGitlabAction(options: { visibility: repoVisibility, }); - await client.Projects.edit(projectId, {topics}); + if (topics.length) { + await client.Projects.edit(projectId, {topics}); + } // When setUserAsOwner is true the input token is expected to come from an unprivileged user GitLab // OAuth flow. In this case GitLab works in a way that allows the unprivileged user to From 5025d2e8b6d5e1eee8f7c00a96f90884d0968bc4 Mon Sep 17 00:00:00 2001 From: Josh Maxwell Date: Mon, 24 Oct 2022 23:09:57 -0600 Subject: [PATCH 3/7] Adding changeset Signed-off-by: Josh Maxwell --- .changeset/large-spies-doubt.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/large-spies-doubt.md diff --git a/.changeset/large-spies-doubt.md b/.changeset/large-spies-doubt.md new file mode 100644 index 0000000000..620d8cf53e --- /dev/null +++ b/.changeset/large-spies-doubt.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend': patch +--- + +Adds the ability to pass (an optional) array of strings that will be applied to the newly scaffolded repository as topic labels. From 8a77c639a113231955933dbb0f00c32d2e2284c1 Mon Sep 17 00:00:00 2001 From: Josh Maxwell Date: Mon, 24 Oct 2022 23:15:08 -0600 Subject: [PATCH 4/7] Prettier -w Signed-off-by: Josh Maxwell --- .../src/scaffolder/actions/builtin/publish/gitlab.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts index e4f1b759a8..c7a811a4d2 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts @@ -186,7 +186,7 @@ export function createPublishGitlabAction(options: { }); if (topics.length) { - await client.Projects.edit(projectId, {topics}); + await client.Projects.edit(projectId, { topics }); } // When setUserAsOwner is true the input token is expected to come from an unprivileged user GitLab From 69a6e87b07352a9a3e00fcaea4be899c964686bc Mon Sep 17 00:00:00 2001 From: Josh Maxwell Date: Mon, 24 Oct 2022 23:29:20 -0600 Subject: [PATCH 5/7] Adding API Report Signed-off-by: Josh Maxwell --- plugins/scaffolder-backend/api-report.md | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/scaffolder-backend/api-report.md b/plugins/scaffolder-backend/api-report.md index 846fa59b08..f32cd42c6b 100644 --- a/plugins/scaffolder-backend/api-report.md +++ b/plugins/scaffolder-backend/api-report.md @@ -422,6 +422,7 @@ export function createPublishGitlabAction(options: { gitAuthorName?: string | undefined; gitAuthorEmail?: string | undefined; setUserAsOwner?: boolean | undefined; + topics?: string[] | undefined; }>; // @public From 0ea0d474f4d273b04912f66073ec9fbce585119b Mon Sep 17 00:00:00 2001 From: Josh Maxwell Date: Tue, 25 Oct 2022 08:16:44 -0600 Subject: [PATCH 6/7] Moving topics into initial project creation rather than a secondary call Signed-off-by: Josh Maxwell --- .../src/scaffolder/actions/builtin/publish/gitlab.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts index c7a811a4d2..53669efd0b 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts @@ -183,12 +183,9 @@ export function createPublishGitlabAction(options: { namespace_id: targetNamespace, name: repo, visibility: repoVisibility, + ...(topics.length ? { topics } : {}), }); - if (topics.length) { - await client.Projects.edit(projectId, { topics }); - } - // When setUserAsOwner is true the input token is expected to come from an unprivileged user GitLab // OAuth flow. In this case GitLab works in a way that allows the unprivileged user to // create the repository, but not to push the default protected branch (e.g. master). From e8528d3befa8ca9927c9475bc4e3fb04815ab203 Mon Sep 17 00:00:00 2001 From: Josh Maxwell Date: Tue, 25 Oct 2022 08:17:24 -0600 Subject: [PATCH 7/7] updating changeset type from patch -> minor Signed-off-by: Josh Maxwell --- .changeset/large-spies-doubt.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/large-spies-doubt.md b/.changeset/large-spies-doubt.md index 620d8cf53e..d81b31df28 100644 --- a/.changeset/large-spies-doubt.md +++ b/.changeset/large-spies-doubt.md @@ -1,5 +1,5 @@ --- -'@backstage/plugin-scaffolder-backend': patch +'@backstage/plugin-scaffolder-backend': minor --- Adds the ability to pass (an optional) array of strings that will be applied to the newly scaffolded repository as topic labels.