2019-11-22 21:13:07 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
|
|
|
|
from commands.base import BaseGitCommand
|
|
|
|
from git import add_files, commit, push
|
2019-11-30 17:47:52 +01:00
|
|
|
from submission import Submission
|
2019-11-22 21:13:07 +01:00
|
|
|
from utils import run_cmd
|
|
|
|
|
|
|
|
|
|
|
|
class MergeRequests(BaseGitCommand):
|
2020-04-03 14:10:37 +02:00
|
|
|
def get_files(self, submission: Submission) -> None:
|
2020-05-25 23:51:08 +02:00
|
|
|
files = f"{self.hw['prefix']}/"
|
|
|
|
if len(self.hw['files']) > 1:
|
|
|
|
files += f"{{{','.join(self.hw['files'])}}}"
|
|
|
|
else:
|
|
|
|
files += f"{self.hw['files'][0]}"
|
2019-11-22 21:13:07 +01:00
|
|
|
|
2019-11-30 17:47:52 +01:00
|
|
|
if run_cmd("rsync", "-avzP", f"aisa:{submission.path}/{files}", "./")[0] != 0:
|
2019-11-22 21:13:07 +01:00
|
|
|
exit(1)
|
|
|
|
|
|
|
|
@staticmethod
|
2019-11-30 17:47:52 +01:00
|
|
|
def call_flake(submission: Submission) -> None:
|
|
|
|
process = run_cmd("flake8", "--exit-zero", f"{submission.homework}.py")[1]
|
2019-11-22 21:13:07 +01:00
|
|
|
with open("flake.log", "w") as f:
|
|
|
|
print(process.stdout, file=f)
|
|
|
|
|
2019-11-30 17:47:52 +01:00
|
|
|
def exec(self, submission: Submission) -> None:
|
2019-11-22 21:13:07 +01:00
|
|
|
self.get_files(submission)
|
2020-04-03 14:10:37 +02:00
|
|
|
# self.call_flake(submission)
|
2019-11-22 21:13:07 +01:00
|
|
|
|
2020-04-03 14:10:37 +02:00
|
|
|
add_files(*self.hw['files'])
|
|
|
|
commit(f'"Add sources ({submission.branch} {submission.login})"')
|
2019-11-30 17:47:52 +01:00
|
|
|
push("origin", submission.branch)
|
2019-11-22 21:13:07 +01:00
|
|
|
|
2020-05-26 14:03:58 +02:00
|
|
|
mail = f"<details>\n<summary>Mail</summary>\n\n<pre>{submission.get_mail()}</pre></details>"
|
|
|
|
|
2019-12-12 12:15:52 +01:00
|
|
|
self.gitlab.post_mr(
|
2019-11-30 17:47:52 +01:00
|
|
|
source_branch=submission.branch,
|
2019-11-22 21:13:07 +01:00
|
|
|
target_branch="master",
|
2019-12-02 11:39:23 +01:00
|
|
|
title=f"[{submission.homework}{'-opravne' if submission.correction else ''}] {submission.login}",
|
2020-05-26 14:03:58 +02:00
|
|
|
description=mail,
|
2019-11-30 17:47:52 +01:00
|
|
|
labels=submission.homework,
|
2019-11-22 21:13:07 +01:00
|
|
|
remove_source_branch="true",
|
|
|
|
assignee_ids=["1772"],
|
|
|
|
)
|