Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions mailman/patchset.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
REMOTE_PULL_URL = 'http://git:8000/grading.git'

MAIL_DIR_ABSPATH = "/var/lib/email/mail"
maildir = pathlib.Path(MAIL_DIR_ABSPATH)


def try_or_false(do, exc):
Expand Down Expand Up @@ -38,7 +39,6 @@ def tag_and_push(repo_path, tag_name):

def do_check(repo_path, cover_letter, patches):
repo = git.Repo.init(repo_path)
maildir = pathlib.Path(MAIL_DIR_ABSPATH)
whitespace_errors = []

def am_cover_letter(keep_empty=True):
Expand All @@ -49,13 +49,13 @@ def am_cover_letter(keep_empty=True):

if try_or_false(lambda: am_cover_letter(keep_empty=False),
git.GitCommandError):
return "missing cover letter"
return "missing cover letter!"

repo.git.execute(["git", *author_args, "am", "--abort"])
if not try_or_false(lambda: am_cover_letter(keep_empty=True),
git.GitCommandError):
return ("missing cover letter and "
"first patch failed to apply")
"first patch failed to apply!")

for i, patch in enumerate(patches):
patch_abspath = str(maildir / patch.msg_id)
Expand All @@ -77,24 +77,28 @@ def do_git_am(extra_args=[]):
continue

# If we still fail, the patch does not apply
return f'patch {i+1} failed to apply'
return f'patch {i+1} failed to apply!'

if whitespace_errors:
return ('whitespace error patch(es) '
f'{",".join(whitespace_errors)}')
f'{",".join(whitespace_errors)}?')
else:
return 'patchset applies'
return 'patchset applies.'


def check(cover_letter, patches, submission_id):
with tempfile.TemporaryDirectory() as repo_path:
status = do_check(repo_path, cover_letter, patches)
if status[-1] == '!':
repo = git.Repo(repo_path)
for patch in patches:
patch_abspath = str(maildir / patch.msg_id)
repo.git.execute(['git', *author_args, 'commit', '--allow-empty', '-F', patch_abspath])
tag_and_push(repo_path, submission_id)
return status


def apply_peer_review(email, submission_id, review_id):
maildir = pathlib.Path(MAIL_DIR_ABSPATH)
args = [*git_am_args, '--empty=keep']
patch_abspath = str(maildir / email.msg_id)

Expand Down