From 7cdbb244a1959630fee003e7c42e668cd460da5a Mon Sep 17 00:00:00 2001 From: Matt Benson Date: Wed, 25 Sep 2024 09:31:27 -0500 Subject: [PATCH] improve efficiency when commit is explicitly skipped Signed-off-by: Matt Benson --- .../src/actions/gitlabMergeRequest.ts | 57 ++++++++++--------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabMergeRequest.ts b/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabMergeRequest.ts index a719176bd7..616fdc1fd2 100644 --- a/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabMergeRequest.ts +++ b/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabMergeRequest.ts @@ -276,33 +276,36 @@ which uses additional API calls in order to detect whether to 'create', 'update' } } - const actions: Types.CommitAction[] = ( - ( - await Promise.all( - fileContents.map(async file => - getFileAction( - { file, targetPath }, - { repoID, branch: targetBranch! }, - api, - ctx, - remoteFiles, - ctx.input.commitAction, - ).then(action => ({ file, action })), - ), - ) - ).filter(o => o.action !== 'skip') as { - file: SerializedFile; - action: Types.CommitAction['action']; - }[] - ).map(({ file, action }) => ({ - action, - filePath: targetPath - ? path.posix.join(targetPath, file.path) - : file.path, - encoding: 'base64', - content: file.content.toString('base64'), - execute_filemode: file.executable, - })); + const actions: Types.CommitAction[] = + ctx.input.commitAction === 'skip' + ? [] + : ( + ( + await Promise.all( + fileContents.map(async file => + getFileAction( + { file, targetPath }, + { repoID, branch: targetBranch! }, + api, + ctx, + remoteFiles, + ctx.input.commitAction, + ).then(action => ({ file, action })), + ), + ) + ).filter(o => o.action !== 'skip') as { + file: SerializedFile; + action: Types.CommitAction['action']; + }[] + ).map(({ file, action }) => ({ + action, + filePath: targetPath + ? path.posix.join(targetPath, file.path) + : file.path, + encoding: 'base64', + content: file.content.toString('base64'), + execute_filemode: file.executable, + })); let createBranch: boolean; if (actions.length) {