Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix out of range error from totalCount #127

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion reviewrot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 10 additions & 2 deletions reviewrot/githubstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion reviewrot/pagurestack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 6 additions & 4 deletions test/github_tests/mock_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions test/github_tests/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down