Skip to content

Commit cb09a2c

Browse files
committed
[push-over] Basic verify
1 parent c4ae12c commit cb09a2c

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

push_over/verify.py

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,46 @@
1-
from typing import List
1+
import os
2+
import subprocess
3+
from typing import List, Optional
4+
from datetime import datetime
5+
import pytz
26

3-
from git_autograder import GitAutograderOutput, GitAutograderRepo
7+
from git_autograder import GitAutograderOutput, GitAutograderRepo, GitAutograderStatus
48

9+
MISSING_REPO = "You should have {repo} in your exercise folder. You might want to re-download the exercise."
510

6-
def verify(repo: GitAutograderRepo) -> GitAutograderOutput:
11+
12+
def run_command(command: List[str], verbose: bool) -> Optional[str]:
13+
try:
14+
result = subprocess.run(
15+
command,
16+
capture_output=True,
17+
text=True,
18+
check=True,
19+
)
20+
if verbose:
21+
print(result.stdout)
22+
return result.stdout.strip()
23+
except subprocess.CalledProcessError as e:
24+
if verbose:
25+
print(e.stderr)
26+
return None
27+
28+
29+
def verify() -> GitAutograderOutput:
730
comments: List[str] = []
31+
started_at = datetime.now(tz=pytz.UTC)
32+
33+
username = run_command(["gh", "api", "user", "-q", ".login"], verbose=False)
34+
repo_name = f"{username}-gitmastery-push-over"
35+
36+
if not os.path.isdir(repo_name):
37+
return GitAutograderOutput(
38+
status=GitAutograderStatus.UNSUCCESSFUL,
39+
started_at=started_at,
40+
completed_at=datetime.now(tz=pytz.UTC),
41+
comments=[MISSING_REPO.format(repo=repo_name)],
42+
)
843

9-
# INSERT YOUR GRADING CODE HERE
44+
repo = GitAutograderRepo("push-over", repo_name)
1045

1146
return repo.to_output(comments)

0 commit comments

Comments
 (0)