-
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
Open
oadultradeepfield
wants to merge
13
commits into
git-mastery:main
Choose a base branch
from
oadultradeepfield:feat/hp-populate-remote
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f7f7db5
feat: Implement add_origin utils in Git wrapper
oadultradeepfield 295500c
feat: Implement T2L5/hp-populate-remote
oadultradeepfield 8a10b00
chore: Revert unintended formatter
oadultradeepfield ba2ef97
chore: Minor improvement in abstraction
oadultradeepfield a6cf95b
style: Improve code formatting
oadultradeepfield a6bb231
refactor: Change add_origin to a more general add_remote
oadultradeepfield de05a24
feat: Add utility function run_command_with_code
oadultradeepfield abc4bf8
refactor: Remove unnecessary abstractions in _setup_local_repository
oadultradeepfield 5e001c3
chore: Improve code formatting
oadultradeepfield 12187c7
fix: Change to single-line string
oadultradeepfield b7d53e1
fix: Check empty username before strip
oadultradeepfield 284a758
fix: Use empty string instead of none for empty username
oadultradeepfield 7ab822c
Merge branch 'git-mastery:main' into feat/hp-populate-remote
oadultradeepfield File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import os | ||
|
|
||
| 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): | ||
| _initialize_workspace(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.""" | ||
| _, return_code = run_command_with_code(["gh", "repo", "view", _get_full_repo_name(verbose)], verbose) | ||
| if return_code == 0: | ||
| run_command(["gh", "repo", "delete", REPO_NAME, "--yes"], verbose) | ||
|
|
||
| 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 _initialize_workspace(verbose: bool): | ||
| os.makedirs("things") | ||
| os.chdir("things") | ||
| init(verbose) | ||
|
|
||
|
|
||
| def _get_full_repo_name(verbose: bool) -> str: | ||
| output = run_command(["gh", "api", "user", "-q", ".login"], verbose) | ||
| username = output.strip() if output else "" | ||
| return f"{username}/{REPO_NAME}" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.