From 562bd4cfe4f37c3e0727d3346c6e323a9e9897d7 Mon Sep 17 00:00:00 2001 From: djamaile Date: Thu, 9 Jun 2022 01:03:46 +0200 Subject: [PATCH 1/9] chore(gitlab MR action): remove projectId from template to because it is redundant Signed-off-by: djamaile --- .../builtin/publish/gitlabMergeRequest.ts | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts index 7259336b23..ab11787f05 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts @@ -34,7 +34,6 @@ export const createPublishGitlabMergeRequestAction = (options: { const { integrations } = options; return createTemplateAction<{ - projectid: string; repoUrl: string; title: string; description: string; @@ -45,7 +44,7 @@ export const createPublishGitlabMergeRequestAction = (options: { id: 'publish:gitlab:merge-request', schema: { input: { - required: ['projectid', 'repoUrl', 'targetPath', 'branchName'], + required: ['repoUrl', 'targetPath', 'branchName'], type: 'object', properties: { repoUrl: { @@ -53,11 +52,6 @@ export const createPublishGitlabMergeRequestAction = (options: { title: 'Repository Location', description: `Accepts the format 'gitlab.com/group_name/project_name' where 'project_name' is the repository name and 'group_name' is a group or username`, }, - projectid: { - type: 'string', - title: 'projectid', - description: 'Project ID/Name(slug) of the Gitlab Project', - }, title: { type: 'string', title: 'Merge Request Name', @@ -88,8 +82,8 @@ export const createPublishGitlabMergeRequestAction = (options: { output: { type: 'object', properties: { - projectid: { - title: 'Gitlab Project id/Name(slug)', + projectPath: { + title: 'Gitlab Project path', type: 'string', }, mergeRequestURL: { @@ -102,7 +96,9 @@ export const createPublishGitlabMergeRequestAction = (options: { }, async handler(ctx) { const repoUrl = ctx.input.repoUrl; - const { host } = parseRepoUrl(repoUrl, integrations); + const { host, owner, repo } = parseRepoUrl(repoUrl, integrations); + const projectPath = `${owner}/${repo}`; + const integrationConfig = integrations.gitlab.byHost(host); const destinationBranch = ctx.input.branchName; @@ -140,14 +136,13 @@ export const createPublishGitlabMergeRequestAction = (options: { content: file.content.toString('base64'), execute_filemode: file.executable, })); - - const projects = await api.Projects.show(ctx.input.projectid); + const projects = await api.Projects.show(projectPath); const { default_branch: defaultBranch } = projects; try { await api.Branches.create( - ctx.input.projectid, + projectPath, destinationBranch, String(defaultBranch), ); @@ -157,7 +152,7 @@ export const createPublishGitlabMergeRequestAction = (options: { try { await api.Commits.create( - ctx.input.projectid, + projectPath, destinationBranch, ctx.input.title, actions, @@ -170,7 +165,7 @@ export const createPublishGitlabMergeRequestAction = (options: { try { const mergeRequestUrl = await api.MergeRequests.create( - ctx.input.projectid, + projectPath, destinationBranch, String(defaultBranch), ctx.input.title, @@ -178,7 +173,7 @@ export const createPublishGitlabMergeRequestAction = (options: { ).then((mergeRequest: { web_url: string }) => { return mergeRequest.web_url; }); - ctx.output('projectid', ctx.input.projectid); + ctx.output('project path: ', projectPath); ctx.output('mergeRequestUrl', mergeRequestUrl); } catch (e) { throw new InputError(`Merge request creation failed${e}`); From 35a26131b3a07f746c8173317ed5c31fd6920e32 Mon Sep 17 00:00:00 2001 From: djamaile Date: Thu, 9 Jun 2022 01:17:05 +0200 Subject: [PATCH 2/9] chore: add changeset Signed-off-by: djamaile --- .changeset/forty-timers-cheer.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/forty-timers-cheer.md diff --git a/.changeset/forty-timers-cheer.md b/.changeset/forty-timers-cheer.md new file mode 100644 index 0000000000..29815fba67 --- /dev/null +++ b/.changeset/forty-timers-cheer.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend': minor +--- + +refactored the gitlab publish merge request action to not use the `projectId` property. Instead use the `host` and `owner` property from the `RepoUrlPicker`. This decreases the amount of fields the user has to fill in. From 7f78d71537f8fb22fbee525ae9b4800c1f1c351f Mon Sep 17 00:00:00 2001 From: djamaile Date: Thu, 9 Jun 2022 01:31:28 +0200 Subject: [PATCH 3/9] chore: run api report command to prevent build from breaking Signed-off-by: djamaile --- plugins/scaffolder-backend/api-report.md | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/scaffolder-backend/api-report.md b/plugins/scaffolder-backend/api-report.md index 308696d59b..51588054c0 100644 --- a/plugins/scaffolder-backend/api-report.md +++ b/plugins/scaffolder-backend/api-report.md @@ -338,7 +338,6 @@ export function createPublishGitlabAction(options: { export const createPublishGitlabMergeRequestAction: (options: { integrations: ScmIntegrationRegistry; }) => TemplateAction<{ - projectid: string; repoUrl: string; title: string; description: string; From 34b84b4072fb3546e97319fc012d52557b4d3755 Mon Sep 17 00:00:00 2001 From: djamaile Date: Thu, 9 Jun 2022 11:50:48 +0200 Subject: [PATCH 4/9] chore: make the changes backwards compatible to ease the migration Signed-off-by: djamaile --- .changeset/forty-timers-cheer.md | 5 +++-- .../actions/builtin/publish/gitlabMergeRequest.ts | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.changeset/forty-timers-cheer.md b/.changeset/forty-timers-cheer.md index 29815fba67..20ea9b90d4 100644 --- a/.changeset/forty-timers-cheer.md +++ b/.changeset/forty-timers-cheer.md @@ -1,5 +1,6 @@ --- -'@backstage/plugin-scaffolder-backend': minor +'@backstage/plugin-scaffolder-backend': major --- -refactored the gitlab publish merge request action to not use the `projectId` property. Instead use the `host` and `owner` property from the `RepoUrlPicker`. This decreases the amount of fields the user has to fill in. +**DEPRECATION**: The `projectid` input parameters to the `publish:gitlab:merge-request`, it's no longer required as it can be decoded from the `repoUrl` input parameter. +**DEPRECATION**: The `projectid` output of the action in favour of `projectPath` diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts index ab11787f05..d163a52d26 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts @@ -40,6 +40,8 @@ export const createPublishGitlabMergeRequestAction = (options: { branchName: string; targetPath: string; token?: string; + /** @deprecated */ + projectid?: string; }>({ id: 'publish:gitlab:merge-request', schema: { @@ -52,6 +54,12 @@ export const createPublishGitlabMergeRequestAction = (options: { title: 'Repository Location', description: `Accepts the format 'gitlab.com/group_name/project_name' where 'project_name' is the repository name and 'group_name' is a group or username`, }, + /** @deprecated */ + projectid: { + type: 'string', + title: 'projectid', + description: 'Project ID/Name(slug) of the Gitlab Project', + }, title: { type: 'string', title: 'Merge Request Name', @@ -82,6 +90,10 @@ export const createPublishGitlabMergeRequestAction = (options: { output: { type: 'object', properties: { + projectid: { + title: 'Gitlab Project id/Name(slug)', + type: 'string', + }, projectPath: { title: 'Gitlab Project path', type: 'string', @@ -173,7 +185,8 @@ export const createPublishGitlabMergeRequestAction = (options: { ).then((mergeRequest: { web_url: string }) => { return mergeRequest.web_url; }); - ctx.output('project path: ', projectPath); + ctx.output('projectid', projectPath); + ctx.output('projectPath', projectPath); ctx.output('mergeRequestUrl', mergeRequestUrl); } catch (e) { throw new InputError(`Merge request creation failed${e}`); From c8af5ea7b3b64fec05fdf4ce19ad517278326351 Mon Sep 17 00:00:00 2001 From: djamaile Date: Thu, 9 Jun 2022 12:09:39 +0200 Subject: [PATCH 5/9] chore: run api report command to prevent build from breaking Signed-off-by: djamaile --- plugins/scaffolder-backend/api-report.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/scaffolder-backend/api-report.md b/plugins/scaffolder-backend/api-report.md index 51588054c0..fbb071cd51 100644 --- a/plugins/scaffolder-backend/api-report.md +++ b/plugins/scaffolder-backend/api-report.md @@ -344,6 +344,7 @@ export const createPublishGitlabMergeRequestAction: (options: { branchName: string; targetPath: string; token?: string | undefined; + projectid?: string | undefined; }>; // @public @@ -709,4 +710,8 @@ export class TemplateActionRegistry { // @public (undocumented) export type TemplateFilter = (...args: JsonValue[]) => JsonValue | undefined; + +// Warnings were encountered during analysis: +// +// src/scaffolder/actions/builtin/publish/gitlabMergeRequest.d.ts:16:9 - (tsdoc-missing-deprecation-message) The @deprecated block must include a deprecation message, e.g. describing the recommended alternative ``` From d507278a0c31422b7e33f99577a45690b8751fc0 Mon Sep 17 00:00:00 2001 From: djamaile Date: Thu, 9 Jun 2022 12:40:21 +0200 Subject: [PATCH 6/9] chore: change major to minor because we haven't make any breaking changes Signed-off-by: djamaile --- .changeset/forty-timers-cheer.md | 2 +- .../scaffolder/actions/builtin/publish/gitlabMergeRequest.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.changeset/forty-timers-cheer.md b/.changeset/forty-timers-cheer.md index 20ea9b90d4..9fba60e6ed 100644 --- a/.changeset/forty-timers-cheer.md +++ b/.changeset/forty-timers-cheer.md @@ -1,5 +1,5 @@ --- -'@backstage/plugin-scaffolder-backend': major +'@backstage/plugin-scaffolder-backend': minor --- **DEPRECATION**: The `projectid` input parameters to the `publish:gitlab:merge-request`, it's no longer required as it can be decoded from the `repoUrl` input parameter. diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts index d163a52d26..07c094cba9 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts @@ -185,6 +185,7 @@ export const createPublishGitlabMergeRequestAction = (options: { ).then((mergeRequest: { web_url: string }) => { return mergeRequest.web_url; }); + /** @deprecated */ ctx.output('projectid', projectPath); ctx.output('projectPath', projectPath); ctx.output('mergeRequestUrl', mergeRequestUrl); From 890dfe614af5d28af2119ac23264dc7372a0a209 Mon Sep 17 00:00:00 2001 From: djamaile Date: Thu, 9 Jun 2022 14:46:01 +0200 Subject: [PATCH 7/9] chore: give alternative to deprecated projectId Signed-off-by: djamaile --- plugins/scaffolder-backend/api-report.md | 4 ---- .../actions/builtin/publish/gitlabMergeRequest.ts | 6 +++--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/plugins/scaffolder-backend/api-report.md b/plugins/scaffolder-backend/api-report.md index fbb071cd51..707b8e62ba 100644 --- a/plugins/scaffolder-backend/api-report.md +++ b/plugins/scaffolder-backend/api-report.md @@ -710,8 +710,4 @@ export class TemplateActionRegistry { // @public (undocumented) export type TemplateFilter = (...args: JsonValue[]) => JsonValue | undefined; - -// Warnings were encountered during analysis: -// -// src/scaffolder/actions/builtin/publish/gitlabMergeRequest.d.ts:16:9 - (tsdoc-missing-deprecation-message) The @deprecated block must include a deprecation message, e.g. describing the recommended alternative ``` diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts index 07c094cba9..c5dd41f807 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts @@ -40,7 +40,7 @@ export const createPublishGitlabMergeRequestAction = (options: { branchName: string; targetPath: string; token?: string; - /** @deprecated */ + /** @deprecated Use projectPath instead */ projectid?: string; }>({ id: 'publish:gitlab:merge-request', @@ -54,7 +54,7 @@ export const createPublishGitlabMergeRequestAction = (options: { title: 'Repository Location', description: `Accepts the format 'gitlab.com/group_name/project_name' where 'project_name' is the repository name and 'group_name' is a group or username`, }, - /** @deprecated */ + /** @deprecated Use projectPath instead */ projectid: { type: 'string', title: 'projectid', @@ -185,7 +185,7 @@ export const createPublishGitlabMergeRequestAction = (options: { ).then((mergeRequest: { web_url: string }) => { return mergeRequest.web_url; }); - /** @deprecated */ + /** @deprecated Use projectPath instead */ ctx.output('projectid', projectPath); ctx.output('projectPath', projectPath); ctx.output('mergeRequestUrl', mergeRequestUrl); From 6424c0ad6fd7be5af38af30fa9680fbbfe54d58d Mon Sep 17 00:00:00 2001 From: djamaile Date: Thu, 9 Jun 2022 14:51:07 +0200 Subject: [PATCH 8/9] chore: give alternative to deprecated projectId Signed-off-by: djamaile --- .../scaffolder/actions/builtin/publish/gitlabMergeRequest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts index c5dd41f807..8c2e9efeb2 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts @@ -185,7 +185,7 @@ export const createPublishGitlabMergeRequestAction = (options: { ).then((mergeRequest: { web_url: string }) => { return mergeRequest.web_url; }); - /** @deprecated Use projectPath instead */ + /** @deprecated */ ctx.output('projectid', projectPath); ctx.output('projectPath', projectPath); ctx.output('mergeRequestUrl', mergeRequestUrl); From 5179b8d80516604175e638e57f2feacdef1b4db6 Mon Sep 17 00:00:00 2001 From: djamaile Date: Thu, 9 Jun 2022 22:48:11 +0200 Subject: [PATCH 9/9] chore: add warning to notify user that projectid is deprecated Signed-off-by: djamaile --- .../actions/builtin/publish/gitlabMergeRequest.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts index 8c2e9efeb2..f717a7a0c6 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts @@ -111,6 +111,12 @@ export const createPublishGitlabMergeRequestAction = (options: { const { host, owner, repo } = parseRepoUrl(repoUrl, integrations); const projectPath = `${owner}/${repo}`; + if (ctx.input.projectid) { + const deprecationWarning = `Property "projectid" is deprecated and no longer to needed to create a MR`; + ctx.logger.warn(deprecationWarning); + console.warn(deprecationWarning); + } + const integrationConfig = integrations.gitlab.byHost(host); const destinationBranch = ctx.input.branchName;