From ea7b510926487841cf3caa7b5c3e7acb2614d673 Mon Sep 17 00:00:00 2001 From: Karma Riuk Date: Tue, 20 May 2025 16:40:50 +0200 Subject: [PATCH] added another way pr can be invalid, if they have no lines for their comment (github api be wierd) --- errors.py | 4 ++++ pull_requests.py | 29 ++++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/errors.py b/errors.py index e1c2059..37da78c 100644 --- a/errors.py +++ b/errors.py @@ -13,6 +13,10 @@ class NoDiffsAfterError(SetupException): reason_for_failure = "Couldn't get the diffs after the last comment" +class NoLinesForCommentError(SetupException): + reason_for_failure = "There are no line reference for the comment" + + class CantCloneRepoError(SetupException): reason_for_failure = "Couldn't clone the repository" diff --git a/pull_requests.py b/pull_requests.py index 01b1605..8965b8b 100644 --- a/pull_requests.py +++ b/pull_requests.py @@ -186,15 +186,34 @@ def get_files(pr: PullRequest, repo: Repository, repo_path: str) -> dict[str, Fi def get_comments(pr: PullRequest) -> list[Comment]: ret = [] for comment in pr.get_review_comments(): + if ( + comment.start_line is None + and comment.original_start_line is None + and comment.line is None + and comment.original_line is None + ): + raise NoLinesForCommentError( + f"Github gave a comment with no lines what so ever {comment}" + ) + + from_ = comment.start_line + if from_ is None: + from_ = comment.original_start_line + + to = comment.line + if to is None: + to = comment.original_line + comment_to_add = Comment( body=comment.body, file=comment.path, - from_=comment.start_line if comment.start_line else comment.line, - to=comment.line, + from_=from_, + to=to, ) - if comment_to_add.from_ is None or comment_to_add.to is None: - comment_to_add.to = comment.original_line - comment_to_add.from_ = comment.original_start_line + if comment_to_add.from_ is None and comment_to_add.to is None: + raise NoLinesForCommentError( + "After creating the comment object, the from_ an to fields were None" + ) ret.append(comment_to_add) return ret