diff --git a/reviewrot/__init__.py b/reviewrot/__init__.py index af0eaaa..d15ed7a 100644 --- a/reviewrot/__init__.py +++ b/reviewrot/__init__.py @@ -400,7 +400,7 @@ def dict_constructor(loader, node): # format the output to print a blank scalar rather than null def represent_none(self, _): """TODO: docstring goes here.""" - return self.represent_scalar("tag:yaml.org,2002:null", u"") + return self.represent_scalar("tag:yaml.org,2002:null", "") yaml.add_representer(type(None), represent_none) diff --git a/reviewrot/githubstack.py b/reviewrot/githubstack.py index d97fb56..690d9a0 100644 --- a/reviewrot/githubstack.py +++ b/reviewrot/githubstack.py @@ -193,11 +193,19 @@ def get_last_comment(self, pr): last_issue_comment = None last_comment = None - if review_comments.totalCount > 0: + try: + # review_comments.totalCount may return a non-zero value when + # the list of comments is actually empty :( last_review_comment = review_comments.reversed[0] + except IndexError: + pass - if issue_comments.totalCount > 0: + try: + # issue_comments.totalCount may return a non-zero value when + # the list of comments is actually empty :( last_issue_comment = issue_comments.reversed[0] + except IndexError: + pass # check which is newer if pr has both types of comments if last_issue_comment and last_review_comment: diff --git a/reviewrot/pagurestack.py b/reviewrot/pagurestack.py index e322770..a125c9b 100644 --- a/reviewrot/pagurestack.py +++ b/reviewrot/pagurestack.py @@ -216,7 +216,7 @@ def _avatar(self, username, ssl_verify=True): "Fallback to construct based on username" ) query = urllib.parse.urlencode(avatar_query) - openid = u"http://%s.id.fedoraproject.org/" % username + openid = "http://%s.id.fedoraproject.org/" % username idx = hashlib.sha256(openid.encode("utf-8")).hexdigest() avatar_url = "https://seccdn.libravatar.org/avatar/%s?%s" % (idx, query) diff --git a/test/github_tests/mock_github.py b/test/github_tests/mock_github.py index 025fb25..21b058d 100644 --- a/test/github_tests/mock_github.py +++ b/test/github_tests/mock_github.py @@ -35,22 +35,24 @@ class MockValueOlder: class MockGithubComments: """Mocks Github Comments object.""" - totalCount = int(1) + totalCount = int(1) # noqa: N815 reversed = [MockValue] class MockGithubCommentsOlder: """Mocks Github Comments object.""" - totalCount = int(1) + totalCount = int(1) # noqa: N815 reversed = [MockValueOlder] class MockGithubCommentsEmpty: """Mocks Github Comment object with no comments.""" - totalCount = 0 - reversed = [MockValue] + # Simulate the bug from the PyGithub package, where + # totalCount is non-zero when there are no comments. + totalCount = int(2) # noqa: N815 + reversed = [] class MockPull: diff --git a/test/github_tests/test_github.py b/test/github_tests/test_github.py index bb1ec05..d79e921 100644 --- a/test/github_tests/test_github.py +++ b/test/github_tests/test_github.py @@ -75,8 +75,7 @@ def test_get_last_comment_nothing(self, mock_lastcomment): # Call function response = GithubService().get_last_comment(mock_pr) - # Validate function calls and response - mock_lastcomment.assert_not_called() + # Validate function response self.assertIsNone(response) @patch(PATH + "GithubService.check_request_state")