-
Notifications
You must be signed in to change notification settings - Fork 25
Implement hands on hp-push-tags #103
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?
Conversation
|
I'm not sure what to do when there's a conflict in repo names, i.e., the user already has a repo named |
We can use an alternative fork name such as |
Sure! Maybe I can submit follow-up commits regarding this later. |
|
The follow-up commits are up! |
woojiahao
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pending some comments from @damithc on the original hands-on discussion. Let's come back to this once he confirms if we need to fork the repository.
hands_on/push_tags.py
Outdated
| tag_with_options("v1.0", ["HEAD~1"], verbose) | ||
| annotated_tag_with_options("v0.9", ["HEAD~2", "-m", "First beta release"], verbose) | ||
|
|
||
| pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| pass |
hands_on/push_tags.py
Outdated
| check_existing_fork(username, "git-mastery", REPO_NAME) | ||
| check_same_repo_name(username, REPO_NAME) | ||
|
|
||
| run_command(["gh", "repo", "fork", f"git-mastery/{REPO_NAME}", REPO_NAME, "--clone"], verbose) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a comment for @damithc in the original hands-on discussion, but I doubt we actually need to fork the repository for the student. This would avoid polluting the student's Github with excessive repositories they might not be using
|
@woojiahao When I'm implementing the part checking whether the current user has a repo with the same name (but not necessarily a fork), I am a bit confused about the def has_repo(repo_name: str, is_fork: bool, verbose: bool) -> bool:
"""Returns if the given repository exists under the current user's repositories."""
command = ["gh", "repo", "view", repo_name]
if is_fork:
command.extend(["--json", "isFork", "--jq", ".isFork"])
result = run(
command,
verbose,
env={"GH_PAGER": "cat"},
)
return result.is_success() and result.stdout == "true"For this function, if the |
|
@dingZvel Ah good catch, that was a logic bug. I've pushed a fix for it already |
|
I've refactored the program using the new github_cli util functions! It now does the following:
Current issue: If the user already has a repo named Possible solution: Add a new util function |
woojiahao
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a comment for discussion, @damithc for your input
| def check_existing_fork(username: str, fork_owner_name: str, repo_name: str, verbose: bool) -> None: | ||
| result = run( | ||
| ["gh", | ||
| "api", | ||
| f"repos/{fork_owner_name}/{repo_name}/forks", | ||
| "-q", | ||
| f'''.[] | .owner.login | select(. =="{username}")''', | ||
| ], | ||
| verbose | ||
| ) | ||
| if result.is_success(): | ||
| if result.stdout == username: | ||
| print(f"ERROR: A fork of {fork_owner_name}/{repo_name} already exists! " | ||
| "Please delete the fork and run this download operation again.\n" | ||
| "!Aborting...") | ||
| exit(1) | ||
|
|
||
| def check_same_repo_name(username: str, repo_name: str, verbose: bool) -> str: | ||
| if has_repo(repo_name, False, verbose): | ||
| print(f"Warning: {username}/{repo_name} already exists, the fork repo will be " | ||
| f"named as {username}/{repo_name}-1") | ||
| return repo_name + "-1" | ||
| return repo_name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given what @damithc said, if this is used as part of a series of forks, we would be expecting to have already seen the fork before so that we can push to it. So I think it's worth just keeping the repository and avoiding re-forking when a duplicate is found. This is mostly because there is no real way for us to properly abort from this state given the limitations of the tooling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right! So just to clarify, when an existing fork is found, should I just skip the forking step, obtain the existing fork's repo name, and then clone it? Can I proceed to update the implementation or should I wait for further discussion first?
Exercise Review
Exercise Discussion
#94
Checklist
Git-Masteryorganization, have you created a request for it?repo-smithto validate the exercise grading scheme?test-download.sh?git-autograder?app?