Merge pull request #24501 from fidelity-contributions/feature/enable-scaffolder-dry-run

Feature/enable scaffolder dry run
This commit is contained in:
Ben Lambert
2024-05-17 16:22:20 +02:00
committed by GitHub
5 changed files with 58 additions and 0 deletions
@@ -231,6 +231,18 @@ describe('createPublishGithubPullRequestAction', () => {
);
expect(ctx.output).toHaveBeenCalledWith('pullRequestNumber', 123);
});
it('sets correct outputs during dry run', async () => {
ctx.isDryRun = true;
await instance.handler(ctx);
expect(ctx.output).toHaveBeenCalledWith('targetBranchName', 'new-app');
expect(ctx.output).toHaveBeenCalledWith(
'remoteUrl',
'github.com?owner=myorg&repo=myrepo',
);
expect(ctx.output).toHaveBeenCalledWith('pullRequestNumber', 43);
});
});
describe('with sourcePath', () => {
@@ -149,6 +149,7 @@ export const createPublishGithubPullRequestAction = (
}>({
id: 'publish:github:pull-request',
examples,
supportsDryRun: true,
schema: {
input: {
required: ['repoUrl', 'title', 'description', 'branchName'],
@@ -343,6 +344,16 @@ export const createPublishGithubPullRequestAction = (
]),
);
// If this is a dry run, log and return
if (ctx.isDryRun) {
ctx.logger.info(`Performing dry run of creating pull request`);
ctx.output('targetBranchName', branchName);
ctx.output('remoteUrl', repoUrl);
ctx.output('pullRequestNumber', 43);
ctx.logger.info(`Dry run complete`);
return;
}
try {
const createOptions: createPullRequest.Options = {
owner,
@@ -221,6 +221,29 @@ describe('github:repository:webhook:create', () => {
});
});
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';
// Create the context object with the necessary properties for a dry run
const ctx = {
...mockContext,
isDryRun: true,
input: {
...mockContext.input,
repoUrl,
webhookUrl,
},
};
// 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 () => {
const Validator = require('jsonschema').Validator;
const v = new Validator();
@@ -55,6 +55,7 @@ export function createGithubWebhookAction(options: {
id: 'github:webhook',
description: 'Creates webhook for a repository on GitHub.',
examples,
supportsDryRun: true,
schema: {
input: {
type: 'object',
@@ -148,6 +149,12 @@ export function createGithubWebhookAction(options: {
}),
);
// If this is a dry run, log and return
if (ctx.isDryRun) {
ctx.logger.info(`Dry run complete`);
return;
}
try {
const insecure_ssl = insecureSsl ? '1' : '0';
await client.rest.repos.createWebhook({