From 73615f4b9f646bda7eac5bd143dece3a7fb2cca5 Mon Sep 17 00:00:00 2001 From: bi003731 Date: Tue, 2 Dec 2025 13:31:17 -0300 Subject: [PATCH] improve readablility Signed-off-by: bi003731 --- .../src/actions/gitlabRepoPush.ts | 57 +++++++++---------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabRepoPush.ts b/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabRepoPush.ts index bdd6321911..dd8e28d87a 100644 --- a/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabRepoPush.ts +++ b/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabRepoPush.ts @@ -146,36 +146,33 @@ export const createGitlabRepoPushAction = (options: { } } - const actions: CommitAction[] = ( - ( - await (async () => { - const results = []; - for (const file of fileContents) { - const action = await getFileAction( - { file, targetPath }, - { repoID, branch: branchName }, - api, - ctx.logger, - remoteFiles, - ctx.input.commitAction, - ); - results.push({ file, action }); - } - return results; - })() - ).filter(o => o.action !== 'skip') as { - file: SerializedFile; - action: 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 fileActionMap: { + file: SerializedFile; + action: 'create' | 'delete' | 'update' | 'skip'; + }[] = []; + for (const file of fileContents) { + const action = await getFileAction( + { file, targetPath }, + { repoID, branch: branchName }, + api, + ctx.logger, + remoteFiles, + ctx.input.commitAction, + ); + fileActionMap.push({ file, action }); + } + + const actions: CommitAction[] = fileActionMap + .filter(o => o.action !== 'skip') + .map(({ file, action }) => ({ + action: action as CommitAction['action'], + filePath: targetPath + ? path.posix.join(targetPath, file.path) + : file.path, + encoding: 'base64', + content: file.content.toString('base64'), + execute_filemode: file.executable, + })); const branchExists = await ctx.checkpoint({ key: `branch.exists.${repoID}.${branchName}`,