updates to githubWebhook

Signed-off-by: Tavi Nolan <Tavi.Nolan@fmr.com>
This commit is contained in:
Tavi Nolan
2024-04-04 14:55:54 +01:00
parent 8de90c8358
commit cbbde942d7
2 changed files with 21 additions and 30 deletions
@@ -222,37 +222,27 @@ describe('github:repository:webhook:create', () => {
});
});
it('should call the githubApi for creating repository Webhook with dry run', async () => {
it('should not call the githubApi for creating repository Webhook with dry run', async () => {
// Define constants for reused string literals
const repoUrl = 'github.com?repo=repo&owner=owner';
const webhookUrl = 'https://example.com/payload';
const ctx = Object.assign({}, mockContext, {
input: { repoUrl, webhookUrl },
});
ctx.isDryRun = true;
await action.handler(ctx);
const webhookSecret = 'yet_another_secret';
await action.handler({
// Create the context object with the necessary properties for a dry run
const ctx = {
...mockContext,
isDryRun: true,
input: {
...mockContext.input,
webhookSecret,
events: ['push', 'pull_request'],
repoUrl,
webhookUrl,
},
});
};
expect(mockOctokit.rest.repos.createWebhook).toHaveBeenCalledWith({
owner: 'owner',
repo: 'repo',
events: ['push', 'pull_request'],
active: true,
config: {
url: webhookUrl,
content_type: 'form',
secret: webhookSecret,
insecure_ssl: '0',
},
});
// Call the handler with the context
await action.handler(ctx);
// Check that the createWebhook method was not called
expect(mockOctokit.rest.repos.createWebhook).not.toHaveBeenCalled();
});
it('should validate input', async () => {
@@ -149,14 +149,15 @@ export function createGithubWebhookAction(options: {
}),
);
// If this is a dry run, log the arguments and exit
if (ctx.isDryRun) {
ctx.logger.info(
`Dry run arguments: ${{
webhookSecret,
events,
...ctx.input,
}}`,
);
const dryRunArgs = {
webhookSecret,
events,
...ctx.input,
};
ctx.logger.info(`Dry run completed`);
return;
}