From 9f071f3c4d1046d5b37e98c304cda4bda1ab8eb1 Mon Sep 17 00:00:00 2001 From: Leon van Ginneken Date: Tue, 16 Aug 2022 15:05:17 +0200 Subject: [PATCH 1/9] feat: add homepage to github:publish options Signed-off-by: Leon van Ginneken --- .../src/scaffolder/actions/builtin/github/helpers.ts | 3 +++ .../src/scaffolder/actions/builtin/github/inputProperties.ts | 5 +++++ .../src/scaffolder/actions/builtin/publish/github.ts | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/helpers.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/helpers.ts index b60794295a..fd3899b18a 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/helpers.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/helpers.ts @@ -97,6 +97,7 @@ export async function createGithubRepoWithCollaboratorsAndTopics( owner: string, repoVisibility: 'private' | 'internal' | 'public', description: string | undefined, + homepage: string | undefined, deleteBranchOnMerge: boolean, allowMergeCommit: boolean, allowSquashMerge: boolean, @@ -138,6 +139,7 @@ export async function createGithubRepoWithCollaboratorsAndTopics( allow_merge_commit: allowMergeCommit, allow_squash_merge: allowSquashMerge, allow_rebase_merge: allowRebaseMerge, + homepage: homepage, }) : client.rest.repos.createForAuthenticatedUser({ name: repo, @@ -147,6 +149,7 @@ export async function createGithubRepoWithCollaboratorsAndTopics( allow_merge_commit: allowMergeCommit, allow_squash_merge: allowSquashMerge, allow_rebase_merge: allowRebaseMerge, + homepage: homepage, }); let newRepo; diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/inputProperties.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/inputProperties.ts index b0113a4485..153b2e6941 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/inputProperties.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/inputProperties.ts @@ -23,6 +23,10 @@ const description = { title: 'Repository Description', type: 'string', }; +const homepage = { + title: 'Repository Homepage', + type: 'string', +}; const access = { title: 'Repository Access', description: `Sets an admin collaborator on the repository. Can either be a user reference different from 'owner' in 'repoUrl' or team reference, eg. 'org/team-name'`, @@ -156,6 +160,7 @@ export { description }; export { gitAuthorEmail }; export { gitAuthorName }; export { gitCommitMessage }; +export { homepage }; export { protectDefaultBranch }; export { protectEnforceAdmins }; export { repoUrl }; diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts index eea006ae8f..8ce9105237 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts @@ -45,6 +45,7 @@ export function createPublishGithubAction(options: { return createTemplateAction<{ repoUrl: string; description?: string; + homepage?: string; access?: string; defaultBranch?: string; protectDefaultBranch?: boolean; @@ -88,6 +89,7 @@ export function createPublishGithubAction(options: { properties: { repoUrl: inputProps.repoUrl, description: inputProps.description, + homepage: inputProps.homepage, access: inputProps.access, requireCodeOwnerReviews: inputProps.requireCodeOwnerReviews, requiredStatusCheckContexts: inputProps.requiredStatusCheckContexts, @@ -120,6 +122,7 @@ export function createPublishGithubAction(options: { const { repoUrl, description, + homepage, access, requireCodeOwnerReviews = false, requiredStatusCheckContexts = [], @@ -159,6 +162,7 @@ export function createPublishGithubAction(options: { owner, repoVisibility, description, + homepage, deleteBranchOnMerge, allowMergeCommit, allowSquashMerge, From ea2eee9e6a65217f56202ff4f693566912b80c86 Mon Sep 17 00:00:00 2001 From: Leon van Ginneken Date: Tue, 16 Aug 2022 15:10:33 +0200 Subject: [PATCH 2/9] chore: changeset Signed-off-by: Leon van Ginneken --- .changeset/beige-pumas-tap.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/beige-pumas-tap.md diff --git a/.changeset/beige-pumas-tap.md b/.changeset/beige-pumas-tap.md new file mode 100644 index 0000000000..63b2fb0ec5 --- /dev/null +++ b/.changeset/beige-pumas-tap.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend': minor +--- + +Add the option for a homepage when using the github:publish action From 88f8c2a4068cfbe8e9ab9ea5e705545d4abf0a86 Mon Sep 17 00:00:00 2001 From: Leon van Ginneken Date: Tue, 16 Aug 2022 15:34:30 +0200 Subject: [PATCH 3/9] feat: add homepage option to github:repo:create Signed-off-by: Leon van Ginneken --- .../src/scaffolder/actions/builtin/github/githubRepoCreate.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubRepoCreate.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubRepoCreate.ts index 1e92d91a64..5bc1fa8702 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubRepoCreate.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubRepoCreate.ts @@ -42,6 +42,7 @@ export function createGithubRepoCreateAction(options: { return createTemplateAction<{ repoUrl: string; description?: string; + homepage?: string; access?: string; deleteBranchOnMerge?: boolean; gitAuthorName?: string; @@ -79,6 +80,7 @@ export function createGithubRepoCreateAction(options: { properties: { repoUrl: inputProps.repoUrl, description: inputProps.description, + homepage: inputProps.homepage, access: inputProps.access, requireCodeOwnerReviews: inputProps.requireCodeOwnerReviews, requiredStatusCheckContexts: inputProps.requiredStatusCheckContexts, @@ -104,6 +106,7 @@ export function createGithubRepoCreateAction(options: { const { repoUrl, description, + homepage, access, repoVisibility = 'private', deleteBranchOnMerge = false, @@ -135,6 +138,7 @@ export function createGithubRepoCreateAction(options: { owner, repoVisibility, description, + homepage, deleteBranchOnMerge, allowMergeCommit, allowSquashMerge, From 1c6106bafbd89234282452bcdf87399a56f0ab1a Mon Sep 17 00:00:00 2001 From: Leon van Ginneken Date: Tue, 16 Aug 2022 15:35:03 +0200 Subject: [PATCH 4/9] test: add tests Signed-off-by: Leon van Ginneken --- .../builtin/github/githubRepoCreate.test.ts | 38 ++++++++++ .../actions/builtin/publish/github.test.ts | 71 +++++++++++++++++++ 2 files changed, 109 insertions(+) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubRepoCreate.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubRepoCreate.test.ts index 0e7e907917..f7fd624865 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubRepoCreate.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubRepoCreate.test.ts @@ -129,6 +129,25 @@ describe('github:repo:create', () => { allow_rebase_merge: true, visibility: 'public', }); + + await action.handler({ + ...mockContext, + input: { + ...mockContext.input, + homepage: 'https://example.com', + }, + }); + expect(mockOctokit.rest.repos.createInOrg).toHaveBeenCalledWith({ + description: 'description', + name: 'repo', + org: 'owner', + private: false, + delete_branch_on_merge: false, + allow_squash_merge: true, + allow_merge_commit: true, + allow_rebase_merge: true, + visibility: 'public', + }); }); it('should call the githubApis with the correct values for createForAuthenticatedUser', async () => { @@ -171,6 +190,25 @@ describe('github:repo:create', () => { allow_merge_commit: true, allow_rebase_merge: true, }); + + await action.handler({ + ...mockContext, + input: { + ...mockContext.input, + homepage: 'https://example.com', + }, + }); + expect( + mockOctokit.rest.repos.createForAuthenticatedUser, + ).toHaveBeenCalledWith({ + description: 'description', + name: 'repo', + private: false, + delete_branch_on_merge: false, + allow_squash_merge: true, + allow_merge_commit: true, + allow_rebase_merge: true, + }); }); it('should add access for the team when it starts with the owner', async () => { diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts index a526e73019..eec413e2f0 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts @@ -134,6 +134,25 @@ describe('publish:github', () => { allow_rebase_merge: true, visibility: 'public', }); + + await action.handler({ + ...mockContext, + input: { + ...mockContext.input, + homepage: 'https://example.com', + }, + }); + expect(mockOctokit.rest.repos.createInOrg).toHaveBeenCalledWith({ + description: 'description', + name: 'repo', + org: 'owner', + private: false, + delete_branch_on_merge: false, + allow_squash_merge: true, + allow_merge_commit: true, + allow_rebase_merge: true, + visibility: 'public', + }); }); it('should call the githubApis with the correct values for createForAuthenticatedUser', async () => { @@ -176,6 +195,25 @@ describe('publish:github', () => { allow_merge_commit: true, allow_rebase_merge: true, }); + + await action.handler({ + ...mockContext, + input: { + ...mockContext.input, + homepage: 'https://example.com', + }, + }); + expect( + mockOctokit.rest.repos.createForAuthenticatedUser, + ).toHaveBeenCalledWith({ + description: 'description', + name: 'repo', + private: false, + delete_branch_on_merge: false, + allow_squash_merge: true, + allow_merge_commit: true, + allow_rebase_merge: true, + }); }); it('should call initRepoAndPush with the correct values', async () => { @@ -812,4 +850,37 @@ describe('publish:github', () => { expect(enableBranchProtectionOnDefaultRepoBranch).not.toHaveBeenCalled(); }); + + it('should add homepage when provided', async () => { + mockOctokit.rest.users.getByUsername.mockResolvedValue({ + data: { type: 'User' }, + }); + + mockOctokit.rest.repos.createForAuthenticatedUser.mockResolvedValue({ + data: { + clone_url: 'https://github.com/clone/url.git', + html_url: 'https://github.com/html/url', + }, + }); + + mockOctokit.rest.repos.replaceAllTopics.mockResolvedValue({ + data: { + names: ['node.js'], + }, + }); + + await action.handler({ + ...mockContext, + input: { + ...mockContext.input, + topics: ['node.js'], + }, + }); + + expect(mockOctokit.rest.repos.replaceAllTopics).toHaveBeenCalledWith({ + owner: 'owner', + repo: 'repo', + names: ['node.js'], + }); + }); }); From bcd9bc0d507766d0b100735e1a93acda0b6d8bbb Mon Sep 17 00:00:00 2001 From: Leon van Ginneken Date: Tue, 16 Aug 2022 16:22:19 +0200 Subject: [PATCH 5/9] test: fix test Signed-off-by: Leon van Ginneken --- .../actions/builtin/github/githubRepoCreate.test.ts | 8 +++++--- .../src/scaffolder/actions/builtin/publish/github.test.ts | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubRepoCreate.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubRepoCreate.test.ts index f7fd624865..f04a735bee 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubRepoCreate.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubRepoCreate.test.ts @@ -139,14 +139,15 @@ describe('github:repo:create', () => { }); expect(mockOctokit.rest.repos.createInOrg).toHaveBeenCalledWith({ description: 'description', + homepage: 'https://example.com', name: 'repo', org: 'owner', - private: false, + private: true, delete_branch_on_merge: false, allow_squash_merge: true, allow_merge_commit: true, allow_rebase_merge: true, - visibility: 'public', + visibility: 'private', }); }); @@ -202,8 +203,9 @@ describe('github:repo:create', () => { mockOctokit.rest.repos.createForAuthenticatedUser, ).toHaveBeenCalledWith({ description: 'description', + homepage: 'https://example.com', name: 'repo', - private: false, + private: true, delete_branch_on_merge: false, allow_squash_merge: true, allow_merge_commit: true, diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts index eec413e2f0..6a2665bc8d 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts @@ -145,13 +145,14 @@ describe('publish:github', () => { expect(mockOctokit.rest.repos.createInOrg).toHaveBeenCalledWith({ description: 'description', name: 'repo', + homepage: 'https://example.com', org: 'owner', - private: false, + private: true, delete_branch_on_merge: false, allow_squash_merge: true, allow_merge_commit: true, allow_rebase_merge: true, - visibility: 'public', + visibility: 'private', }); }); @@ -207,8 +208,9 @@ describe('publish:github', () => { mockOctokit.rest.repos.createForAuthenticatedUser, ).toHaveBeenCalledWith({ description: 'description', + homepage: 'https://example.com', name: 'repo', - private: false, + private: true, delete_branch_on_merge: false, allow_squash_merge: true, allow_merge_commit: true, From b254e95141ad9cd1a3d16e5b94aa39f0b53e8022 Mon Sep 17 00:00:00 2001 From: Leon van Ginneken Date: Tue, 16 Aug 2022 16:30:01 +0200 Subject: [PATCH 6/9] chore: update api-report Signed-off-by: Leon van Ginneken --- plugins/scaffolder-backend/api-report.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/scaffolder-backend/api-report.md b/plugins/scaffolder-backend/api-report.md index 96a4d7b400..256eda0063 100644 --- a/plugins/scaffolder-backend/api-report.md +++ b/plugins/scaffolder-backend/api-report.md @@ -178,6 +178,7 @@ export function createGithubRepoCreateAction(options: { }): TemplateAction<{ repoUrl: string; description?: string | undefined; + homepage?: string | undefined; access?: string | undefined; deleteBranchOnMerge?: boolean | undefined; gitAuthorName?: string | undefined; @@ -187,7 +188,7 @@ export function createGithubRepoCreateAction(options: { allowMergeCommit?: boolean | undefined; requireCodeOwnerReviews?: boolean | undefined; requiredStatusCheckContexts?: string[] | undefined; - repoVisibility?: 'internal' | 'private' | 'public' | undefined; + repoVisibility?: 'public' | 'private' | 'internal' | undefined; collaborators?: | ( | { @@ -267,7 +268,7 @@ export function createPublishBitbucketAction(options: { repoUrl: string; description?: string | undefined; defaultBranch?: string | undefined; - repoVisibility?: 'private' | 'public' | undefined; + repoVisibility?: 'public' | 'private' | undefined; sourcePath?: string | undefined; enableLFS?: boolean | undefined; token?: string | undefined; @@ -284,7 +285,7 @@ export function createPublishBitbucketCloudAction(options: { repoUrl: string; description?: string | undefined; defaultBranch?: string | undefined; - repoVisibility?: 'private' | 'public' | undefined; + repoVisibility?: 'public' | 'private' | undefined; sourcePath?: string | undefined; token?: string | undefined; }>; @@ -297,7 +298,7 @@ export function createPublishBitbucketServerAction(options: { repoUrl: string; description?: string | undefined; defaultBranch?: string | undefined; - repoVisibility?: 'private' | 'public' | undefined; + repoVisibility?: 'public' | 'private' | undefined; sourcePath?: string | undefined; enableLFS?: boolean | undefined; token?: string | undefined; @@ -343,6 +344,7 @@ export function createPublishGithubAction(options: { }): TemplateAction<{ repoUrl: string; description?: string | undefined; + homepage?: string | undefined; access?: string | undefined; defaultBranch?: string | undefined; protectDefaultBranch?: boolean | undefined; @@ -357,7 +359,7 @@ export function createPublishGithubAction(options: { sourcePath?: string | undefined; requireCodeOwnerReviews?: boolean | undefined; requiredStatusCheckContexts?: string[] | undefined; - repoVisibility?: 'internal' | 'private' | 'public' | undefined; + repoVisibility?: 'public' | 'private' | 'internal' | undefined; collaborators?: | ( | { @@ -403,7 +405,7 @@ export function createPublishGitlabAction(options: { }): TemplateAction<{ repoUrl: string; defaultBranch?: string | undefined; - repoVisibility?: 'internal' | 'private' | 'public' | undefined; + repoVisibility?: 'public' | 'private' | 'internal' | undefined; sourcePath?: string | undefined; token?: string | undefined; gitCommitMessage?: string | undefined; @@ -422,7 +424,7 @@ export const createPublishGitlabMergeRequestAction: (options: { branchName: string; targetPath: string; token?: string | undefined; - commitAction?: 'update' | 'create' | 'delete' | undefined; + commitAction?: 'create' | 'update' | 'delete' | undefined; projectid?: string | undefined; removeSourceBranch?: boolean | undefined; assignee?: string | undefined; From f5bfad5dd2af8d8d6a7c8c07b80be0de58e30a6e Mon Sep 17 00:00:00 2001 From: Leon van Ginneken Date: Wed, 17 Aug 2022 11:43:26 +0200 Subject: [PATCH 7/9] Update .changeset/beige-pumas-tap.md Co-authored-by: Patrik Oldsberg Signed-off-by: Leon van Ginneken --- .changeset/beige-pumas-tap.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/beige-pumas-tap.md b/.changeset/beige-pumas-tap.md index 63b2fb0ec5..8ed8aab1f4 100644 --- a/.changeset/beige-pumas-tap.md +++ b/.changeset/beige-pumas-tap.md @@ -2,4 +2,4 @@ '@backstage/plugin-scaffolder-backend': minor --- -Add the option for a homepage when using the github:publish action +Add the option for a homepage when using the `github:publish` action From 422ac84c304dbeff96f5baa57171edb2f944674f Mon Sep 17 00:00:00 2001 From: Leon van Ginneken Date: Wed, 17 Aug 2022 12:15:49 +0200 Subject: [PATCH 8/9] chore: api-report Signed-off-by: Leon van Ginneken --- plugins/scaffolder-backend/api-report.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/scaffolder-backend/api-report.md b/plugins/scaffolder-backend/api-report.md index 7bdc09c874..cdbfe165f4 100644 --- a/plugins/scaffolder-backend/api-report.md +++ b/plugins/scaffolder-backend/api-report.md @@ -188,7 +188,7 @@ export function createGithubRepoCreateAction(options: { allowMergeCommit?: boolean | undefined; requireCodeOwnerReviews?: boolean | undefined; requiredStatusCheckContexts?: string[] | undefined; - repoVisibility?: 'public' | 'private' | 'internal' | undefined; + repoVisibility?: 'internal' | 'private' | 'public' | undefined; collaborators?: | ( | { @@ -268,7 +268,7 @@ export function createPublishBitbucketAction(options: { repoUrl: string; description?: string | undefined; defaultBranch?: string | undefined; - repoVisibility?: 'public' | 'private' | undefined; + repoVisibility?: 'private' | 'public' | undefined; sourcePath?: string | undefined; enableLFS?: boolean | undefined; token?: string | undefined; @@ -285,7 +285,7 @@ export function createPublishBitbucketCloudAction(options: { repoUrl: string; description?: string | undefined; defaultBranch?: string | undefined; - repoVisibility?: 'public' | 'private' | undefined; + repoVisibility?: 'private' | 'public' | undefined; sourcePath?: string | undefined; token?: string | undefined; }>; @@ -298,7 +298,7 @@ export function createPublishBitbucketServerAction(options: { repoUrl: string; description?: string | undefined; defaultBranch?: string | undefined; - repoVisibility?: 'public' | 'private' | undefined; + repoVisibility?: 'private' | 'public' | undefined; sourcePath?: string | undefined; enableLFS?: boolean | undefined; token?: string | undefined; @@ -354,7 +354,7 @@ export function createPublishGithubAction(options: { sourcePath?: string | undefined; requireCodeOwnerReviews?: boolean | undefined; requiredStatusCheckContexts?: string[] | undefined; - repoVisibility?: 'public' | 'private' | 'internal' | undefined; + repoVisibility?: 'internal' | 'private' | 'public' | undefined; collaborators?: | ( | { @@ -400,7 +400,7 @@ export function createPublishGitlabAction(options: { }): TemplateAction<{ repoUrl: string; defaultBranch?: string | undefined; - repoVisibility?: 'public' | 'private' | 'internal' | undefined; + repoVisibility?: 'internal' | 'private' | 'public' | undefined; sourcePath?: string | undefined; token?: string | undefined; gitCommitMessage?: string | undefined; @@ -419,7 +419,7 @@ export const createPublishGitlabMergeRequestAction: (options: { branchName: string; targetPath: string; token?: string | undefined; - commitAction?: 'create' | 'update' | 'delete' | undefined; + commitAction?: 'update' | 'delete' | 'create' | undefined; projectid?: string | undefined; removeSourceBranch?: boolean | undefined; assignee?: string | undefined; From 361d88f6cc6e61dbe3d1c274a1a93f0a381a3a34 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Wed, 17 Aug 2022 13:09:41 +0200 Subject: [PATCH 9/9] scaffolder-backend: update API report Signed-off-by: Patrik Oldsberg --- plugins/scaffolder-backend/api-report.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/scaffolder-backend/api-report.md b/plugins/scaffolder-backend/api-report.md index cdbfe165f4..68ab024bf6 100644 --- a/plugins/scaffolder-backend/api-report.md +++ b/plugins/scaffolder-backend/api-report.md @@ -419,7 +419,7 @@ export const createPublishGitlabMergeRequestAction: (options: { branchName: string; targetPath: string; token?: string | undefined; - commitAction?: 'update' | 'delete' | 'create' | undefined; + commitAction?: 'update' | 'create' | 'delete' | undefined; projectid?: string | undefined; removeSourceBranch?: boolean | undefined; assignee?: string | undefined;