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

Add support for triage and maintain permissions #294

Merged
merged 17 commits into from
May 10, 2021

Conversation

bluekeyes
Copy link
Member

Deprecate the admins and write_collaborators properties and replace them with a new permissions key that accepts all permission levels. Like before, users must specify levels explicitly and there is no permission inheritance (e.g. users with admin permissions do not count as having write permissions.)

The GitHub REST API does not expose the new permissions, so switch collaborator lookup to GraphQL, which does include them. This will remove caching of collaborator information, so we may need to revisit that to reduce request rates.

I still need to fix up reviewer assignment to work with the new fields. That's coming in a future commit.

Deprecate the "admins" and "write_collaborators" properties and replace
them with a new "permissions" key that accepts all permission levels.
Like before, users must specify levels explicitly and there is no
permission inheritance (e.g. users with admin permissions do not count
as having write permissions.)

The GitHub REST API does not expose the new permissions, so switch
collaborator lookup to GraphQL, which does include them. This will
remove caching of collaborator information, so we may need to revisit
that to reduce request rates.
pull/permission.go Outdated Show resolved Hide resolved
policy/common/actor.go Outdated Show resolved Hide resolved
This will always operate on the current pull request/repository and can
share cached data with RepositoryCollaborators() so there's no reason to
make it part of the membership/cross-org context.
policy/common/actor.go Outdated Show resolved Hide resolved
pull/github.go Outdated Show resolved Hide resolved
# A user must have a permission in this list for their approval to count for
# this rule. Valid permissions are "admin", "maintain", "write", "triage",
# and "read".
permissions: ["admin", "maintain", "write"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 this is much nicer.

pull/permission.go Outdated Show resolved Hide resolved
Rename RepositoryPermission to Permission and use it directly in the
YAML configuration. This avoids parsing later on and adds validation,
since the current validation logic really only checks that the YAML
parses cleanly.
This required quite a bit of API fiddling because the APIs here are
pretty inconsistent. I settled on a heuristic approach, but an alternate
method would be to make more API calls so that we:

1. List team permissions and then expand membership
2. List direct repository collaborators
3. Anything else must come from the org
This requires fixing up some tests which happened to work before because
write_collaborators did not work for teams. Also remove a test that was
only testing the mock pull.Context implementation.
Copy link
Member Author

@bluekeyes bluekeyes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It compiles and passes the existing tests now, but it still needs tests for the new functionality. I'm also not happy about how I worked around current GitHub API limits and may revisit that part.

pull/github.go Outdated Show resolved Hide resolved
Use additional API requests (probably 1 in practice) to get this
information more directly, instead of using heuristics based on API
misbehavior.
Only include results relevant to situation being tested to minimize
breaks when unrelated behavior changes.
@bluekeyes bluekeyes marked this pull request as ready for review May 6, 2021 20:19
@bluekeyes
Copy link
Member Author

Still need to do some more local testing, but this should be ready for review now. This ended up including a bit of refactoring for reviewer assignment that wasn't strictly necessary for the new permission types, but should make things more efficient when using teams as the request mode.

@bluekeyes bluekeyes requested a review from a team May 6, 2021 20:21
Started refactoring this in a previous commit and then never finished.
pull/github.go Outdated Show resolved Hide resolved
return nil
}

func selectUserReviewers(ctx context.Context, prctx pull.Context, selection *Selection, result *common.Result, r *rand.Rand) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function feels a lot more readable now, thanks for fixing it up.

// See the License for the specific language governing permissions and
// limitations under the License.

package pull
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would be nice to put this in its own package (instead of pull), maybe it would be useful in octo-correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given this is a pretty simple type and these two systems don't directly interact, I prefer copying this (or something similar) into other apps that need it rather than introducing a new dependency package or moving it into a common dependency like go-githubapp (where I feel it doesn't really fit with any existing functionality.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking maybe a package in policy-bot, but I think you're right.

pull/github.go Outdated Show resolved Hide resolved
I mistakenly assumed the "query" parameter was an exact match on user
name, but it's actually a substring filter. This means we need to
iterate over returned collaborators to find the one we want.
permissionsSources is apparently not available to GitHub Apps,
regardless of the app's permissions.
@bluekeyes
Copy link
Member Author

Ok, this should be set for final review now. Local testing looks good and I think I found all the API scorpions 🦂.

@asvoboda
Copy link
Member

👍 Lets try it out!

@bluekeyes bluekeyes merged commit 2d6b209 into develop May 10, 2021
@bluekeyes bluekeyes deleted the bkeyes/maintain-triage branch May 10, 2021 16:53
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

Successfully merging this pull request may close these issues.

None yet

3 participants