52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
|
#!/usr/bin/env python3
|
||
|
|
||
|
|
||
|
from commands.base import BaseCommand
|
||
|
from gitlab import get_mrs_for_branch, get_comments
|
||
|
|
||
|
|
||
|
class Comments(BaseCommand):
|
||
|
@staticmethod
|
||
|
def sort_comments(comments):
|
||
|
result = {}
|
||
|
|
||
|
for comment in comments:
|
||
|
author = comment["author"]["username"], comment["author"]["name"]
|
||
|
if author not in result:
|
||
|
result[author] = list()
|
||
|
|
||
|
result[author].append(comment)
|
||
|
|
||
|
return result
|
||
|
|
||
|
@staticmethod
|
||
|
def print_comments(comments):
|
||
|
comments = Comments.sort_comments(comments)
|
||
|
|
||
|
for author in comments:
|
||
|
login, name = author
|
||
|
print(f"***** {name} ({login}) *****")
|
||
|
|
||
|
for comment in comments[author]:
|
||
|
if comment["system"]:
|
||
|
continue
|
||
|
|
||
|
if comment["type"] == "DiffNote":
|
||
|
print(f"""L{comment["position"]["new_line"]}: {comment["body"]}""")
|
||
|
else:
|
||
|
print(f"""[{comment["created_at"]}]\n{comment["body"]}""")
|
||
|
print()
|
||
|
print()
|
||
|
|
||
|
def exec(self, login: str, submission: str):
|
||
|
mrs = get_mrs_for_branch(self.branch)
|
||
|
if not mrs:
|
||
|
return
|
||
|
|
||
|
iid = mrs[0]["iid"]
|
||
|
comments = get_comments(iid)
|
||
|
|
||
|
print(f"# {self.branch}")
|
||
|
self.print_comments(comments)
|
||
|
print(f"# {self.branch}")
|