From d66ca81a3836786eb646f39ce5d3ce241c83db66 Mon Sep 17 00:00:00 2001 From: Tavi Nolan Date: Thu, 4 Apr 2024 17:38:42 +0100 Subject: [PATCH] fixed outputs for github and githubRepoCreate, added dry run for githubRepoPush Signed-off-by: Tavi Nolan --- .../src/actions/github.test.ts | 18 ++++++++++++++++ .../src/actions/github.ts | 4 +++- .../src/actions/githubRepoCreate.test.ts | 8 +++++++ .../src/actions/githubRepoCreate.ts | 2 +- .../src/actions/githubRepoPush.ts | 21 ++++++++++++++----- 5 files changed, 46 insertions(+), 7 deletions(-) diff --git a/plugins/scaffolder-backend-module-github/src/actions/github.test.ts b/plugins/scaffolder-backend-module-github/src/actions/github.test.ts index 4802fd9078..a346781428 100644 --- a/plugins/scaffolder-backend-module-github/src/actions/github.test.ts +++ b/plugins/scaffolder-backend-module-github/src/actions/github.test.ts @@ -2083,6 +2083,15 @@ describe('publish:github', () => { mockContext.isDryRun = true; await action.handler(mockContext); + expect(mockContext.output).toHaveBeenCalledWith('commitHash', 'commitHash'); + expect(mockContext.output).toHaveBeenCalledWith( + 'remoteUrl', + 'www.example.com', + ); + expect(mockContext.output).toHaveBeenCalledWith( + 'repoContentsUrl', + 'www.example.com/contents', + ); expect(mockOctokit.rest.repos.createInOrg).not.toHaveBeenCalled(); }); @@ -2096,6 +2105,15 @@ describe('publish:github', () => { }); await action.handler(mockContext); + expect(mockContext.output).toHaveBeenCalledWith('commitHash', 'commitHash'); + expect(mockContext.output).toHaveBeenCalledWith( + 'remoteUrl', + 'www.example.com', + ); + expect(mockContext.output).toHaveBeenCalledWith( + 'repoContentsUrl', + 'www.example.com/contents', + ); expect( mockOctokit.rest.repos.createForAuthenticatedUser, ).not.toHaveBeenCalled(); diff --git a/plugins/scaffolder-backend-module-github/src/actions/github.ts b/plugins/scaffolder-backend-module-github/src/actions/github.ts index 923190465a..ab7375daaa 100644 --- a/plugins/scaffolder-backend-module-github/src/actions/github.ts +++ b/plugins/scaffolder-backend-module-github/src/actions/github.ts @@ -231,7 +231,9 @@ export function createPublishGithubAction(options: { if (ctx.isDryRun) { ctx.logger.info(`Performing dry run of creating repository`); - ctx.output('remoteUrl', repoUrl); + ctx.output('commitHash', 'commitHash'); + ctx.output('remoteUrl', 'www.example.com'); + ctx.output('repoContentsUrl', 'www.example.com/contents'); ctx.logger.info(`Dry run complete`); return; } diff --git a/plugins/scaffolder-backend-module-github/src/actions/githubRepoCreate.test.ts b/plugins/scaffolder-backend-module-github/src/actions/githubRepoCreate.test.ts index 3940a71c5d..ebd82f0f06 100644 --- a/plugins/scaffolder-backend-module-github/src/actions/githubRepoCreate.test.ts +++ b/plugins/scaffolder-backend-module-github/src/actions/githubRepoCreate.test.ts @@ -715,6 +715,10 @@ describe('github:repo:create', () => { mockContext.isDryRun = true; await action.handler(mockContext); + expect(mockContext.output).toHaveBeenCalledWith( + 'remoteUrl', + 'www.example.com', + ); expect(mockOctokit.rest.repos.createInOrg).not.toHaveBeenCalled(); }); @@ -728,6 +732,10 @@ describe('github:repo:create', () => { }); await action.handler(mockContext); + expect(mockContext.output).toHaveBeenCalledWith( + 'remoteUrl', + 'www.example.com', + ); expect( mockOctokit.rest.repos.createForAuthenticatedUser, ).not.toHaveBeenCalled(); diff --git a/plugins/scaffolder-backend-module-github/src/actions/githubRepoCreate.ts b/plugins/scaffolder-backend-module-github/src/actions/githubRepoCreate.ts index 175aae46aa..80edb219df 100644 --- a/plugins/scaffolder-backend-module-github/src/actions/githubRepoCreate.ts +++ b/plugins/scaffolder-backend-module-github/src/actions/githubRepoCreate.ts @@ -192,7 +192,7 @@ export function createGithubRepoCreateAction(options: { if (ctx.isDryRun) { ctx.logger.info(`Performing dry run of creating repository`); - ctx.output('remoteUrl', repoUrl); + ctx.output('remoteUrl', 'www.example.com'); ctx.logger.info(`Dry run complete`); return; } diff --git a/plugins/scaffolder-backend-module-github/src/actions/githubRepoPush.ts b/plugins/scaffolder-backend-module-github/src/actions/githubRepoPush.ts index 5b9db78f48..5b10226b3d 100644 --- a/plugins/scaffolder-backend-module-github/src/actions/githubRepoPush.ts +++ b/plugins/scaffolder-backend-module-github/src/actions/githubRepoPush.ts @@ -14,20 +14,22 @@ * limitations under the License. */ -import { Config } from '@backstage/config'; -import { InputError } from '@backstage/errors'; +import * as inputProps from './inputProperties'; +import * as outputProps from './outputProperties'; + import { GithubCredentialsProvider, ScmIntegrationRegistry, } from '@backstage/integration'; -import { Octokit } from 'octokit'; import { createTemplateAction, parseRepoUrl, } from '@backstage/plugin-scaffolder-node'; import { getOctokitOptions, initRepoPushAndProtect } from './helpers'; -import * as inputProps from './inputProperties'; -import * as outputProps from './outputProperties'; + +import { Config } from '@backstage/config'; +import { InputError } from '@backstage/errors'; +import { Octokit } from 'octokit'; import { examples } from './githubRepoPush.examples'; /** @@ -156,6 +158,15 @@ export function createGithubRepoPushAction(options: { const remoteUrl = targetRepo.data.clone_url; const repoContentsUrl = `${targetRepo.data.html_url}/blob/${defaultBranch}`; + if (ctx.isDryRun) { + ctx.logger.info(`Performing dry run of creating pull request`); + ctx.output('remoteUrl', 'www.example.com'); + ctx.output('repoContentsUrl', 'www.example.com/content'); + ctx.output('commitHash', 'commitHash'); + ctx.logger.info(`Dry run complete`); + return; + } + const { commitHash } = await initRepoPushAndProtect( remoteUrl, octokitOptions.auth,