diff --git a/.changeset/sharp-poets-count.md b/.changeset/sharp-poets-count.md new file mode 100644 index 0000000000..33ec80b718 --- /dev/null +++ b/.changeset/sharp-poets-count.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend': patch +--- + +Add support for disabling Github repository wiki, issues and projects diff --git a/plugins/scaffolder-backend/api-report.md b/plugins/scaffolder-backend/api-report.md index 40a0ec11a0..69ef893dc3 100644 --- a/plugins/scaffolder-backend/api-report.md +++ b/plugins/scaffolder-backend/api-report.md @@ -225,6 +225,9 @@ export function createGithubRepoCreateAction(options: { } )[] | undefined; + hasProjects?: boolean | undefined; + hasWiki?: boolean | undefined; + hasIssues?: boolean | undefined; token?: string | undefined; topics?: string[] | undefined; }>; @@ -412,6 +415,9 @@ export function createPublishGithubAction(options: { } )[] | undefined; + hasProjects?: boolean | undefined; + hasWiki?: boolean | undefined; + hasIssues?: boolean | undefined; token?: string | undefined; topics?: string[] | undefined; }>; 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 5692682882..0b0f98e2e7 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 @@ -152,6 +152,60 @@ describe('github:repo:create', () => { allow_auto_merge: false, visibility: 'private', }); + + await action.handler({ + ...mockContext, + input: { + ...mockContext.input, + hasWiki: true, + hasProjects: true, + hasIssues: true, + }, + }); + expect( + mockOctokit.rest.repos.createInOrg, + ).toHaveBeenCalledWith({ + description: 'description', + name: 'repo', + org: 'owner', + private: true, + delete_branch_on_merge: false, + allow_squash_merge: true, + allow_merge_commit: true, + allow_rebase_merge: true, + allow_auto_merge: false, + visibility: 'private', + has_wiki: true, + has_projects: true, + has_issues: true, + }); + + await action.handler({ + ...mockContext, + input: { + ...mockContext.input, + hasWiki: false, + hasProjects: false, + hasIssues: false, + }, + }); + expect( + mockOctokit.rest.repos.createInOrg, + ).toHaveBeenCalledWith({ + description: 'description', + name: 'repo', + org: 'owner', + private: true, + delete_branch_on_merge: false, + allow_squash_merge: true, + allow_merge_commit: true, + allow_rebase_merge: true, + allow_auto_merge: false, + visibility: 'private', + has_wiki: false, + has_projects: false, + has_issues: false, + }); }); it('should call the githubApis with the correct values for createForAuthenticatedUser', async () => { @@ -217,6 +271,56 @@ describe('github:repo:create', () => { allow_rebase_merge: true, allow_auto_merge: false, }); + + await action.handler({ + ...mockContext, + input: { + ...mockContext.input, + hasWiki: true, + hasProjects: true, + hasIssues: true, + }, + }); + expect( + mockOctokit.rest.repos.createForAuthenticatedUser, + ).toHaveBeenCalledWith({ + description: 'description', + name: 'repo', + private: true, + delete_branch_on_merge: false, + allow_squash_merge: true, + allow_merge_commit: true, + allow_rebase_merge: true, + allow_auto_merge: false, + has_wiki: true, + has_projects: true, + has_issues: true, + }); + + await action.handler({ + ...mockContext, + input: { + ...mockContext.input, + hasWiki: false, + hasProjects: false, + hasIssues: false, + }, + }); + expect( + mockOctokit.rest.repos.createForAuthenticatedUser, + ).toHaveBeenCalledWith({ + description: 'description', + name: 'repo', + private: true, + delete_branch_on_merge: false, + allow_squash_merge: true, + allow_merge_commit: true, + allow_rebase_merge: true, + allow_auto_merge: false, + has_wiki: false, + has_projects: false, + has_issues: false, + }); }); it('should add access for the team when it starts with the owner', async () => { 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 4f2cf4a71e..598e3314fb 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubRepoCreate.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubRepoCreate.ts @@ -76,6 +76,9 @@ export function createGithubRepoCreateAction(options: { access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage'; } >; + hasProjects?: boolean; + hasWiki?: boolean; + hasIssues?: boolean; token?: string; topics?: string[]; }>({ @@ -103,6 +106,9 @@ export function createGithubRepoCreateAction(options: { allowRebaseMerge: inputProps.allowRebaseMerge, allowAutoMerge: inputProps.allowAutoMerge, collaborators: inputProps.collaborators, + hasProjects: inputProps.hasProjects, + hasWiki: inputProps.hasWiki, + hasIssues: inputProps.hasIssues, token: inputProps.token, topics: inputProps.topics, }, @@ -128,6 +134,9 @@ export function createGithubRepoCreateAction(options: { allowRebaseMerge = true, allowAutoMerge = false, collaborators, + hasProjects = undefined, + hasWiki = undefined, + hasIssues = undefined, topics, token: providedToken, } = ctx.input; @@ -160,6 +169,9 @@ export function createGithubRepoCreateAction(options: { allowAutoMerge, access, collaborators, + hasProjects, + hasWiki, + hasIssues, topics, ctx.logger, ); 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 216a94ac57..499826ee6b 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/helpers.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/helpers.ts @@ -122,6 +122,9 @@ export async function createGithubRepoWithCollaboratorsAndTopics( } )[] | undefined, + hasProjects: boolean | undefined, + hasWiki: boolean | undefined, + hasIssues: boolean | undefined, topics: string[] | undefined, logger: Logger, ) { @@ -144,6 +147,9 @@ export async function createGithubRepoWithCollaboratorsAndTopics( allow_rebase_merge: allowRebaseMerge, allow_auto_merge: allowAutoMerge, homepage: homepage, + has_projects: hasProjects, + has_wiki: hasWiki, + has_issues: hasIssues, }) : client.rest.repos.createForAuthenticatedUser({ name: repo, @@ -155,6 +161,9 @@ export async function createGithubRepoWithCollaboratorsAndTopics( allow_rebase_merge: allowRebaseMerge, allow_auto_merge: allowAutoMerge, homepage: homepage, + has_projects: hasProjects, + has_wiki: hasWiki, + has_issues: hasIssues, }); 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 a99a3030ac..07dd0f8163 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/inputProperties.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/inputProperties.ts @@ -132,6 +132,21 @@ const collaborators = { oneOf: [{ required: ['user'] }, { required: ['team'] }], }, }; +const hasProjects = { + title: 'Enable projects', + type: 'boolean', + description: `Enable projects for the repository. The default value is 'true' unless the organization has disabled repository projects`, +}; +const hasWiki = { + title: 'Enable the wiki', + type: 'boolean', + description: `Enable the wiki for the repository. The default value is 'true'`, +}; +const hasIssues = { + title: 'Enable issues', + type: 'boolean', + description: `Enable issues for the repository. The default value is 'true'`, +}; const token = { title: 'Authentication Token', type: 'string', @@ -223,6 +238,9 @@ export { dismissStaleReviews }; export { requiredStatusCheckContexts }; export { requireBranchesToBeUpToDate }; export { requiredConversationResolution }; +export { hasProjects }; +export { hasIssues }; +export { hasWiki }; export { sourcePath }; export { token }; export { topics }; 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 fa3b3c9b45..68e328e9fc 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 @@ -157,6 +157,60 @@ describe('publish:github', () => { allow_auto_merge: false, visibility: 'private', }); + + await action.handler({ + ...mockContext, + input: { + ...mockContext.input, + hasWiki: true, + hasProjects: true, + hasIssues: true, + }, + }); + expect( + mockOctokit.rest.repos.createInOrg, + ).toHaveBeenCalledWith({ + description: 'description', + name: 'repo', + org: 'owner', + private: true, + delete_branch_on_merge: false, + allow_squash_merge: true, + allow_merge_commit: true, + allow_rebase_merge: true, + allow_auto_merge: false, + visibility: 'private', + has_wiki: true, + has_projects: true, + has_issues: true, + }); + + await action.handler({ + ...mockContext, + input: { + ...mockContext.input, + hasWiki: false, + hasProjects: false, + hasIssues: false, + }, + }); + expect( + mockOctokit.rest.repos.createInOrg, + ).toHaveBeenCalledWith({ + description: 'description', + name: 'repo', + org: 'owner', + private: true, + delete_branch_on_merge: false, + allow_squash_merge: true, + allow_merge_commit: true, + allow_rebase_merge: true, + allow_auto_merge: false, + visibility: 'private', + has_wiki: false, + has_projects: false, + has_issues: false, + }); }); it('should call the githubApis with the correct values for createForAuthenticatedUser', async () => { @@ -222,6 +276,56 @@ describe('publish:github', () => { allow_rebase_merge: true, allow_auto_merge: false, }); + + await action.handler({ + ...mockContext, + input: { + ...mockContext.input, + hasWiki: true, + hasProjects: true, + hasIssues: true, + }, + }); + expect( + mockOctokit.rest.repos.createForAuthenticatedUser, + ).toHaveBeenCalledWith({ + description: 'description', + name: 'repo', + private: true, + delete_branch_on_merge: false, + allow_squash_merge: true, + allow_merge_commit: true, + allow_rebase_merge: true, + allow_auto_merge: false, + has_wiki: true, + has_projects: true, + has_issues: true, + }); + + await action.handler({ + ...mockContext, + input: { + ...mockContext.input, + hasWiki: false, + hasProjects: false, + hasIssues: false, + }, + }); + expect( + mockOctokit.rest.repos.createForAuthenticatedUser, + ).toHaveBeenCalledWith({ + description: 'description', + name: 'repo', + private: true, + delete_branch_on_merge: false, + allow_squash_merge: true, + allow_merge_commit: true, + allow_rebase_merge: true, + allow_auto_merge: false, + has_wiki: false, + has_projects: false, + has_issues: false, + }); }); it('should call initRepoAndPush with the correct values', async () => { 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 e246234d2c..edb1c699d7 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts @@ -88,6 +88,9 @@ export function createPublishGithubAction(options: { access: 'pull' | 'push' | 'admin' | 'maintain' | 'triage'; } >; + hasProjects?: boolean | undefined; + hasWiki?: boolean | undefined; + hasIssues?: boolean | undefined; token?: string; topics?: string[]; }>({ @@ -124,6 +127,9 @@ export function createPublishGithubAction(options: { allowAutoMerge: inputProps.allowAutoMerge, sourcePath: inputProps.sourcePath, collaborators: inputProps.collaborators, + hasProjects: inputProps.hasProjects, + hasWiki: inputProps.hasWiki, + hasIssues: inputProps.hasIssues, token: inputProps.token, topics: inputProps.topics, }, @@ -161,6 +167,9 @@ export function createPublishGithubAction(options: { allowRebaseMerge = true, allowAutoMerge = false, collaborators, + hasProjects = undefined, + hasWiki = undefined, + hasIssues = undefined, topics, token: providedToken, } = ctx.input; @@ -193,6 +202,9 @@ export function createPublishGithubAction(options: { allowAutoMerge, access, collaborators, + hasProjects, + hasWiki, + hasIssues, topics, ctx.logger, );