Branches protection preview API
The new GitHub v3 branches protection API has been updated. I implemented the current documented preview API (https://github.com/lsst-sqre/github3.py/pull/1).
Assuming there is interest I plan on PRing it after I've added tests. So is there interest? Any comments on the architecture? I tried to keep it similar to other modules in github3.py. It's pushed to pypi as sqre-github3.py. Though if anyone is planning on using it before it's PR'ed I should probably give it a more appropriate name like github3.py-branch-protection.
See Also
A series of GitHub Developer posts on the protected branches API.
https://developer.github.com/changes/2016-06-27-protected-branches-api-update/
https://developer.github.com/changes/2017-03-22-protected-branches-admin-improvements/
https://developer.github.com/changes/2017-04-11-protected-branch-dismissal-restrictions/
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
Looks like the GitHub v3 branches protection API are now stable.
https://developer.github.com/changes/2017-09-06-protected-branches-preview-end/
I've been using this patch and haven't run into any issue in my limited use case. I think it'd be nice to have the functionality in github3.py as well.
Hi folks, I've been investigating the same issue. What I've found that to update protected status of the branch one should use the following API, which has recently changed according to the Blog Post.
Although currently library is using a different endpoint which might be already deprecated.
@paulchubatyy I'd love to review a PR that fixes the current situation. The GitHub API moves too quickly for me to follow solely on my own. :smile:
I have some time to work on this over the next week. I'll see if I can implement any recent changes and some tests and PR it.
Yeah, I'm trying to figure it out how I make these changes. Seems like branch protection changed the HTTP method for setting it (from PATCH to PUT), I did the changes in my pull request and tried to validate that on the client (an app that uses this library to talk to github), but it's still failing. Pretty new to the project so it will take some time for me.
Basically the idea is the following:
- As branch protection is a separate endpoint I would consider creating separate model for it
branch.protectshould probably be using kwargs to pass to the branch protection endpoint so that we didn't have to change the library every time github adds/removes the data it expects on the endpoint.branch.unprotecton the other hand should be just sendingDELETEHTTP request to branch protection endpoint (as I understand from the documentation).
Please let me know if I'm on a right track and I will start working on the pull request to fix this issue on Monday.
I pushed 9dfbec8 with what little time I've had to hopefully help guide the development of these updates.
I think, perhaps, that we should remove branch.protect and branch.unprotect at some point in favour of having users do
protection_configuration = branch.protection()
protection_configuration.update(...)
protection_configuration.required_status_checks.add_contexts(...)
# etc.
Regarding using **kwargs, I think that is a pattern that exists nowhere else in this library. It makes the library harder to use by accepting anything, and it doesn't aid the maintainers by documenting what the acceptable parameters actually are. It's a pattern that I'd like to avoid at all costs.
@sigmavirus24 thanks for the commit. Indeed, once the object model is there for branch protection the mechanics of the implementation is very obvious.
Yeah I don't think **kwargs is required to implement this, but it's either that or some additional objects to represent all the configurations are required.
I implemented possible branch.protect and branch.unprotect already but they have changed quite a bit. So it makes sense to deprecate and eventually remove them. They were part of the initial preview implementation for branch protection but as features were added it got much more complicated.
I've already got this working, including a very similar object model to @sigmavirus24 at https://github.com/lsst-sqre/github3.py/pull/1. It just needs the luke-cage changes added.
Do you mind writing an example on how to protect a branch with the current implementation? it looks a little bit chaotic to figure out the right path here.
Thanks!
@pmatias it hasn't been implemented properly yet? That's happening in #815
That actually makes a lot of sense. Thanks Ian :)