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: issue accessing repo when not provided in query #291

Merged
merged 1 commit into from
May 24, 2024
Merged
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
4 changes: 3 additions & 1 deletion issue_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ def wait_for_api_refresh(iterator: github3.structs.SearchIterator):
issues = []
repos_and_owners_string = ""
for item in owners_and_repositories:
repos_and_owners_string += f"{item['owner']}/{item['repository']} "
repos_and_owners_string += (
f"{item.get('owner', '')}/{item.get('repository', '')} "
)

# Print the issue titles
try:
Expand Down
33 changes: 29 additions & 4 deletions test_issue_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ class TestSearchIssues(unittest.TestCase):
module to mock the GitHub API and test the function in isolation.

Methods:
test_search_issues: Test that search_issues returns the correct issues.
test_search_issues_with_owner_and_repository: Test that search_issues with owner/repo returns the correct issues.
test_search_issues_with_just_owner_or_org: Test that search_issues with just an owner/org returns the correct issues.

"""

def test_search_issues(self):
"""Test that search_issues returns the correct issues."""
def test_search_issues_with_owner_and_repository(self):
"""Test that search_issues with owner/repo returns the correct issues."""

# Set up the mock GitHub connection object
mock_issues = [
Expand All @@ -63,6 +64,30 @@ def test_search_issues(self):
issues = search_issues("is:open", mock_connection, owners_and_repositories)
self.assertEqual(issues, mock_issues)

def test_search_issues_with_just_owner_or_org(self):
"""Test that search_issues with just an owner/org returns the correct issues."""

# Set up the mock GitHub connection object
mock_issues = [
MagicMock(title="Issue 1"),
MagicMock(title="Issue 2"),
MagicMock(title="Issue 3"),
]

# simulating github3.structs.SearchIterator return value
mock_search_result = MagicMock()
mock_search_result.__iter__.return_value = iter(mock_issues)
mock_search_result.ratelimit_remaining = 30

mock_connection = MagicMock()
mock_connection.search_issues.return_value = mock_search_result

# Call search_issues and check that it returns the correct issues
org = {"owner": "org1"}
owners = [org]
issues = search_issues("is:open", mock_connection, owners)
self.assertEqual(issues, mock_issues)


class TestGetOwnerAndRepository(unittest.TestCase):
"""Unit tests for the get_owners_and_repositories function.
Expand All @@ -84,7 +109,7 @@ def test_get_owners_with_owner_and_repo_in_query(self):
self.assertEqual(result[0].get("owner"), "owner1")
self.assertEqual(result[0].get("repository"), "repo1")

def test_get_owner_and_repositories_with_repo_in_query(self):
def test_get_owner_and_repositories_without_repo_in_query(self):
"""Test get just owner."""
result = get_owners_and_repositories("org:owner1")
self.assertEqual(result[0].get("owner"), "owner1")
Expand Down
1 change: 1 addition & 0 deletions time_to_close.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def get_stats_time_to_close(

# Calculate the total time to close for all issues
close_times = []
total_time_to_close = None
if issues_with_time_to_close:
total_time_to_close = 0
for issue in issues_with_time_to_close:
Expand Down
Loading