feat: allow empty commits
Signed-off-by: ElaineDeMattosSilvaB <elaine.mattos@gmail.com>
This commit is contained in:
@@ -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',
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
},
|
||||
];
|
||||
|
||||
@@ -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;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user