-
Notifications
You must be signed in to change notification settings - Fork 48
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
Check for user write access (also, more speed and less code!) #222
base: main
Are you sure you want to change the base?
Conversation
This switches from [`Teams.ListTeams`](https://pkg.go.dev/github.com/google/go-github/v41/github#TeamsService.ListTeams) and potentially many calls of [`Teams.IsTeamRepoBySlug`](https://pkg.go.dev/github.com/google/go-github/v41/github#TeamsService.IsTeamRepoBySlug) to just a single [`Repositories.ListTeams`](https://pkg.go.dev/github.com/google/go-github/v41/github#RepositoriesService.ListTeams), which returns all the teams permissions to a specific repository. This does have the minor drawback of not being able to distinguish between teams not existing and teams not being in the organisation, but this does also have the benefit of potentially speeding up the result when there's many teams in the organisation.
For organizations with many members without write access (e.g. https://github.com/orgs/NixOS/people), this speeds up the user check by switching from [`Organizations.ListMembers`](https://pkg.go.dev/github.com/google/go-github/v41/github#OrganizationsService.ListMembers) to [`Repositories.ListCollaborators`](https://pkg.go.dev/github.com/google/go-github/v41/github#RepositoriesService.ListCollaborators). Furthermore, using `ListCollaborators` we can easily check that the users actually have write access to the repo, the same way as is done for teams since the parent commit.
We shouldn't use personal access tokens, instead we created a GitHub App with read-only access to just this repository. While codeowners-validator supports GitHub App authentication, the same cannot be said for the hacky script I wrote because there was no support for checking write access: mszostok/codeowners-validator#157 Instead of trying to hack the script more to make it work with GitHub App authentication, I decided to implement it into codeowners-validator itself: mszostok/codeowners-validator#222 Because it's not merged/released yet, we need to build it ourselves, so I added some Nix to do that reproducibly.
Just discovered that when using this with a GitHub App, it needs the "Repository/Administration/read-only" permission instead of the "Organization/Members/read-only" permission, see NixOS/org#9. So I guess this is a breaking change. I only updated the documentation for now, but I imagine more might be needed because of this. Edit: Needs to be updated to clarify Repository/Administration instead of Organization/Administration |
We shouldn't use personal access tokens, instead we created a GitHub App with read-only access to just this repository. While codeowners-validator supports GitHub App authentication, the same cannot be said for the hacky script I wrote because there was no support for checking write access: mszostok/codeowners-validator#157 Instead of trying to hack the script more to make it work with GitHub App authentication, I decided to implement it into codeowners-validator itself: mszostok/codeowners-validator#222 Because it's not merged/released yet, we need to build it ourselves, so I added some Nix to do that reproducibly.
74b5eca
to
840eeb8
Compare
We shouldn't use personal access tokens, instead we created a GitHub App with read-only access to just this repository. While codeowners-validator supports GitHub App authentication, the same cannot be said for the hacky script I wrote because there was no support for checking write access: mszostok/codeowners-validator#157 Instead of trying to hack the script more to make it work with GitHub App authentication, I decided to implement it into codeowners-validator itself: mszostok/codeowners-validator#222 Because it's not merged/released yet, we need to build it ourselves, so I added some Nix to do that reproducibly.
Description
This PR improves the
owners
check:README.md
documentation to mention thatSee the commits for more details.
Other than the locally runnable tests, I've also tested this minimally with an actual GitHub org repo
Related issue(s)
This work is sponsored by Antithesis ✨