-
Notifications
You must be signed in to change notification settings - Fork 25
Implement Role Marker and Wrapper Function for Github Cli #266
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
desmondwong1215
wants to merge
17
commits into
git-mastery:main
Choose a base branch
from
desmondwong1215:infra/tour9-10-autograding
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
17 commits
Select commit
Hold shift + click to select a range
dd3a1f0
Implement Role Marker
desmondwong1215 8b646cb
Add wrapper for gh cli
desmondwong1215 02ce7ad
Reformat file
desmondwong1215 f958bf8
Update config and github_cli
desmondwong1215 b6eee08
Update config and github_cli
desmondwong1215 2c07ccc
Update exercise_config
desmondwong1215 c18d8f3
Rename repo_full_name to pr_repo_full_name
desmondwong1215 475df72
Update exercise_config
desmondwong1215 6edb4f5
Update github_cli
desmondwong1215 28661aa
Update github_cli wrapper function
desmondwong1215 ff28694
Update github_cli
desmondwong1215 98796ef
Update exercise_config
desmondwong1215 2945eed
Fix formatting issues
desmondwong1215 5b33f09
Update list_prs github_cli
desmondwong1215 7b91c5a
Add missing parameters
desmondwong1215 19d98a2
Fix bug when merging config
desmondwong1215 701f5b2
Update exercise_config
desmondwong1215 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import json | ||
| from pathlib import Path | ||
| from typing import Any | ||
|
|
||
|
|
||
| EXERCISE_CONFIG_FILE_NAME = ".gitmastery-exercise.json" | ||
|
|
||
|
|
||
| def _merge_config_fields(config: dict[str, Any], updates: dict[str, Any]) -> None: | ||
| """ | ||
| Recursively updates a JSON-like configuration as specified by the provided dictionary. | ||
| """ | ||
| for key, value in updates.items(): | ||
| if isinstance(value, dict): | ||
| current_value = config.get(key) | ||
| if not isinstance(current_value, dict): | ||
| config[key] = {} | ||
| _merge_config_fields(config[key], value) | ||
| continue | ||
|
|
||
| config[key] = value | ||
|
|
||
|
|
||
| def update_config_fields(updates: dict[str, Any], config_path: Path) -> None: | ||
| """ | ||
| Update fields in .gitmastery-exercise.json. | ||
|
|
||
| Example updates: | ||
| { | ||
| "exercise_repo": { | ||
| "pr_number": 1, | ||
| "pr_repo_full_name": "owner/repo", | ||
| }, | ||
| "teammate": "teammate-bob", | ||
| } | ||
| """ | ||
| config_path = Path(config_path) | ||
| if not config_path.exists(): | ||
| raise FileNotFoundError( | ||
| f".gitmastery-exercise.json file not found at {config_path.resolve()}" | ||
| ) | ||
| config = json.loads(config_path.read_text()) | ||
| _merge_config_fields(config, updates) | ||
|
|
||
| config_path.write_text(json.dumps(config, indent=2)) | ||
|
|
||
|
|
||
| def add_pr_config( | ||
| config_path: Path, | ||
| pr_number: int | None = None, | ||
| pr_repo_full_name: str | None = None, | ||
| ) -> None: | ||
| exercise_repo_updates: dict[str, int | str] = {} | ||
| if pr_number is not None: | ||
| exercise_repo_updates["pr_number"] = pr_number | ||
| if pr_repo_full_name is not None: | ||
| exercise_repo_updates["pr_repo_full_name"] = pr_repo_full_name | ||
|
|
||
| update_config_fields( | ||
| {"exercise_repo": exercise_repo_updates}, | ||
| config_path=config_path / ".gitmastery-exercise.json", | ||
| ) | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.