Skip to content

Commit 923fc0f

Browse files
committed
[push-over] Add base download
1 parent 5ca02e0 commit 923fc0f

File tree

8 files changed

+126
-0
lines changed

8 files changed

+126
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"exercise_name": "push-over",
3+
"tags": [
4+
"git-remote",
5+
"git-commit",
6+
"git-push"
7+
],
8+
"is_downloadable": true,
9+
"requires_repo": false,
10+
"requires_github": true,
11+
"resources": {}
12+
}

push_over/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# push-over
2+
3+
<!--- Insert exercise description -->
4+
5+
## Learning outcomes
6+
7+
<!--- Insert exercise learning outcomes -->
8+
9+
## Task
10+
11+
<!--- Insert exercise task, simplify what needs to be done -->
12+
13+
## Verification
14+
15+
Run `gitmastery verify` in this exercise folder.
16+
17+
## Hints
18+
19+
<!--- Insert hints here -->
20+
<!---
21+
Use Github Markdown's collapsible content:
22+
<details>
23+
<summary>...</summary>
24+
...
25+
</details>
26+
-->

push_over/__init__.py

Whitespace-only changes.

push_over/download.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import os
2+
import subprocess
3+
from sys import exit
4+
from typing import List, Optional
5+
6+
7+
def run_command(command: List[str], verbose: bool) -> Optional[str]:
8+
try:
9+
result = subprocess.run(
10+
command,
11+
capture_output=True,
12+
text=True,
13+
check=True,
14+
)
15+
if verbose:
16+
print(result.stdout)
17+
return result.stdout.strip()
18+
except subprocess.CalledProcessError as e:
19+
if verbose:
20+
print(e.stderr)
21+
exit(1)
22+
23+
24+
def setup(verbose: bool = False):
25+
username = run_command(["gh", "api", "user", "-q", ".login"], verbose=verbose)
26+
fork_name = f"{username}-gitmastery-push-over"
27+
28+
has_fork = run_command(
29+
[
30+
"gh",
31+
"repo",
32+
"view",
33+
fork_name,
34+
"--json",
35+
"isFork",
36+
"--jq",
37+
".isFork",
38+
],
39+
verbose,
40+
)
41+
42+
if not has_fork:
43+
run_command(
44+
[
45+
"gh",
46+
"repo",
47+
"fork",
48+
"git-mastery/push-over",
49+
"--default-branch-only",
50+
"--fork-name",
51+
fork_name,
52+
],
53+
verbose=verbose,
54+
)
55+
56+
has_clone = os.path.isdir(fork_name)
57+
58+
if not has_clone:
59+
run_command(["gh", "repo", "clone", f"{username}/{fork_name}"], verbose=verbose)

push_over/tests/__init__.py

Whitespace-only changes.

push_over/tests/specs/base.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
initialization:
2+
steps:
3+
- type: commit
4+
empty: true
5+
message: Empty commit
6+
id: start

push_over/tests/test_verify.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from git_autograder import GitAutograderTestLoader
2+
3+
from ..verify import verify
4+
5+
REPOSITORY_NAME = "push-over"
6+
7+
loader = GitAutograderTestLoader(__file__, REPOSITORY_NAME, verify)
8+
9+
10+
def test():
11+
with loader.load("specs/base.yml", "start"):
12+
pass

push_over/verify.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from typing import List
2+
3+
from git_autograder import GitAutograderOutput, GitAutograderRepo
4+
5+
6+
def verify(repo: GitAutograderRepo) -> GitAutograderOutput:
7+
comments: List[str] = []
8+
9+
# INSERT YOUR GRADING CODE HERE
10+
11+
return repo.to_output(comments)

0 commit comments

Comments
 (0)