Skip to content

Commit

Permalink
Change: Cleanup create-repository github script
Browse files Browse the repository at this point in the history
Move evaluation of input arguments to the top of the code. It's easier
to read what's happening if all arguments are evaluated early.
  • Loading branch information
bjoernricks committed Jan 30, 2024
1 parent dd89d1f commit c483e14
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions pontos/github/scripts/create-repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,17 @@ def add_script_arguments(parser: ArgumentParser) -> None:
async def github_script(api: GitHubAsyncRESTApi, args: Namespace) -> int:
organization = args.organization
repository = args.name
private = True if args.visibility == "private" else False
gitignore_template = GITIGNORE.get(args.template)
license_template = args.license
description = args.description

team_id = None
if args.team:
team = await api.teams.get(organization, args.team)
team_id = team.id
else:
team_id = None
team = None

with temp_directory() as temp_dir:
git = Git()
Expand All @@ -101,8 +107,6 @@ async def github_script(api: GitHubAsyncRESTApi, args: Namespace) -> int:
git.cwd = temp_dir
git.init()

private = True if args.visibility == "private" else False

repo = await api.repositories.create(
organization,
repository,
Expand All @@ -116,10 +120,10 @@ async def github_script(api: GitHubAsyncRESTApi, args: Namespace) -> int:
allow_update_branch=True,
delete_branch_on_merge=True,
is_template=False,
license_template=args.license,
description=args.description,
license_template=license_template,
description=description,
auto_init=True,
gitignore_template=GITIGNORE.get(args.template),
gitignore_template=gitignore_template,
team_id=team_id,
)

Expand All @@ -136,7 +140,7 @@ async def github_script(api: GitHubAsyncRESTApi, args: Namespace) -> int:
else:
git.checkout("main", start_point="upstream/main")

if args.team:
if team:
await api.teams.update_permission(
organization, team.slug, repository, Permission.ADMIN
)
Expand Down

0 comments on commit c483e14

Please sign in to comment.