-
Notifications
You must be signed in to change notification settings - Fork 47
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
Open
infinisil
wants to merge
4
commits into
mszostok:main
Choose a base branch
from
tweag:simpler-faster-permission-check
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains 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
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:/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.
infinisil
changed the title
Simpler faster permission check
Check for user write access (also, more speed and less code!)
Apr 25, 2024
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.
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.
infinisil
force-pushed
the
simpler-faster-permission-check
branch
from
April 26, 2024 17:50
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
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
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 ✨