Implement Role Marker and Wrapper Function for Github Cli#266
Implement Role Marker and Wrapper Function for Github Cli#266desmondwong1215 wants to merge 17 commits intogit-mastery:mainfrom
Conversation
|
Hi @desmondwong1215, thank you for your contribution! 🎉 This PR comes from your fork Before you request for a review, please ensure that you have tested your changes locally! Important The previously recommended way of using Please read the following instructions for the latest instructions. PrerequisitesEnsure that you have the Testing stepsIf you already have a local Git-Mastery root to test, you can skip the following step. Create a Git-Mastery root locally: gitmastery setupNavigate into the Git-Mastery root (defaults to cd gitmastery-exercises/Edit the {
# other fields...
"exercises_source": {
"username": "desmondwong1215",
"repository": "exercises",
"branch": "infra/tour9-10-autograding"
}
}Then, you can use the gitmastery download <your new change>
gitmastery verifyChecklist
Important To any reviewers of this pull request, please use the same instructions above to test the changes. |
cebe009 to
b6eee08
Compare
exercise_utils/exercise_config.py
Outdated
| def add_pr_config(pr_number: int, pr_repo_full_name: str) -> None: | ||
| update_config_fields( |
There was a problem hiding this comment.
A short docstring here would be nice, something like:
| def add_pr_config(pr_number: int, pr_repo_full_name: str) -> None: | |
| update_config_fields( | |
| def add_pr_config(pr_number: int, pr_repo_full_name: str) -> None: | |
| """Adds a PR config to .gitmastery-exercise.json.""" | |
| update_config_fields( |
exercise_utils/github_cli.py
Outdated
| command = _build_pr_command( | ||
| "list", | ||
| "--state", | ||
| validated_state, | ||
| "--json", | ||
| "number,title,state,author,headRefName,baseRefName", | ||
| repo_name=repo_name, | ||
| ) |
There was a problem hiding this comment.
Keep in mind that doing it this way only lists the 30 most recent PRs. To list more/less of them, I recommend adding the --limit flag with a limit parameter which allows you to manually define the number of PRs to list.
exercise_utils/github_cli.py
Outdated
| def list_prs(state: str, repo_name: str, verbose: bool) -> list[dict[str, Any]]: | ||
| """ | ||
| List pull requests. | ||
| PR state filter ('open', 'closed', 'merged', 'all') | ||
| """ | ||
| validated_state = _validate_choice(state, _PR_STATES, "state") | ||
| command = _build_pr_command( | ||
| "list", | ||
| "--state", | ||
| validated_state, | ||
| "--json", | ||
| "number,title,state,author,headRefName,baseRefName", | ||
| repo_name=repo_name, | ||
| ) | ||
|
|
||
| result = run(command, verbose) | ||
|
|
||
| if result.is_success(): | ||
| parsed = _parse_json_or_default(result.stdout, []) | ||
| return parsed if isinstance(parsed, list) else [] | ||
| return [] |
There was a problem hiding this comment.
I highly recommend adding support for the --search flag since I foresee it being useful in the future.
exercise_utils/roles.py
Outdated
| repo_name: str, | ||
| verbose: bool, | ||
| ) -> bool: | ||
| """Submit a review on a pull request with automatic role marker. True if review was submitted successfully, False otherwise""" |
There was a problem hiding this comment.
Incorrect docstring formatting. Considering changing it to:
| """Submit a review on a pull request with automatic role marker. True if review was submitted successfully, False otherwise""" | |
| """ | |
| Submit a review on a pull request with automatic role marker. | |
| True if review was submitted successfully, False otherwise | |
| """ |
exercise_utils/roles.py
Outdated
| """Format text with a role marker. | ||
| Example: |
There was a problem hiding this comment.
Formatting nit:
| """Format text with a role marker. | |
| Example: | |
| """ | |
| Format text with a role marker. | |
| Example: |
exercise_utils/roles.py
Outdated
| """Wrapper for git and GitHub operations with automatic role marker formatting. | ||
|
|
There was a problem hiding this comment.
Formatting nit:
| """Wrapper for git and GitHub operations with automatic role marker formatting. | |
| """ | |
| Wrapper for git and GitHub operations with automatic role marker formatting. | |
VikramGoyal23
left a comment
There was a problem hiding this comment.
Mostly LGTM, just some nits regarding role helpers.
| verbose: bool, | ||
| ) -> Optional[int]: | ||
| """Create a pull request with automatic role markers.""" | ||
| return github_cli.create_pr( | ||
| self._format_text(title), | ||
| self._format_text(body), | ||
| base, | ||
| head, | ||
| repo_name, | ||
| verbose, | ||
| ) |
There was a problem hiding this comment.
Developers are unable to create draft PRs with role markers since this function doesn't allow passing in a draft parameter.
| verbose: bool, | |
| ) -> Optional[int]: | |
| """Create a pull request with automatic role markers.""" | |
| return github_cli.create_pr( | |
| self._format_text(title), | |
| self._format_text(body), | |
| base, | |
| head, | |
| repo_name, | |
| verbose, | |
| ) | |
| verbose: bool, | |
| draft: bool = False, | |
| ) -> Optional[int]: | |
| """Create a pull request with automatic role markers.""" | |
| return github_cli.create_pr( | |
| self._format_text(title), | |
| self._format_text(body), | |
| base, | |
| head, | |
| repo_name, | |
| verbose, | |
| draft, | |
| ) |
exercise_utils/roles.py
Outdated
| comment: Optional[str] = None, | ||
| verbose: bool = False, | ||
| ) -> bool: | ||
| """Close a pull request without merging.""" | ||
| formatted_comment = self._format_text(comment) if comment else None | ||
| return github_cli.close_pr(pr_number, repo_name, formatted_comment, verbose) |
There was a problem hiding this comment.
This is missing the delete_branch parameter. Running this command will add the delete-branch flag according to the value of verbose.
| comment: Optional[str] = None, | |
| verbose: bool = False, | |
| ) -> bool: | |
| """Close a pull request without merging.""" | |
| formatted_comment = self._format_text(comment) if comment else None | |
| return github_cli.close_pr(pr_number, repo_name, formatted_comment, verbose) | |
| comment: Optional[str] = None, | |
| delete_branch: bool = False, | |
| verbose: bool = False, | |
| ) -> bool: | |
| """Close a pull request without merging.""" | |
| formatted_comment = self._format_text(comment) if comment else None | |
| return github_cli.close_pr( | |
| pr_number, | |
| repo_name, | |
| formatted_comment, | |
| delete_branch, | |
| verbose | |
| ) |
exercise_utils/exercise_config.py
Outdated
| if not value: | ||
| continue |
There was a problem hiding this comment.
Are you sure about this change? What this effectively does is prevent you from putting Falsy values as updates to values (e.g. False, "", []). While you most likely do not want to update a config with Falsy values, all this really does is add a bit of inflexibility to the use of the function.
Add Role Marker.
Add helper function to add config to gitmastery-exercise.json.
Add wrapper function for GitHub CLI.