Replies: 3 comments 4 replies
-
Hi, there are no options to do pagination in a way to resume fetching resources from a certain offset (like for page 2 onward), but there is a way to have GitHub CLI do pagination for you. You can supply |
Beta Was this translation helpful? Give feedback.
-
Hello, using
|
Beta Was this translation helpful? Give feedback.
-
Please consider adding pagination, it would I need to reach for hacky scripts less often. Everything I've wanted gh-cli to do, I've had to end up reaching for a custom script, mainly because of pagination.
gh api graphql --paginate -f query='
query($endCursor: String) {
viewer {
repositories(first: 100, after: $endCursor) {
nodes { nameWithOwner }
pageInfo {
hasNextPage
endCursor
}
}
}
}
' Max results is 100 per page for example for example for repository list.
import os
from github import Github
# Loads GITHUB_ACCESS_TOKEN from the environment, or just set yours.
g = Github(os.environ.get("GITHUB_ACCESS_TOKEN"), per_page=100)
def list_repositories(user):
repos = []
try:
# Get the user by username
github_user = g.get_user(user)
# print(github_user.name)
# List all repositories (public and private)
for gh_repo in github_user.get_repos():
repos.append(gh_repo.full_name)
# to print as it adds it:
# print(gh_repo.full_name)
except Exception as e:
print(f"An error occurred: {e}")
return repos
if __name__ == "__main__":
# Replace 'username' with the GitHub username whose repositories you want to list
username = "yourname"
repositories = list_repositories(username)
# print(f"Repositories for {username}:")
for repo in repositories:
print(repo) |
Beta Was this translation helpful? Give feedback.
-
Hi,
It would be perfect to add the option of pagination since the maximum limit is 1000 and it is possible that there are more.
It would also be a good option if we want to make a query limiting it to 10 but we want to query the following 10
Beta Was this translation helpful? Give feedback.
All reactions