Check for user write access (also, more speed and less code!)#222
Open
infinisil wants to merge 4 commits intomszostok:mainfrom
Open
Check for user write access (also, more speed and less code!)#222infinisil wants to merge 4 commits intomszostok:mainfrom
infinisil wants to merge 4 commits intomszostok:mainfrom
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.
This was referenced Apr 25, 2024
infinisil
added a commit
to NixOS/org
that referenced
this pull request
Apr 26, 2024
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.
Author
|
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 |
infinisil
added a commit
to NixOS/org
that referenced
this pull request
Apr 26, 2024
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
infinisil
added a commit
to NixOS/org
that referenced
this pull request
Apr 26, 2024
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.
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR improves the
ownerscheck:README.mddocumentation 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 ✨