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

refactor: a helper for paged results #459

Merged
merged 1 commit into from
Nov 21, 2023
Merged
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
55 changes: 25 additions & 30 deletions edx_repo_tools/repo_checks/repo_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@
cache = lru_cache(maxsize=None)


def all_paged_items(func, *args, **kwargs):
"""
Get all items from a GhApi function returning paged results.
"""
return chain.from_iterable(paged(func, *args, per_page=100, **kwargs))


def is_security_private_fork(api, org, repo):
"""
Check to see if a specific repo is a private security fork.
Expand Down Expand Up @@ -373,14 +380,11 @@ def fix(self, dry_run=False):
)

# Check to see if a PR exists
prs = chain.from_iterable(
paged(
self.api.pulls.list,
owner=self.org_name,
repo=self.repo_name,
head=self.branch_name,
per_page=100,
)
prs = all_paged_items(
self.api.pulls.list,
owner=self.org_name,
repo=self.repo_name,
head=self.branch_name,
)

prs = [pr for pr in prs if pr.head.ref == self.branch_name]
Expand Down Expand Up @@ -438,13 +442,10 @@ def check(self):
"""
See if our labels exist.
"""
existing_labels_from_api = chain.from_iterable(
paged(
self.api.issues.list_labels_for_repo,
self.org_name,
self.repo_name,
per_page=100,
)
existing_labels_from_api = all_paged_items(
self.api.issues.list_labels_for_repo,
self.org_name,
self.repo_name,
)
existing_labels = {
self._simplify_label(label.name): {
Expand Down Expand Up @@ -555,13 +556,10 @@ def is_relevant(self):
raise NotImplementedError

def check(self):
teams = chain.from_iterable(
paged(
self.api.repos.list_teams,
self.org_name,
self.repo_name,
per_page=100,
)
teams = all_paged_items(
self.api.repos.list_teams,
self.org_name,
self.repo_name,
)

team_permissions = {team.slug: team.permission for team in teams}
Expand Down Expand Up @@ -943,14 +941,11 @@ def main(org, dry_run, _github_token, check_names, repos, start_at):
if not repos:
repos = [
repo.name
for repo in chain.from_iterable(
paged(
api.repos.list_for_org,
org,
sort="created",
direction="desc",
per_page=100,
)
for repo in all_paged_items(
api.repos.list_for_org,
org,
sort="created",
direction="desc",
)
]

Expand Down