From a38e03e5d15327ce6e19384579cf3b2ce2ed498e Mon Sep 17 00:00:00 2001 From: ElaineDeMattosSilvaB Date: Thu, 26 Mar 2026 20:58:03 +0100 Subject: [PATCH] feat: allow empty commits Signed-off-by: ElaineDeMattosSilvaB --- .../actions/gitlabRepoPush.examples.test.ts | 21 +++++++++++++++++++ .../src/actions/gitlabRepoPush.examples.ts | 19 +++++++++++++++++ .../src/actions/gitlabRepoPush.ts | 8 +++++++ 3 files changed, 48 insertions(+) diff --git a/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabRepoPush.examples.test.ts b/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabRepoPush.examples.test.ts index 25b6c89ae4..2a50ee9411 100644 --- a/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabRepoPush.examples.test.ts +++ b/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabRepoPush.examples.test.ts @@ -181,4 +181,25 @@ describe('gitlab:repo:push', () => { ); }); }); + + describe('Push an empty commit to gitlab repository', () => { + it(`Should ${examples[3].description}`, async () => { + const input = yaml.parse(examples[3].example).steps[0].input; + mockDir.setContent({ [workspacePath]: {} }); + const ctx = createMockActionContext({ input, workspacePath }); + await instance.handler(ctx); + + expect(mockGitlabClient.Commits.create).toHaveBeenCalledWith( + 'owner/repo', + 'feature-branch', + 'Initial Commit', + [], + { allowEmpty: true }, + ); + expect(ctx.output).toHaveBeenCalledWith( + 'commitHash', + 'f8a2c9bd4e2915b0792b43235c779e82ddad54af', + ); + }); + }); }); diff --git a/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabRepoPush.examples.ts b/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabRepoPush.examples.ts index 56a59f25bc..e43dbddb42 100644 --- a/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabRepoPush.examples.ts +++ b/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabRepoPush.examples.ts @@ -73,4 +73,23 @@ export const examples: TemplateExample[] = [ ], }), }, + { + description: + 'Push an empty commit to gitlab repository (from GitLab 18.8+ on)', + example: yaml.stringify({ + steps: [ + { + id: 'pushChanges', + action: 'gitlab:repo:push', + name: 'Push empty commit to gitlab repository', + input: { + repoUrl: 'gitlab.com?repo=repo&owner=owner', + commitMessage: 'Initial Commit', + branchName: 'feature-branch', + allowEmpty: true, + }, + }, + ], + }), + }, ]; diff --git a/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabRepoPush.ts b/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabRepoPush.ts index 24f2907041..1bf817aac8 100644 --- a/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabRepoPush.ts +++ b/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabRepoPush.ts @@ -83,6 +83,12 @@ export const createGitlabRepoPushAction = (options: { 'The action to be used for git commit. Defaults to create, but can be set to update or delete', }) .optional(), + allowEmpty: z => + z + .boolean({ + description: 'Allow an empty commit to be created.', + }) + .optional(), }, output: { projectid: z => @@ -107,6 +113,7 @@ export const createGitlabRepoPushAction = (options: { sourcePath, token, commitAction, + allowEmpty, } = ctx.input; const { owner, repo, project } = parseRepoUrl(repoUrl, integrations); @@ -217,6 +224,7 @@ export const createGitlabRepoPushAction = (options: { branchName, ctx.input.commitMessage, actions, + ...(allowEmpty !== undefined ? [{ allowEmpty } as object] : []), ); return commit.id; },