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:
author = comment["author"]["username"], comment["author"]["name"]
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
for author in result:
result[author].sort(key=lambda comment:
comment["position"]["new_line"] if "position" in comment
else math.inf)
for file_path in result[author]:
result[author][file_path].sort(key=lambda comment:
comment["position"]["new_line"] if "position" in comment
else math.inf)
return result
@ -40,19 +45,22 @@ class Comments(BaseCommand):
header = f"***** {name} ({login}) *****".center(40, "*").center(80)
print(header)
for comment in comments[author]:
if comment["system"]:
continue
for file_path in comments[author]:
if file_path is not None:
print(f"# `{file_path.split('/')[-1]}`")
for comment in comments[author][file_path]:
if comment["system"]:
continue
if comment["type"] == "DiffNote":
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"]}""")
if comment["type"] == "DiffNote":
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"]}""")
print(header)
def exec(self, submission: Submission) -> None: