refactor: updated GitHub repo creation to make differences clear (#32052)

* refactor: updated repo creation to make differences clear

Signed-off-by: Phred <fearphage@gmail.com>

* added changeset

Signed-off-by: Phred <fearphage@gmail.com>

* revertrted variable cleanup based on review comments

Signed-off-by: Phred <fearphage@gmail.com>

* cleaned up types

Signed-off-by: Phred <fearphage@gmail.com>

---------

Signed-off-by: Phred <fearphage@gmail.com>
This commit is contained in:
Phred Lane
2026-01-23 09:44:07 -06:00
committed by GitHub
parent b03c434471
commit 82ca951c00
3 changed files with 33 additions and 43 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder-backend-module-github': patch
---
cleaned up repo creation to make the unique portions explicit
@@ -81,7 +81,6 @@ export async function createGithubRepoWithCollaboratorsAndTopics(
autoInit?: boolean | undefined,
workflowAccess?: 'none' | 'organization' | 'user',
) {
// eslint-disable-next-line testing-library/no-await-sync-queries
const user = await client.rest.users.getByUsername({
username: owner,
});
@@ -90,49 +89,35 @@ export async function createGithubRepoWithCollaboratorsAndTopics(
await validateAccessTeam(client, access);
}
const baseRepoParams = {
allow_auto_merge: allowAutoMerge,
allow_merge_commit: allowMergeCommit,
allow_rebase_merge: allowRebaseMerge,
allow_squash_merge: allowSquashMerge,
allow_update_branch: allowUpdateBranch,
auto_init: autoInit,
delete_branch_on_merge: deleteBranchOnMerge,
description,
has_issues: hasIssues,
has_projects: hasProjects,
has_wiki: hasWiki,
homepage,
name: repo,
private: repoVisibility === 'private',
squash_merge_commit_message: squashMergeCommitMessage,
squash_merge_commit_title: squashMergeCommitTitle,
};
const repoCreationPromise =
user.data.type === 'Organization'
? client.rest.repos.createInOrg({
name: repo,
org: owner,
private: repoVisibility === 'private',
// @ts-ignore https://github.com/octokit/types.ts/issues/522
visibility: repoVisibility,
description: description,
delete_branch_on_merge: deleteBranchOnMerge,
allow_merge_commit: allowMergeCommit,
allow_squash_merge: allowSquashMerge,
squash_merge_commit_title: squashMergeCommitTitle,
squash_merge_commit_message: squashMergeCommitMessage,
allow_rebase_merge: allowRebaseMerge,
allow_auto_merge: allowAutoMerge,
allow_update_branch: allowUpdateBranch,
homepage: homepage,
has_projects: hasProjects,
has_wiki: hasWiki,
has_issues: hasIssues,
auto_init: autoInit,
...baseRepoParams,
// Custom properties only available on org repos
custom_properties: customProperties,
org: owner,
// @ts-ignore https://github.com/octokit/types.ts/issues/522
visibility: repoVisibility,
})
: client.rest.repos.createForAuthenticatedUser({
name: repo,
private: repoVisibility === 'private',
description: description,
delete_branch_on_merge: deleteBranchOnMerge,
allow_merge_commit: allowMergeCommit,
allow_squash_merge: allowSquashMerge,
squash_merge_commit_title: squashMergeCommitTitle,
squash_merge_commit_message: squashMergeCommitMessage,
allow_rebase_merge: allowRebaseMerge,
allow_auto_merge: allowAutoMerge,
allow_update_branch: allowUpdateBranch,
homepage: homepage,
has_projects: hasProjects,
has_wiki: hasWiki,
has_issues: hasIssues,
auto_init: autoInit,
});
: client.rest.repos.createForAuthenticatedUser(baseRepoParams);
let newRepo;
@@ -291,7 +276,7 @@ export async function initRepoPushAndProtect(
sourcePath: string | undefined,
defaultBranch: string,
protectDefaultBranch: boolean,
protectEnforceAdmins: boolean,
enforceAdmins: boolean,
owner: string,
client: Octokit,
repo: string,
@@ -365,10 +350,10 @@ export async function initRepoPushAndProtect(
requireBranchesToBeUpToDate,
requiredConversationResolution,
requireLastPushApproval,
enforceAdmins: protectEnforceAdmins,
dismissStaleReviews: dismissStaleReviews,
requiredCommitSigning: requiredCommitSigning,
requiredLinearHistory: requiredLinearHistory,
enforceAdmins,
dismissStaleReviews,
requiredCommitSigning,
requiredLinearHistory,
});
} catch (e) {
assertError(e);