Skip to content

Commit

Permalink
Merge pull request #50 from github/iterators
Browse files Browse the repository at this point in the history
fix iterator handling so issues don't get lost
  • Loading branch information
zkoppert authored Jul 18, 2023
2 parents 498ff4d + 9e6a57c commit ccc849a
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions issue_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def get_env_vars() -> tuple[str, str]:

def search_issues(
search_query: str, github_connection: github3.GitHub
) -> github3.structs.SearchIterator: # type: ignore
) -> List[github3.search.IssueSearchResult]: # type: ignore
"""
Searches for issues/prs/discussions in a GitHub repository that match
the given search query.
Expand All @@ -73,14 +73,16 @@ def search_issues(
github_connection (github3.GitHub): A connection to the GitHub API.
Returns:
github3.structs.SearchIterator: A list of issues that match the search query.
List[github3.search.IssueSearchResult]: A list of issues that match the search query.
"""
print("Searching for issues...")
issues = github_connection.search_issues(search_query)
issues_iterator = github_connection.search_issues(search_query, per_page=200)

# Print the issue titles
for issue in issues:
issues = []
for issue in issues_iterator:
print(issue.title) # type: ignore
issues.append(issue)

return issues

Expand All @@ -101,15 +103,15 @@ def auth_to_github() -> github3.GitHub:


def get_per_issue_metrics(
issues: Union[List[dict], List[github3.issues.Issue]], # type: ignore
issues: Union[List[dict], List[github3.search.IssueSearchResult]], # type: ignore
discussions: bool = False,
labels: Union[List[str], None] = None,
) -> tuple[List, int, int]:
"""
Calculate the metrics for each issue/pr/discussion in a list provided.
Args:
issues (Union[List[dict], List[github3.issues.Issue]]): A list of
issues (Union[List[dict], List[github3.search.IssueSearchResult]]): A list of
GitHub issues or discussions.
discussions (bool, optional): Whether the issues are discussions or not.
Defaults to False.
Expand Down Expand Up @@ -273,7 +275,7 @@ def main():
(ie. repo:owner/repo)"
)
issues = search_issues(search_query, github_connection)
if len(issues.items) <= 0:
if len(issues) <= 0:
print("No issues found")
write_to_markdown(None, None, None, None, None, None, None)
return
Expand Down

0 comments on commit ccc849a

Please sign in to comment.