-
Notifications
You must be signed in to change notification settings - Fork 26
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
hands_on/push_tags.py
Outdated
| 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?
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 believe this is correct.
So, the flow should be like this:
- if fork already exists, just clone it
- if fork doesn't yet exist, fork it then clone it
You can use the has_repo, clone_repo_with_gh and fork_repo from exercise_utils.
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.
Thank you for the clarification jovnc! Will update later. However, the has_repo function in exercise_utils only checks if a repo with a given name exists. If the user has forked this repo with a random name they created, we would not know the name and thus cannot find out the fork exists. So I believe I still need to stick to my check_existing_fork function.
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 agree that checking for existence of fork rather than repo can be more robust, in the event user renamed the repo name of the fork.
Perhaps, we can include a function has_fork inside exercise_utils? This can standardise naming convention and also allows us to reuse it across other exercises in the future.
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.
Sure! I'll then integrate this function into exercise_utils then!
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.
We can wait for @woojiahao input on this, as I'm not 100% certain that exercise_utils can be used for hands on, but from my understanding on the architecture, exercise_utils should be loaded into the namespace for hands on downloads.
VikramGoyal23
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 some comments regarding the new functions introduced, but I think the overall structure of the hands-on makes sense.
| def tag_with_options(tag_name: str, options: List[str], verbose: bool) -> None: | ||
| """Tags with the given tag_name with specified options.""" | ||
| run_command(["git", "tag", tag_name, *options], verbose) | ||
|
|
||
|
|
||
| def annotated_tag_with_options(tag_name: str, options: List[str], verbose: bool) -> None: | ||
| """Adds an annotated tag with the given tag_name with specified options.""" | ||
| run_command(["git", "tag", "-a", tag_name, *options], 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.
It is technically not necessary to have both of these functions, as the -a flag is unnecessary to make an annotated tag if the -m flag is passed with its message. However, since it increases code readability, I am not opposed to keeping both of these in.
|
Fixes are up for review! Sorry for the delay, I was between travels. |
VikramGoyal23
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.
Yup, looks alright from my end now, just waiting for @woojiahao's input on the additions to exercise_utils.
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?