This repository has been archived on 2023-07-17. You can view files and clone it, but cannot push or open issues or pull requests.
pushee/commands.py

76 lines
No EOL
2.1 KiB
Python

#!/usr/bin/env python3
import re
from constants import HOMEWORK, SUFFIX
from git import add_files, commit, push
from gitlab import post_mr, get_mrs_for_branch, set_assignees, merge_mr
from utils import run_cmd, get_branch
class MergeRequests:
@staticmethod
def get_files(submission: str) -> None:
relative_path = f"/home/kontr/kontr/_tmp_/ib111/{HOMEWORK}/{submission}"
files = f"{{master-naostro/LoadTest/{HOMEWORK}.py,teacher_email}}"
if run_cmd("rsync", "-avzP", f"aisa:{relative_path}/{files}", "./")[0] != 0:
exit(1)
@staticmethod
def call_flake() -> None:
process = run_cmd("flake8", "--exit-zero", f"{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 __call__(self, login: str, submission: str) -> None:
branch = get_branch(login)
self.get_files(submission)
self.call_flake()
add_files(f"{HOMEWORK}.py", "flake.log")
commit(f'"Add sources and flake log ({HOMEWORK}{SUFFIX} {login})"')
push("origin", branch)
post_mr(
source_branch=branch,
target_branch="master",
title=f"[{HOMEWORK}{SUFFIX}] {login}",
description=f"```\n{self.get_mail()}\n```",
labels=HOMEWORK,
remove_source_branch="true",
assignee_ids=["1772"],
)
class UpdateAssignees:
def __call__(self, login: str, submission: str) -> None:
branch = get_branch(login)
iid = get_mrs_for_branch(branch)[0]["iid"]
print(f"{login} @ {branch} : {iid}")
set_assignees(iid, ["39", "1772"])
class Merge:
def __call__(self, login: str, submission: str):
branch = get_branch(login)
iid = get_mrs_for_branch(branch)[0]["iid"]
merge_mr(iid)
class Test:
def __call__(self, login: str, submission: str):
print(f"{login} - {submission}")