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
Update Branch Protection to current GitHub API #790
Conversation
62ac94d
to
4f01121
Compare
@s-t-e-v-e-n-k I am reviewing, but will take a few hours at least. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chunking my review, I still have more to do. In general for cleanup can we wrap lines to no more than 72 chars.
else: | ||
post_parameters["enforce_admins"] = None | ||
|
||
if dismissal_users is not github.GithubObject.NotSet or dismissal_teams is not github.GithubObject.NotSet or dismiss_stale_reviews is not github.GithubObject.NotSet or require_code_owner_reviews is not github.GithubObject.NotSet: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrap at 72 characters for readablility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
required_approving_review_count
is a parameter available here for required_pull_request_reviews
object as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"The Protected Branches API now has a setting for requiring a specified number of approving pull request reviews before merging. This feature is currently available for developers to preview."
This requires sending a custom Accept header which the code doesn't do. I do plan to add it, but this branch was already large enough.
) | ||
return github.BranchProtection.BranchProtection(self._requester, headers, data, completed=True) | ||
|
||
def edit_protection(self, strict=github.GithubObject.NotSet, contexts=github.GithubObject.NotSet, enforce_admins=github.GithubObject.NotSet, dismissal_users=github.GithubObject.NotSet, dismissal_teams=github.GithubObject.NotSet, dismiss_stale_reviews=github.GithubObject.NotSet, require_code_owner_reviews=github.GithubObject.NotSet, user_push_restrictions=github.GithubObject.NotSet, team_push_restrictions=github.GithubObject.NotSet): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line wrap for readability.
post_parameters["required_pull_request_reviews"]["dismissal_restrictions"]["teams"] = dismissal_teams | ||
else: | ||
post_parameters["required_pull_request_reviews"] = None | ||
if user_push_restrictions is not github.GithubObject.NotSet or team_push_restrictions is not github.GithubObject.NotSet: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we can give meaningful feedback if a user tries to set team push restrictions on a repo that is not part of an org?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To my mind, the exception in itself is useful enough here -- that code is checked in the tests.
input=post_parameters | ||
) | ||
|
||
def remove_protection(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
input=post_parameters | ||
) | ||
|
||
def remove_required_status_checks(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
) | ||
return data["enabled"] | ||
|
||
def set_admin_enforcement(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
self.protection_url + "/enforce_admins" | ||
) | ||
|
||
def remove_admin_enforcement(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
self.protection_url + "/enforce_admins" | ||
) | ||
|
||
def get_user_push_restrictions(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
None | ||
) | ||
|
||
def get_team_push_restrictions(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
input=users | ||
) | ||
|
||
def edit_team_push_restrictions(self, *teams): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
Circling back to this today..been a busy week. |
Finally someone taking this up. Good job @s-t-e-v-e-n-k |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
waiting for the merge for days ... |
@JPWKU I really want to get this out. Do you have anything to add for the code review? |
@jiang-wei @sfdye I realize this has been in limbo for awhile. Just a combination of it being a large PR and having limited bandwidth to go over. Thanks for bringing it to the top again. @s-t-e-v-e-n-k Looks like there is a conflict, can you rebase and resolve that to see a test run again? |
The Branch protection API has been radically changed by GitHub, add new methods to Branch reflecting it. Branch protection methods are now called on the Branch object itself, rather than awkwardly hanging off the Repository object and requiring branch names to be passed in. This adds an over-arching methods to get, edit and remove protection entirely, as well as fine-grained methods for getting, setting and dropping certain aspects of branch protection, as well as three new objects to encompass querying those aspects. This also destroys Repository.protect_branch(), the endpoint has been removed. The old-style protection attributes on Branch have also been removed to force users onto the new API, since they are still sent, but no longer populated. Fixes PyGithub#586
4f01121
to
171cc56
Compare
@JPWKU Done! Let's get this merged! \o/ |
@JPWKU Any more comments? |
Doing one last look through. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
LGTM. @s-t-e-v-e-n-k Could you please add a summary for this PR, for the release note? I don't wanna miss anything 😄 |
@sfdye I think the following: "Add support for the Branch Protection API, which adds 12 new methods onto github.Branch allowing repository owners to set protection on any branch, such as user or team push restrictions, or requiring a number of reviewers before a PR can be merged." Is that enough, or do I need to go into more detail? |
It's fine, I will reformat to release note style bullet points. |
I guess with this PR merged, |
@sfdye I had a PR that was marked as stale that deprecated it, but this PR already adds a breaking change, so I'll push up a PR tonight that removes it. |
Oh yeah, we can just remove it. I have issued a warning on the release note as well. |
The Branch protection API has been radically changed by GitHub, add new
methods to Branch reflecting it. Branch protection methods are now
called on the Branch object itself, rather than awkwardly hanging off the
Repository object and requiring branch names to be passed in.
This adds an over-arching methods to get, edit and remove protection
entirely, as well as fine-grained methods for getting, setting and
dropping certain aspects of branch protection, as well as three new
objects to encompass querying those aspects.
This also destroys Repository.protect_branch(), the endpoint has been
removed. The old-style protection attributes on Branch have also been
removed to force users onto the new API, since they are still sent, but
no longer populated.
Fixes #586
--
I'm sorry for just how large this branch is. I tried to split it up, but everything depends on the new methods in Branch, which pretty much pulls in everything ever due to the tests.