-
Notifications
You must be signed in to change notification settings - Fork 25
Implement hands on hp-update-remote #81
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
VikramGoyal23
wants to merge
8
commits into
git-mastery:main
Choose a base branch
from
VikramGoyal23:update-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.
+128
−26
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f3adb79
Implement hands on hp-update-remote
VikramGoyal23 2730e8c
Fix repo naming
VikramGoyal23 31b7d9d
[tooling] Fix test script for all OS
woojiahao 414eaa7
Implement hands on hp-list-commits
jovnc b8e4a7c
fix: Use create_or_update_file instead of append_to_file
jovnc a1320e8
Implement hands on hp-add-remote
VikramGoyal23 cad35b3
Change multiline to single line
VikramGoyal23 ede54a2
Remove unnecessary default branch checking
VikramGoyal23 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
Some comments aren't visible on the classic Files Changed page.
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 |
|---|---|---|
| @@ -1,27 +1,3 @@ | ||
| # exercises | ||
|
|
||
| ## Git-Mastery exercise structure | ||
|
|
||
| When you download an exercise, you will get the following folder structure: | ||
|
|
||
|
|
||
| ## `.gitmastery-exercise.json` | ||
|
|
||
| Configuration fields for each exercise: | ||
|
|
||
| 1. `exercise_name`: name of exercise | ||
| 2. `tags`: list of tags for exercise | ||
| 3. `requires_git`: downloading the exercise will check that Git is installed and that `git config` is already done | ||
| 4. `requires_github`: downloading the exercise will check that Github and Github CLI is installed | ||
| 5. `base_files`: provides the files to be included outside of the repository, along with `.gitmastery-exercise.json` and `README.md`, most often used for `answers.txt` | ||
| 6. `exercise_repo`: configuration for what the exercise repository would look like | ||
| 1. `repo_type`: `local` (creates and initializes the folder as a Git repository) or `remote` (reference a repository on Github) | ||
| 2. `repo_name`: name of repository during cloning | ||
| 3. `repo_title`: (only read if `link` is present) link of repository on Github | ||
| 4. `create_fork`: (only read if `link` is present) flag to determine if we need to fork the repository to the student's machine, otherwise it just clones the repository | ||
| 5. `init`: (only read if `custom` is present) flag to determine if we will call `git init` on the exercise repository (useful if we don't want to start out with a Git repository) | ||
|
|
||
|
|
||
| ## TODOs | ||
|
|
||
| - [X] Add validation for exercise configuration (e.g. cannot fork + not require Github) - to run as CI | ||
| For more details, refer to the official developer documentation: https://git-mastery.github.io/developers |
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,37 @@ | ||
| import os | ||
|
|
||
| from exercise_utils.git import add, init, commit | ||
| from exercise_utils.file import create_or_update_file, append_to_file | ||
|
|
||
| __requires_git__ = True | ||
| __requires_github__ = False | ||
|
|
||
|
|
||
| def download(verbose: bool): | ||
| os.makedirs("things") | ||
| os.chdir("things") | ||
| init(verbose) | ||
| create_or_update_file( | ||
| "fruits.txt", | ||
| """ | ||
| apples | ||
| bananas | ||
| cherries | ||
| dragon fruits | ||
| figs | ||
| """, | ||
| ) | ||
| 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) |
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,27 @@ | ||
| import os | ||
|
|
||
| from exercise_utils.file import append_to_file, create_or_update_file | ||
| from exercise_utils.git import add, commit, init | ||
|
|
||
| __requires_git__ = True | ||
| __requires_github__ = False | ||
|
|
||
|
|
||
| def download(verbose: bool): | ||
| os.makedirs("things") | ||
| os.chdir("things") | ||
|
|
||
| init(verbose) | ||
|
|
||
| create_or_update_file( | ||
| "fruits.txt", | ||
| """ | ||
| apples | ||
| bananas | ||
| cherries | ||
| dragon fruits | ||
| """ | ||
| ) | ||
|
|
||
| add(["fruits.txt"], verbose) | ||
| commit("Add fruits.txt", verbose) |
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,51 @@ | ||
| import os | ||
| import subprocess | ||
|
|
||
| from exercise_utils.cli import run_command | ||
| from exercise_utils.file import create_or_update_file, append_to_file | ||
| from exercise_utils.git import add, init, commit | ||
|
|
||
| __requires_git__ = True | ||
| __requires_github__ = True | ||
|
|
||
| REPO_NAME = "gitmastery-things" | ||
|
|
||
| def download(verbose: bool): | ||
| username = run_command(["gh", "api", "user", "-q", ".login"], verbose).strip() | ||
| os.makedirs("things") | ||
| os.chdir("things") | ||
| init(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) | ||
| repo_check = subprocess.run( | ||
| ["gh", "repo", "view", f"{username}/{REPO_NAME}"], | ||
| capture_output=True, | ||
| text=True | ||
| ) | ||
|
|
||
| if repo_check.returncode == 0: | ||
| run_command(["gh", "repo", "delete", REPO_NAME, "--yes"], verbose) | ||
|
|
||
| run_command(["gh", "repo", "create", REPO_NAME, "--public"], verbose) | ||
| run_command(["git", "remote", "add", "origin", f"https://github.com/{username}/{REPO_NAME}"], verbose) | ||
|
|
||
| run_command(["git", "push", "-u", "origin", "main"], verbose) | ||
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 |
|---|---|---|
| @@ -1,5 +1,16 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| source venv/bin/activate | ||
| if [ -f "venv/bin/activate" ]; then | ||
| # Linux / macOS | ||
| source venv/bin/activate | ||
| elif [ -f "venv/Scripts/activate" ]; then | ||
| # Windows (Git Bash, Cygwin, or WSL) | ||
| source venv/Scripts/activate | ||
| else | ||
| echo "Error: Could not find Python virtual environment activation script." | ||
| echo "Please create one with: python -m venv venv" | ||
| exit 1 | ||
| fi | ||
|
|
||
| python -m pytest $1/tests/test_verify.py -s -vv |
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.