From 8183a407b07e79d7dd4595a14d4d8f89bae5bd63 Mon Sep 17 00:00:00 2001 From: Balasundaram Date: Mon, 29 Nov 2021 12:15:02 -0500 Subject: [PATCH 01/12] Adding changes for creating action for gitlab MR request during component registration similar to github Signed-off-by: Balasundaram --- .../actions/builtin/createBuiltinActions.ts | 4 + .../builtin/publish/gitlabMergeRequest.ts | 174 ++++++++++++++++++ .../actions/builtin/publish/index.ts | 1 + 3 files changed, 179 insertions(+) create mode 100644 plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/createBuiltinActions.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/createBuiltinActions.ts index d38dfe3cdc..2d916af77e 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/createBuiltinActions.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/createBuiltinActions.ts @@ -36,6 +36,7 @@ import { createPublishGithubAction, createPublishGithubPullRequestAction, createPublishGitlabAction, + createPublishGitlabMergeRequestAction, } from './publish'; import { createGithubActionsDispatchAction, @@ -77,6 +78,9 @@ export const createBuiltinActions = (options: { integrations, config, }), + createPublishGitlabMergeRequestAction({ + integrations, + }), createPublishBitbucketAction({ integrations, config, diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts new file mode 100644 index 0000000000..6ff10deb96 --- /dev/null +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts @@ -0,0 +1,174 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { createTemplateAction } from '../../createTemplateAction'; +import { readFile } from 'fs-extra'; +import { Gitlab } from '@gitbeaker/node'; +import path from 'path'; +import globby from 'globby'; +import { CommitAction } from '@gitbeaker/core/dist/types/services/Commits'; +import { CreateMergeRequestOptions } from '@gitbeaker/core/dist/types/services/MergeRequests'; +import { ScmIntegrationRegistry } from '@backstage/integration'; +import { InputError } from '@backstage/errors'; +import { parseRepoUrl } from './util'; + +export type GitlabMergeRequestActionInput = { + projectid: string; + repoUrl: string; + title: string; + description: string; + destinationBranch: string; + targetPath: string; + }; + +export const createPublishGitlabMergeRequestAction = (options: { + integrations: ScmIntegrationRegistry; + }) => { + const { integrations } = options; + + return createTemplateAction({ + id: 'publish:gitlab-merge-request', + schema: { + input: { + required: ['projectid', 'repoUrl', 'targetPath'], + type: 'object', + properties: { + repoUrl: { + type: 'string', + 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 of the Gitlab Project', + }, + title: { + type: 'string', + title: 'Merge Request Name', + description: 'The name for the merge request', + }, + description: { + type: 'string', + title: 'Merge Request Description', + description: 'The description of the merge request', + }, + destinationBranch: { + type: 'string', + title: 'Destination Branch name', + description: 'The description of the merge request', + }, + targetPath: { + type: 'string', + title: 'Repository Subdirectory', + description: 'Subdirectory of repository to apply changes to', + } + }, + }, + output: { + type: 'object', + properties: { + projectid : { + title: 'Gitlab Project id', + type: 'string', + }, + mergeRequestURL: { + title: 'MergeRequest(MR) URL', + type: 'string', + description: 'Link to the merge request in GitLab', + }, + }, + }, + }, + async handler(ctx) { + const repoUrl = ctx.input.repoUrl; + const { host } = parseRepoUrl(repoUrl, integrations); + const integrationConfig = integrations.gitlab.byHost(host); + + let actions: CommitAction[] = []; + const formatedTimestamp = ()=> { + const d = new Date() + const date = d.toISOString().split('T')[0]; + const time = d.toTimeString().split(' ')[0].replace(/:/g, "_"); + return `${date}_${time}` + } + const destinationBranch = ctx.input.destinationBranch? ctx.input.destinationBranch + formatedTimestamp(): `backstage_${formatedTimestamp()}`; + + if (!integrationConfig) { + throw new InputError( + `No matching integration configuration for host ${host}, please check your integrations config`, + ); + } + + if (!integrationConfig.config.token) { + throw new InputError(`No token available for host ${host}`); + } + + const api = new Gitlab({ + host: integrationConfig.config.baseUrl, + token: integrationConfig.config.token, + }); + + const fileRoot = ctx.workspacePath; + const localFilePaths = await globby([`${ctx.input.targetPath}'/**'`], { + cwd: fileRoot, + gitignore: true, + dot: true, + }); + + const fileContents = await Promise.all( + localFilePaths.map(p => readFile(path.resolve(fileRoot, p))), + ); + + const repoFilePaths = localFilePaths.map(repoFilePath => { + return repoFilePath; + }); + + for(let i=0; i { + return projectJSON?.default_branch; + }); + + try { + await api.Branches.create(ctx.input.projectid, destinationBranch, defaultBranch).then((branchResponse) => { + return branchResponse; + }); + } catch(e) { + throw new InputError(`The branch creation failed ` + e); + } + + try { + await api.Commits.create(ctx.input.projectid, destinationBranch, ctx.input.title, actions); + } catch(e) { + throw new InputError(`Committing the changes to ` + destinationBranch + ` failed ` + e); + } + + try { + let mergeRequestUrl: any = await api.MergeRequests.create(ctx.input.projectid, destinationBranch, defaultBranch, ctx.input.title, { description: ctx.input.description }).then((mergeRequest) => { + return mergeRequest.web_url + }); + ctx.output('projectid', ctx.input.projectid); + ctx.output('mergeRequestUrl', mergeRequestUrl); + } + catch(e) { + throw new InputError(`Merge request creation failed` + e); + } + }, + }); +}; \ No newline at end of file diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/index.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/index.ts index a292438d3a..75af6e190f 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/index.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/index.ts @@ -20,3 +20,4 @@ export { createPublishFileAction } from './file'; export { createPublishGithubAction } from './github'; export { createPublishGithubPullRequestAction } from './githubPullRequest'; export { createPublishGitlabAction } from './gitlab'; +export { createPublishGitlabMergeRequestAction } from './gitlabMergeRequest'; \ No newline at end of file From 86ac8d6cdb6fe45b9f2f434bedcc96863288b014 Mon Sep 17 00:00:00 2001 From: Balasundaram Date: Mon, 29 Nov 2021 13:43:47 -0500 Subject: [PATCH 02/12] Adding prettier changes Signed-off-by: Balasundaram --- .../builtin/publish/gitlabMergeRequest.ts | 289 ++++++++++-------- 1 file changed, 156 insertions(+), 133 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 6ff10deb96..19aeabefdd 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts @@ -19,156 +19,179 @@ import { Gitlab } from '@gitbeaker/node'; import path from 'path'; import globby from 'globby'; import { CommitAction } from '@gitbeaker/core/dist/types/services/Commits'; -import { CreateMergeRequestOptions } from '@gitbeaker/core/dist/types/services/MergeRequests'; +import { CreateMergeRequestOptions } from '@gitbeaker/core/dist/types/services/MergeRequests'; import { ScmIntegrationRegistry } from '@backstage/integration'; import { InputError } from '@backstage/errors'; import { parseRepoUrl } from './util'; export type GitlabMergeRequestActionInput = { - projectid: string; - repoUrl: string; - title: string; - description: string; - destinationBranch: string; - targetPath: string; - }; + projectid: string; + repoUrl: string; + title: string; + description: string; + destinationBranch: string; + targetPath: string; +}; export const createPublishGitlabMergeRequestAction = (options: { - integrations: ScmIntegrationRegistry; - }) => { - const { integrations } = options; + integrations: ScmIntegrationRegistry; +}) => { + const { integrations } = options; - return createTemplateAction({ - id: 'publish:gitlab-merge-request', - schema: { - input: { - required: ['projectid', 'repoUrl', 'targetPath'], - type: 'object', - properties: { - repoUrl: { - type: 'string', - 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 of the Gitlab Project', - }, - title: { - type: 'string', - title: 'Merge Request Name', - description: 'The name for the merge request', - }, - description: { - type: 'string', - title: 'Merge Request Description', - description: 'The description of the merge request', - }, - destinationBranch: { - type: 'string', - title: 'Destination Branch name', - description: 'The description of the merge request', - }, - targetPath: { - type: 'string', - title: 'Repository Subdirectory', - description: 'Subdirectory of repository to apply changes to', - } - }, - }, - output: { - type: 'object', - properties: { - projectid : { - title: 'Gitlab Project id', - type: 'string', - }, - mergeRequestURL: { - title: 'MergeRequest(MR) URL', - type: 'string', - description: 'Link to the merge request in GitLab', - }, - }, - }, - }, - async handler(ctx) { - const repoUrl = ctx.input.repoUrl; - const { host } = parseRepoUrl(repoUrl, integrations); - const integrationConfig = integrations.gitlab.byHost(host); + return createTemplateAction({ + id: 'publish:gitlab-merge-request', + schema: { + input: { + required: ['projectid', 'repoUrl', 'targetPath'], + type: 'object', + properties: { + repoUrl: { + type: 'string', + 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 of the Gitlab Project', + }, + title: { + type: 'string', + title: 'Merge Request Name', + description: 'The name for the merge request', + }, + description: { + type: 'string', + title: 'Merge Request Description', + description: 'The description of the merge request', + }, + destinationBranch: { + type: 'string', + title: 'Destination Branch name', + description: 'The description of the merge request', + }, + targetPath: { + type: 'string', + title: 'Repository Subdirectory', + description: 'Subdirectory of repository to apply changes to', + }, + }, + }, + output: { + type: 'object', + properties: { + projectid: { + title: 'Gitlab Project id', + type: 'string', + }, + mergeRequestURL: { + title: 'MergeRequest(MR) URL', + type: 'string', + description: 'Link to the merge request in GitLab', + }, + }, + }, + }, + async handler(ctx) { + const repoUrl = ctx.input.repoUrl; + const { host } = parseRepoUrl(repoUrl, integrations); + const integrationConfig = integrations.gitlab.byHost(host); - let actions: CommitAction[] = []; - const formatedTimestamp = ()=> { - const d = new Date() - const date = d.toISOString().split('T')[0]; - const time = d.toTimeString().split(' ')[0].replace(/:/g, "_"); - return `${date}_${time}` - } - const destinationBranch = ctx.input.destinationBranch? ctx.input.destinationBranch + formatedTimestamp(): `backstage_${formatedTimestamp()}`; + const actions: CommitAction[] = []; + const formatedTimestamp = () => { + const d = new Date(); + const date = d.toISOString().split('T')[0]; + const time = d.toTimeString().split(' ')[0].replace(/:/g, '_'); + return `${date}_${time}`; + }; + const destinationBranch = ctx.input.destinationBranch + ? ctx.input.destinationBranch + formatedTimestamp() + : `backstage_${formatedTimestamp()}`; - if (!integrationConfig) { - throw new InputError( - `No matching integration configuration for host ${host}, please check your integrations config`, - ); - } + if (!integrationConfig) { + throw new InputError( + `No matching integration configuration for host ${host}, please check your integrations config`, + ); + } - if (!integrationConfig.config.token) { - throw new InputError(`No token available for host ${host}`); - } + if (!integrationConfig.config.token) { + throw new InputError(`No token available for host ${host}`); + } - const api = new Gitlab({ - host: integrationConfig.config.baseUrl, - token: integrationConfig.config.token, - }); + const api = new Gitlab({ + host: integrationConfig.config.baseUrl, + token: integrationConfig.config.token, + }); - const fileRoot = ctx.workspacePath; - const localFilePaths = await globby([`${ctx.input.targetPath}'/**'`], { - cwd: fileRoot, - gitignore: true, - dot: true, - }); + const fileRoot = ctx.workspacePath; + const localFilePaths = await globby([`${ctx.input.targetPath}'/**'`], { + cwd: fileRoot, + gitignore: true, + dot: true, + }); - const fileContents = await Promise.all( - localFilePaths.map(p => readFile(path.resolve(fileRoot, p))), - ); + const fileContents = await Promise.all( + localFilePaths.map(p => readFile(path.resolve(fileRoot, p))), + ); - const repoFilePaths = localFilePaths.map(repoFilePath => { - return repoFilePath; - }); + const repoFilePaths = localFilePaths.map(repoFilePath => { + return repoFilePath; + }); - for(let i=0; i { + return projectJSON?.default_branch; + }); - const defaultBranch: any = await api.Projects.show(ctx.input.projectid).then((projectJSON) => { - return projectJSON?.default_branch; - }); + try { + await api.Branches.create( + ctx.input.projectid, + destinationBranch, + defaultBranch, + ).then(branchResponse => { + return branchResponse; + }); + } catch (e) { + throw new InputError(`The branch creation failed ${e}`); + } - try { - await api.Branches.create(ctx.input.projectid, destinationBranch, defaultBranch).then((branchResponse) => { - return branchResponse; - }); - } catch(e) { - throw new InputError(`The branch creation failed ` + e); - } + try { + await api.Commits.create( + ctx.input.projectid, + destinationBranch, + ctx.input.title, + actions, + ); + } catch (e) { + throw new InputError( + `Committing the changes to ${destinationBranch} failed ${e}`, + ); + } - try { - await api.Commits.create(ctx.input.projectid, destinationBranch, ctx.input.title, actions); - } catch(e) { - throw new InputError(`Committing the changes to ` + destinationBranch + ` failed ` + e); - } - - try { - let mergeRequestUrl: any = await api.MergeRequests.create(ctx.input.projectid, destinationBranch, defaultBranch, ctx.input.title, { description: ctx.input.description }).then((mergeRequest) => { - return mergeRequest.web_url - }); - ctx.output('projectid', ctx.input.projectid); - ctx.output('mergeRequestUrl', mergeRequestUrl); - } - catch(e) { - throw new InputError(`Merge request creation failed` + e); - } - }, - }); -}; \ No newline at end of file + try { + const mergeRequestUrl: any = await api.MergeRequests.create( + ctx.input.projectid, + destinationBranch, + defaultBranch, + ctx.input.title, + { description: ctx.input.description }, + ).then(mergeRequest => { + return mergeRequest.web_url; + }); + ctx.output('projectid', ctx.input.projectid); + ctx.output('mergeRequestUrl', mergeRequestUrl); + } catch (e) { + throw new InputError(`Merge request creation failed${e}`); + } + }, + }); +}; From d9d2ff253d40098c8230d0509e67185a6a5f1f0e Mon Sep 17 00:00:00 2001 From: Balasundaram Date: Tue, 30 Nov 2021 06:44:27 -0500 Subject: [PATCH 03/12] Adding prettier for index.ts Signed-off-by: Balasundaram --- .../src/scaffolder/actions/builtin/publish/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/index.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/index.ts index 75af6e190f..c42b04e55e 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/index.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/index.ts @@ -20,4 +20,4 @@ export { createPublishFileAction } from './file'; export { createPublishGithubAction } from './github'; export { createPublishGithubPullRequestAction } from './githubPullRequest'; export { createPublishGitlabAction } from './gitlab'; -export { createPublishGitlabMergeRequestAction } from './gitlabMergeRequest'; \ No newline at end of file +export { createPublishGitlabMergeRequestAction } from './gitlabMergeRequest'; From 89599a43c628b6b7004fe7aa8301b40f2597b744 Mon Sep 17 00:00:00 2001 From: Balasundaram Date: Wed, 1 Dec 2021 12:50:16 -0500 Subject: [PATCH 04/12] Adding changes for PR review comments Signed-off-by: Balasundaram --- .../builtin/publish/gitlabMergeRequest.ts | 32 +++++++------------ 1 file changed, 11 insertions(+), 21 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 19aeabefdd..0928ff3b6d 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts @@ -16,20 +16,19 @@ import { createTemplateAction } from '../../createTemplateAction'; import { readFile } from 'fs-extra'; import { Gitlab } from '@gitbeaker/node'; -import path from 'path'; import globby from 'globby'; import { CommitAction } from '@gitbeaker/core/dist/types/services/Commits'; -import { CreateMergeRequestOptions } from '@gitbeaker/core/dist/types/services/MergeRequests'; import { ScmIntegrationRegistry } from '@backstage/integration'; import { InputError } from '@backstage/errors'; import { parseRepoUrl } from './util'; +import { resolveSafeChildPath } from '@backstage/backend-common'; export type GitlabMergeRequestActionInput = { projectid: string; repoUrl: string; title: string; description: string; - destinationBranch: string; + branchName: string; targetPath: string; }; @@ -39,10 +38,10 @@ export const createPublishGitlabMergeRequestAction = (options: { const { integrations } = options; return createTemplateAction({ - id: 'publish:gitlab-merge-request', + id: 'publish:gitlab:merge-request', schema: { input: { - required: ['projectid', 'repoUrl', 'targetPath'], + required: ['projectid', 'repoUrl', 'targetPath', 'branchName'], type: 'object', properties: { repoUrl: { @@ -65,7 +64,7 @@ export const createPublishGitlabMergeRequestAction = (options: { title: 'Merge Request Description', description: 'The description of the merge request', }, - destinationBranch: { + branchName: { type: 'string', title: 'Destination Branch name', description: 'The description of the merge request', @@ -98,15 +97,8 @@ export const createPublishGitlabMergeRequestAction = (options: { const integrationConfig = integrations.gitlab.byHost(host); const actions: CommitAction[] = []; - const formatedTimestamp = () => { - const d = new Date(); - const date = d.toISOString().split('T')[0]; - const time = d.toTimeString().split(' ')[0].replace(/:/g, '_'); - return `${date}_${time}`; - }; - const destinationBranch = ctx.input.destinationBranch - ? ctx.input.destinationBranch + formatedTimestamp() - : `backstage_${formatedTimestamp()}`; + + const destinationBranch = ctx.input.branchName; if (!integrationConfig) { throw new InputError( @@ -124,14 +116,14 @@ export const createPublishGitlabMergeRequestAction = (options: { }); const fileRoot = ctx.workspacePath; - const localFilePaths = await globby([`${ctx.input.targetPath}'/**'`], { + const localFilePaths = await globby([`${ctx.input.targetPath}/**`], { cwd: fileRoot, gitignore: true, dot: true, }); const fileContents = await Promise.all( - localFilePaths.map(p => readFile(path.resolve(fileRoot, p))), + localFilePaths.map(p => readFile(resolveSafeChildPath(fileRoot, p))), ); const repoFilePaths = localFilePaths.map(repoFilePath => { @@ -146,11 +138,9 @@ export const createPublishGitlabMergeRequestAction = (options: { }); } - const defaultBranch: any = await api.Projects.show( + const { default_branch: defaultBranch }: any = await api.Projects.show( ctx.input.projectid, - ).then(projectJSON => { - return projectJSON?.default_branch; - }); + ); try { await api.Branches.create( From a955e16875ca60e4a8ffe954704528fb64909d7a Mon Sep 17 00:00:00 2001 From: Balasundaram Date: Thu, 2 Dec 2021 10:49:14 -0500 Subject: [PATCH 05/12] Adding changes for PR review comments II Signed-off-by: Balasundaram --- .../actions/builtin/publish/gitlabMergeRequest.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 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 0928ff3b6d..8238d040b2 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts @@ -138,15 +138,15 @@ export const createPublishGitlabMergeRequestAction = (options: { }); } - const { default_branch: defaultBranch }: any = await api.Projects.show( - ctx.input.projectid, - ); + const projects = await api.Projects.show(ctx.input.projectid); + + const { default_branch: defaultBranch } = projects; try { await api.Branches.create( ctx.input.projectid, destinationBranch, - defaultBranch, + String(defaultBranch), ).then(branchResponse => { return branchResponse; }); @@ -171,7 +171,7 @@ export const createPublishGitlabMergeRequestAction = (options: { const mergeRequestUrl: any = await api.MergeRequests.create( ctx.input.projectid, destinationBranch, - defaultBranch, + String(defaultBranch), ctx.input.title, { description: ctx.input.description }, ).then(mergeRequest => { From 8ee5b6f3dd7da14a8f0495a31ab7fe38cd4bad46 Mon Sep 17 00:00:00 2001 From: Balasundaram Date: Wed, 8 Dec 2021 16:34:09 -0500 Subject: [PATCH 06/12] Adding changes for PR review comments III Signed-off-by: Balasundaram --- plugins/scaffolder-backend/package.json | 4 ++-- .../builtin/publish/gitlabMergeRequest.ts | 17 ++++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/plugins/scaffolder-backend/package.json b/plugins/scaffolder-backend/package.json index fe5d61d4d3..21f554779f 100644 --- a/plugins/scaffolder-backend/package.json +++ b/plugins/scaffolder-backend/package.json @@ -40,8 +40,8 @@ "@backstage/plugin-scaffolder-common": "^0.1.1", "@backstage/plugin-scaffolder-backend-module-cookiecutter": "^0.1.3", "@backstage/types": "^0.1.1", - "@gitbeaker/core": "^30.2.0", - "@gitbeaker/node": "^30.2.0", + "@gitbeaker/core": "^35.1.0", + "@gitbeaker/node": "^35.1.0", "@octokit/rest": "^18.5.3", "@octokit/webhooks": "^9.14.1", "@types/express": "^4.17.6", 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 8238d040b2..b333b5234d 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts @@ -17,7 +17,8 @@ import { createTemplateAction } from '../../createTemplateAction'; import { readFile } from 'fs-extra'; import { Gitlab } from '@gitbeaker/node'; import globby from 'globby'; -import { CommitAction } from '@gitbeaker/core/dist/types/services/Commits'; +import { Types } from '@gitbeaker/core'; + import { ScmIntegrationRegistry } from '@backstage/integration'; import { InputError } from '@backstage/errors'; import { parseRepoUrl } from './util'; @@ -96,7 +97,11 @@ export const createPublishGitlabMergeRequestAction = (options: { const { host } = parseRepoUrl(repoUrl, integrations); const integrationConfig = integrations.gitlab.byHost(host); - const actions: CommitAction[] = []; + /* const a : Types.CommitAction = { + action: 'create', + filePath: '' + };*/ + const actions: Types.CommitAction[] = []; const destinationBranch = ctx.input.branchName; @@ -147,9 +152,7 @@ export const createPublishGitlabMergeRequestAction = (options: { ctx.input.projectid, destinationBranch, String(defaultBranch), - ).then(branchResponse => { - return branchResponse; - }); + ); } catch (e) { throw new InputError(`The branch creation failed ${e}`); } @@ -168,13 +171,13 @@ export const createPublishGitlabMergeRequestAction = (options: { } try { - const mergeRequestUrl: any = await api.MergeRequests.create( + const mergeRequestUrl = await api.MergeRequests.create( ctx.input.projectid, destinationBranch, String(defaultBranch), ctx.input.title, { description: ctx.input.description }, - ).then(mergeRequest => { + ).then((mergeRequest: { web_url: string }) => { return mergeRequest.web_url; }); ctx.output('projectid', ctx.input.projectid); From 90f8f33355fd3a15fe68fcc08eb4d3c409dc1db8 Mon Sep 17 00:00:00 2001 From: Balasundaram Date: Thu, 9 Dec 2021 12:57:18 -0500 Subject: [PATCH 07/12] Adding changes for PR review comments to add description for projectname Signed-off-by: Balasundaram --- .../scaffolder/actions/builtin/publish/gitlabMergeRequest.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 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 b333b5234d..b64ec1a83d 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts @@ -53,7 +53,7 @@ export const createPublishGitlabMergeRequestAction = (options: { projectid: { type: 'string', title: 'projectid', - description: 'Project ID of the Gitlab Project', + description: 'Project ID/Name(slug) of the Gitlab Project', }, title: { type: 'string', @@ -81,7 +81,7 @@ export const createPublishGitlabMergeRequestAction = (options: { type: 'object', properties: { projectid: { - title: 'Gitlab Project id', + title: 'Gitlab Project id/Name(slug)', type: 'string', }, mergeRequestURL: { From ed52f74ab3c2dceb27f07bd0ba509fdcf732a673 Mon Sep 17 00:00:00 2001 From: Balasundaram Date: Thu, 9 Dec 2021 13:06:04 -0500 Subject: [PATCH 08/12] Adding changeset for the #8277 Signed-off-by: Balasundaram --- .changeset/nervous-hounds-attend.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/nervous-hounds-attend.md diff --git a/.changeset/nervous-hounds-attend.md b/.changeset/nervous-hounds-attend.md new file mode 100644 index 0000000000..a9eed8422d --- /dev/null +++ b/.changeset/nervous-hounds-attend.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend': minor +--- + +Adding changes to create Gitlab Merge Request using custom action From 646e5d01d8baff61429be714451528bc0d7fa81d Mon Sep 17 00:00:00 2001 From: Balasundaram Date: Thu, 9 Dec 2021 13:13:04 -0500 Subject: [PATCH 09/12] Changing minor to patch changeset for the #8277 Signed-off-by: Balasundaram --- .changeset/nervous-hounds-attend.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/nervous-hounds-attend.md b/.changeset/nervous-hounds-attend.md index a9eed8422d..15ca4aa085 100644 --- a/.changeset/nervous-hounds-attend.md +++ b/.changeset/nervous-hounds-attend.md @@ -1,5 +1,5 @@ --- -'@backstage/plugin-scaffolder-backend': minor +'@backstage/plugin-scaffolder-backend': patch --- Adding changes to create Gitlab Merge Request using custom action From ccf48de9ba82aa62d23b4e3f4aa0a4dcc66b660a Mon Sep 17 00:00:00 2001 From: Balasundaram Date: Thu, 9 Dec 2021 13:16:48 -0500 Subject: [PATCH 10/12] Adding changes to remove comments Signed-off-by: Balasundaram --- .../scaffolder/actions/builtin/publish/gitlabMergeRequest.ts | 4 ---- 1 file changed, 4 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 b64ec1a83d..2ac369249b 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlabMergeRequest.ts @@ -97,10 +97,6 @@ export const createPublishGitlabMergeRequestAction = (options: { const { host } = parseRepoUrl(repoUrl, integrations); const integrationConfig = integrations.gitlab.byHost(host); - /* const a : Types.CommitAction = { - action: 'create', - filePath: '' - };*/ const actions: Types.CommitAction[] = []; const destinationBranch = ctx.input.branchName; From a516412bb3777ea59af09a995cdb6fb4df0b8e33 Mon Sep 17 00:00:00 2001 From: Balasundaram Date: Thu, 9 Dec 2021 14:50:19 -0500 Subject: [PATCH 11/12] Adding public api report Signed-off-by: Balasundaram --- plugins/scaffolder-backend/api-report.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/scaffolder-backend/api-report.md b/plugins/scaffolder-backend/api-report.md index 6ed4625f66..bf03443419 100644 --- a/plugins/scaffolder-backend/api-report.md +++ b/plugins/scaffolder-backend/api-report.md @@ -179,6 +179,13 @@ export function createPublishGitlabAction(options: { config: Config; }): TemplateAction; +// Warning: (ae-missing-release-tag) "createPublishGitlabMergeRequestAction" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export const createPublishGitlabMergeRequestAction: (options: { + integrations: ScmIntegrationRegistry; +}) => TemplateAction; + // Warning: (ae-missing-release-tag) "createRouter" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) From 8ab8c30f1b67b720c09525500476eb21eb2cc4cf Mon Sep 17 00:00:00 2001 From: Balasundaram Date: Mon, 13 Dec 2021 11:10:20 -0500 Subject: [PATCH 12/12] Adding fixes for changeset spelling Signed-off-by: Balasundaram --- .changeset/nervous-hounds-attend.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/nervous-hounds-attend.md b/.changeset/nervous-hounds-attend.md index 15ca4aa085..b54eb5a688 100644 --- a/.changeset/nervous-hounds-attend.md +++ b/.changeset/nervous-hounds-attend.md @@ -2,4 +2,4 @@ '@backstage/plugin-scaffolder-backend': patch --- -Adding changes to create Gitlab Merge Request using custom action +Adding changes to create GitLab Merge Request using custom action