52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
|
|
|
|
import re
|
|
|
|
|
|
from commands.base import BaseGitCommand
|
|
from git import add_files, commit, push
|
|
from gitlab import post_mr
|
|
from submission import Submission
|
|
from utils import run_cmd
|
|
|
|
|
|
class MergeRequests(BaseGitCommand):
|
|
@staticmethod
|
|
def get_files(submission: Submission) -> None:
|
|
files = f"{{master-naostro/LoadTest/{submission.homework}.py,teacher_email}}"
|
|
|
|
if run_cmd("rsync", "-avzP", f"aisa:{submission.path}/{files}", "./")[0] != 0:
|
|
exit(1)
|
|
|
|
@staticmethod
|
|
def call_flake(submission: Submission) -> None:
|
|
process = run_cmd("flake8", "--exit-zero", f"{submission.homework}.py")[1]
|
|
with open("flake.log", "w") as f:
|
|
print(process.stdout, file=f)
|
|
|
|
@staticmethod
|
|
def get_mail() -> None:
|
|
with open("teacher_email") as file:
|
|
contents = file.read()
|
|
match = re.search(r"<pre>((.*\s+)+)<\/pre>", contents)
|
|
|
|
return match.group(1) if match else contents
|
|
|
|
def exec(self, submission: Submission) -> None:
|
|
self.get_files(submission)
|
|
self.call_flake(submission)
|
|
|
|
add_files(f"{submission.homework}.py", "flake.log")
|
|
commit(f'"Add sources and flake log ({submission.branch} {submission.login})"')
|
|
push("origin", submission.branch)
|
|
|
|
post_mr(
|
|
source_branch=submission.branch,
|
|
target_branch="master",
|
|
title=f"[{submission.branch}] {submission.login}",
|
|
description=f"```\n{self.get_mail()}\n```",
|
|
labels=submission.homework,
|
|
remove_source_branch="true",
|
|
assignee_ids=["1772"],
|
|
)
|