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

Setting protection is broken with existing "restrict who can push" setup #1131

Open
ccotter opened this issue Feb 10, 2023 · 0 comments
Open

Comments

@ccotter
Copy link
Contributor

ccotter commented Feb 10, 2023

With v3.2.0, when a branch protection is setup on a branch with "Restrict who can push to matching branches" enabled with one or more users or team, and no other protections are enabled, then when attempting to add more protections, the github3 fails with

protection.update(required_pull_request_reviews={ ... })
  File "/home/ccotter/git/policy_bot/src/policy_bot.py", line 225, in validate_branch
    protection.update(required_pull_request_reviews={}, restrictions=restrictions)
  File "/home/ccotter/git/policy_bot/venv/lib/python3.10/site-packages/github3/decorators.py", line 24, in auth_wrapper
    return func(self, *args, **kwargs)
  File "/home/ccotter/git/policy_bot/venv/lib/python3.10/site-packages/github3/repos/branch.py", line 469, in update
    json = self._json(self._put(self._api, json=edit), 200)
  File "/home/ccotter/git/policy_bot/venv/lib/python3.10/site-packages/github3/models.py", line 161, in _json
    raise exceptions.error_for(response)
github3.exceptions.UnprocessableEntity: 422 Invalid request.

No subschema in "anyOf" matched.

(Note the line number from the github3 code are a bit off as I added some prints)

While github3 is creating the PUT HTTP request, it ends up inserting the the entire restrictions value from the original request that retrieved the restrictions, and the PUT request ends up containing an invalid payload. To fix, I think https://github.com/sigmavirus24/github3.py/blob/3.2.0/src/github3/repos/branch.py#L460 needs to extract out only the login name of each user, and the team name of each time. If I get a chance, I can submit a fix for this.

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