From 102ef3e6ec1b1b80ac5974cc93a8eae80bd65718 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Tue, 26 May 2020 14:17:11 +0200 Subject: [PATCH] Make comments differentiate files Closes #12 --- commands/comments.py | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/commands/comments.py b/commands/comments.py index 3d7fe79..816a3a2 100644 --- a/commands/comments.py +++ b/commands/comments.py @@ -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: