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

Updater does not work for GitHub users #2

Open
Mr-Pepe opened this issue Jan 6, 2024 · 0 comments
Open

Updater does not work for GitHub users #2

Mr-Pepe opened this issue Jan 6, 2024 · 0 comments

Comments

@Mr-Pepe
Copy link
Contributor

Mr-Pepe commented Jan 6, 2024

Trying to test #1, I realized that the updater currently only works for actual GitHub organizations and not for users.

There are two ways of supporting GitHub users.

The CLI argument github_organization could be renamed to github_organization_or_user and the repositories could be retrieved like this:

try:
    repos = Github(github_access_token).get_organization(github_organization_or_user).get_repos()
except UnknownObjectException:
    repos = Github(github_access_token).get_user(github_organization_or_user).get_repos()

However, this only retrieves a user's public repositories and the REST API that backs this specific PyGithub functionality does not provide a way to list private repositories.

The second way is to turn the github_organization argument into an option and doing this:

# Turn `github_organization` into an option

if github_organization:
    repos = Github(github_access_token).get_organization(github_organization).get_repos()
else:
    repos = Github(github_access_token).get_user().get_repos(affiliation="owner")

Not providing a user name for Github(github_access_token).get_user() retrieves the user authenticated by the token. Calling get_repos() on that user retrieves private repositories but also includes all repositories of organizations the user is a member of. This can be controlled by the affiliation parameter of get_repos to only retrieve repositories owned by the user.

I think the second option is preferable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant