fixed outputs for github and githubRepoCreate, added dry run for githubRepoPush

Signed-off-by: Tavi Nolan <Tavi.Nolan@fmr.com>
This commit is contained in:
Tavi Nolan
2024-04-04 17:38:42 +01:00
parent 7c2c8e4961
commit d66ca81a38
5 changed files with 46 additions and 7 deletions
@@ -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();
@@ -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;
}
@@ -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();
@@ -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;
}
@@ -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,