Make comments differentiate files

Closes #12
This commit is contained in:
Matej Focko 2020-05-26 14:17:11 +02:00
parent a0eaafc12e
commit 102ef3e6ec
Signed by: mfocko
GPG key ID: 299B916A55682021

View file

@ -19,15 +19,20 @@ class Comments(BaseCommand):
for comment in comments: for comment in comments:
author = comment["author"]["username"], comment["author"]["name"] author = comment["author"]["username"], comment["author"]["name"]
if author not in result: if author not in result:
result[author] = list() result[author] = dict()
result[author].append(comment) file_path = comment["position"]["new_path"] if "position" in comment else None
if file_path not in result[author]:
result[author][file_path] = list()
result[author][file_path].append(comment)
# sort by lines # sort by lines
for author in result: for author in result:
result[author].sort(key=lambda comment: for file_path in result[author]:
comment["position"]["new_line"] if "position" in comment result[author][file_path].sort(key=lambda comment:
else math.inf) comment["position"]["new_line"] if "position" in comment
else math.inf)
return result return result
@ -40,19 +45,22 @@ class Comments(BaseCommand):
header = f"***** {name} ({login}) *****".center(40, "*").center(80) header = f"***** {name} ({login}) *****".center(40, "*").center(80)
print(header) print(header)
for comment in comments[author]: for file_path in comments[author]:
if comment["system"]: if file_path is not None:
continue print(f"# `{file_path.split('/')[-1]}`")
for comment in comments[author][file_path]:
if comment["system"]:
continue
if comment["type"] == "DiffNote": if comment["type"] == "DiffNote":
body = comment["body"].replace( body = comment["body"].replace(
"\n", "\n" + " " * (Comments.width + 2) "\n", "\n" + " " * (Comments.width + 2)
) )
print( print(
f"""{f'L{comment["position"]["new_line"]}':>{Comments.width}}: {body}""" f"""{f'L{comment["position"]["new_line"]}':>{Comments.width}}: {body}"""
) )
else: else:
print(f"""[{comment["created_at"]}]\n{comment["body"]}""") print(f"""[{comment["created_at"]}]\n{comment["body"]}""")
print(header) print(header)
def exec(self, submission: Submission) -> None: def exec(self, submission: Submission) -> None: