From 96fc2769897c33785a028ca121f31fb6a5659f42 Mon Sep 17 00:00:00 2001 From: Joe Porpeglia Date: Thu, 8 Jul 2021 13:53:49 -0400 Subject: [PATCH] Fix repository inputs for githubPullRequest publish action Signed-off-by: Joe Porpeglia --- .changeset/shy-rules-design.md | 7 ++++ .../builtin/publish/githubPullRequest.test.ts | 6 ++-- .../builtin/publish/githubPullRequest.ts | 33 ++++--------------- 3 files changed, 15 insertions(+), 31 deletions(-) create mode 100644 .changeset/shy-rules-design.md diff --git a/.changeset/shy-rules-design.md b/.changeset/shy-rules-design.md new file mode 100644 index 0000000000..4f009e5aa8 --- /dev/null +++ b/.changeset/shy-rules-design.md @@ -0,0 +1,7 @@ +--- +'@backstage/plugin-scaffolder-backend': minor +--- + +Updated inputs for the `publish:github:pull-request` action. + +Now requires a `repoUrl` instead of separate `owner` and `repo` inputs. This aligns with the output of the `RepoUrlPicker` ui field used by the pull-request sample template. diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.test.ts index 32527afd5d..2ba30bb3db 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.test.ts @@ -67,8 +67,7 @@ describe('createPublishGithubPullRequestAction', () => { beforeEach(() => { input = { - owner: 'myorg', - repo: 'myrepo', + repoUrl: 'github.com?owner=myorg&repo=myrepo', title: 'Create my new app', branchName: 'new-app', description: 'This PR is really good', @@ -127,8 +126,7 @@ describe('createPublishGithubPullRequestAction', () => { beforeEach(() => { input = { - owner: 'myorg', - repo: 'myrepo', + repoUrl: 'github.com?owner=myorg&repo=myrepo', title: 'Create my new app', branchName: 'new-app', description: 'This PR is really good', diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.ts index 18ceeca3c9..1c46e80d03 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.ts @@ -49,10 +49,7 @@ export type GithubPullRequestActionInput = { title: string; branchName: string; description: string; - owner?: string; - repo?: string; - repoUrl?: string; - host?: string; + repoUrl: string; targetPath?: string; sourcePath?: string; }; @@ -119,18 +116,13 @@ export const createPublishGithubPullRequestAction = ({ id: 'publish:github:pull-request', schema: { input: { - required: ['owner', 'repo', 'title', 'description', 'branchName'], + required: ['repoUrl', 'title', 'description', 'branchName'], type: 'object', properties: { - owner: { + repoUrl: { + title: 'Repository Location', + description: `Accepts the format 'github.com?repo=reponame&owner=owner' where 'reponame' is the repository name and 'owner' is an organization or username`, type: 'string', - title: 'Repository owner', - description: 'The owner of the target repository', - }, - repo: { - type: 'string', - title: 'Repository', - description: 'The github repository to create the file in', }, branchName: { type: 'string', @@ -173,8 +165,6 @@ export const createPublishGithubPullRequestAction = ({ }, }, async handler(ctx) { - let { owner, repo } = ctx.input; - let host = 'github.com'; const { repoUrl, branchName, @@ -184,18 +174,7 @@ export const createPublishGithubPullRequestAction = ({ sourcePath, } = ctx.input; - if (repoUrl) { - const parsed = parseRepoUrl(repoUrl); - host = parsed.host; - owner = parsed.owner; - repo = parsed.repo; - } - - if (!host || !owner || !repo) { - throw new InputError( - 'must provide either valid repo URL or owner and repo as parameters', - ); - } + const { owner, repo, host } = parseRepoUrl(repoUrl); const client = await clientFactory({ integrations, host, owner, repo }); const fileRoot = sourcePath