|
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 |
2 | 6 |
|
3 | | -from git_autograder import GitAutograderOutput, GitAutograderRepo |
| 7 | +from git_autograder import GitAutograderOutput, GitAutograderRepo, GitAutograderStatus |
4 | 8 |
|
| 9 | +MISSING_REPO = "You should have {repo} in your exercise folder. You might want to re-download the exercise." |
5 | 10 |
|
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: |
7 | 30 | 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 | + ) |
8 | 43 |
|
9 | | - # INSERT YOUR GRADING CODE HERE |
| 44 | + repo = GitAutograderRepo("push-over", repo_name) |
10 | 45 |
|
11 | 46 | return repo.to_output(comments) |
0 commit comments