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/merge_requests.py

65 lines
2 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
2020-06-08 17:39:36 +02:00
import glob
import os
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
from utils import run_cmd
class MergeRequests(BaseGitCommand):
2020-04-03 14:10:37 +02:00
def get_files(self, submission: Submission) -> None:
2020-06-08 17:39:36 +02:00
files = []
for file in self.hw["files"]:
files.extend(glob.glob(f'{submission.path}/{self.hw["prefix"]}/{file}'))
files = map(lambda f: f.split("/")[-1], files)
for file in files:
if (
run_cmd(
"rsync",
"-avzP",
f"aisa:{submission.path}/{self.hw['prefix']}/{file}",
"./",
)[0]
!= 0
):
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]
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:
self.get_files(submission)
2020-04-03 14:10:37 +02:00
# self.call_flake(submission)
2020-06-08 17:39:36 +02:00
add_files(*self.hw["files"])
2020-04-03 14:10:37 +02:00
commit(f'"Add sources ({submission.branch} {submission.login})"')
2019-11-30 17:47:52 +01:00
push("origin", submission.branch)
2020-05-26 14:03:58 +02:00
mail = f"<details>\n<summary>Mail</summary>\n\n<pre>{submission.get_mail()}</pre></details>"
2020-06-08 17:39:36 +02:00
try:
mr = self.gitlab.post_mr(
2020-06-08 17:39:36 +02:00
source_branch=submission.branch,
target_branch="master",
title=f"[{submission.homework}{'-opravne' if submission.correction else ''}] {submission.login}",
description=mail,
labels=submission.homework,
remove_source_branch="true",
assignee_ids=["1772"],
)
2020-06-08 18:05:05 +02:00
mr.comment(
body="Summary\n=======\n\n# TODO\n\nDiff notes\n==========\n\n# TODO\n\nCorrection (YYYY/MM/DD)\n=======================\n\n# TODO"
)
2020-06-08 17:39:36 +02:00
except:
pass