Skip to content

Commit 21ac308

Browse files
committed
[push-over] Add verification
1 parent 3157cda commit 21ac308

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

push_over/verify.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import os
22
import subprocess
3-
from typing import List, Optional
43
from datetime import datetime
5-
import pytz
4+
from typing import List, Optional
65

6+
import pytz
77
from git_autograder import GitAutograderOutput, GitAutograderRepo, GitAutograderStatus
88

99
MISSING_REPO = "You should have {repo} in your exercise folder. You might want to re-download the exercise."
10+
MISSING_COMMIT = "You should have made a separate commit!"
11+
MISSING_COMMIT_REMOTE = (
12+
"You might have forgotten to push your commit to the remote repository."
13+
)
1014

1115

1216
def run_command(command: List[str], verbose: bool) -> Optional[str]:
@@ -27,15 +31,11 @@ def run_command(command: List[str], verbose: bool) -> Optional[str]:
2731

2832

2933
def verify() -> GitAutograderOutput:
30-
comments: List[str] = []
3134
started_at = datetime.now(tz=pytz.UTC)
3235

3336
username = run_command(["gh", "api", "user", "-q", ".login"], verbose=False)
3437
repo_name = f"{username}-gitmastery-push-over"
3538

36-
print(os.getcwd())
37-
print(os.listdir())
38-
3939
if not os.path.isdir(repo_name):
4040
return GitAutograderOutput(
4141
status=GitAutograderStatus.UNSUCCESSFUL,
@@ -46,4 +46,18 @@ def verify() -> GitAutograderOutput:
4646

4747
repo = GitAutograderRepo("push-over", repo_name)
4848

49-
return repo.to_output(comments)
49+
if repo.commits == 1:
50+
raise repo.wrong_answer([MISSING_COMMIT])
51+
52+
origin_remote = repo.remotes.remote("origin")
53+
origin_remote.remote.fetch()
54+
remote_branch = repo.repo.refs["origin/main"]
55+
remote_commits = list(repo.repo.iter_commits(remote_branch))
56+
57+
if len(remote_commits) == 1:
58+
raise repo.wrong_answer([MISSING_COMMIT_REMOTE])
59+
60+
return repo.to_output(
61+
["Great work pushing changes to the remote!"],
62+
status=GitAutograderStatus.SUCCESSFUL,
63+
)

0 commit comments

Comments
 (0)