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

64 lines
1.7 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
2019-11-23 13:46:45 +01:00
import json
from commands.base import BaseCommand
2019-11-30 17:47:52 +01:00
from submission import Submission
class Comments(BaseCommand):
2019-11-23 13:46:45 +01:00
width = 5
@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
2019-11-30 18:08:26 +01:00
header = f"***** {name} ({login}) *****".center(40, "*").center(80)
print(header)
for comment in comments[author]:
if comment["system"]:
continue
if comment["type"] == "DiffNote":
2019-11-23 13:46:45 +01:00
body = comment["body"].replace(
"\n", "\n" + " " * (Comments.width + 2)
)
print(
f"""{f'L{comment["position"]["new_line"]}':>{Comments.width}}: {body}"""
)
else:
print(f"""[{comment["created_at"]}]\n{comment["body"]}""")
2019-11-30 18:08:26 +01:00
print(header)
2019-11-30 17:47:52 +01:00
def exec(self, submission: Submission) -> None:
2019-12-12 12:15:52 +01:00
mrs = self.gitlab.get_mrs_for_branch(submission.branch)
if not mrs:
return
iid = mrs[0]["iid"]
2019-12-12 12:15:52 +01:00
comments = self.gitlab.get_comments(iid)
2019-11-30 18:08:26 +01:00
branch = f"### {submission.branch.center(20)} ###".upper().center(80, "#")
print(branch)
self.print_comments(comments)
2019-11-30 18:08:26 +01:00
print(branch)