-
Notifications
You must be signed in to change notification settings - Fork 25
Implement hands on hp-populate-remote #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f7f7db5
295500c
8a10b00
ba2ef97
a6cf95b
a6bb231
de05a24
abc4bf8
5e001c3
12187c7
b7d53e1
284a758
7ab822c
274a744
6678afc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import os | ||
| import sys | ||
|
|
||
| from exercise_utils.cli import run_command, run_command_with_code | ||
| from exercise_utils.file import create_or_update_file, append_to_file | ||
| from exercise_utils.git import add, init, commit, add_remote | ||
|
|
||
| __requires_git__ = True | ||
| __requires_github__ = True | ||
|
|
||
| REPO_NAME = "gitmastery-things" | ||
|
|
||
|
|
||
| def download(verbose: bool): | ||
| _setup_local_repository(verbose) | ||
| _create_things_repository(verbose) | ||
| _link_repositories(verbose) | ||
|
|
||
|
|
||
| def _setup_local_repository(verbose: bool): | ||
| os.makedirs("things") | ||
| os.chdir("things") | ||
| init(verbose) | ||
|
|
||
| create_or_update_file( | ||
| "fruits.txt", | ||
| """ | ||
| apples | ||
| bananas | ||
| cherries | ||
| dragon fruits | ||
| """, | ||
| ) | ||
| add(["fruits.txt"], verbose) | ||
|
|
||
| append_to_file("fruits.txt", "figs") | ||
| add(["fruits.txt"], verbose) | ||
| commit("Insert figs into fruits.txt", verbose) | ||
|
|
||
| create_or_update_file( | ||
| "colours.txt", | ||
| """ | ||
| a file for colours | ||
| """, | ||
| ) | ||
| create_or_update_file( | ||
| "shapes.txt", | ||
| """ | ||
| a file for shapes | ||
| """, | ||
| ) | ||
| add(["colours.txt", "shapes.txt"], verbose) | ||
| commit("Add colours.txt, shapes.txt", verbose) | ||
|
|
||
|
|
||
| def _create_things_repository(verbose: bool): | ||
| """Create the gitmastery-things repository, deleting any existing ones.""" | ||
| full_repo_name = _get_full_repo_name(verbose) | ||
| _, return_code = run_command_with_code( | ||
| ["gh", "repo", "view", full_repo_name], verbose | ||
| ) | ||
|
|
||
| if return_code == 0: | ||
| print( | ||
| f"\nRepository 'https://github.com/{full_repo_name}' already exists on GitHub.\n" | ||
| "Please delete the existing repository before proceeding." | ||
| ) | ||
| sys.exit(1) | ||
|
Comment on lines
+64
to
+68
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I guess this part can be simplified to raising an exception with a similar message here? |
||
|
|
||
| run_command(["gh", "repo", "create", REPO_NAME, "--public"], verbose) | ||
|
|
||
|
|
||
| def _link_repositories(verbose: bool): | ||
| full_repo_name = _get_full_repo_name(verbose) | ||
| add_remote("origin", f"https://github.com/{full_repo_name}", verbose) | ||
|
|
||
|
|
||
| def _get_full_repo_name(verbose: bool) -> str: | ||
| output = run_command(["gh", "api", "user", "-q", ".login"], verbose) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose this can be changed to get the output from the utility function you will provide as well! |
||
| username = output.strip() if output else "" | ||
| return f"{username}/{REPO_NAME}" | ||
Uh oh!
There was an error while loading. Please reload this page.