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

Update Branch Protection to current GitHub API #790

Merged
merged 1 commit into from Aug 15, 2018

Conversation

s-t-e-v-e-n-k
Copy link
Collaborator

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.

@JPWKU
Copy link
Member

JPWKU commented May 14, 2018

@s-t-e-v-e-n-k I am reviewing, but will take a few hours at least.

@JPWKU JPWKU self-requested a review May 14, 2018 20:59
Copy link
Member

@JPWKU JPWKU left a 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:
Copy link
Member

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.

Copy link
Member

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.

Copy link
Collaborator Author

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):
Copy link
Member

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:
Copy link
Member

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?

Copy link
Collaborator Author

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):
Copy link
Member

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):
Copy link
Member

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):
Copy link
Member

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):
Copy link
Member

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):
Copy link
Member

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):
Copy link
Member

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):
Copy link
Member

Choose a reason for hiding this comment

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

+1

@JPWKU
Copy link
Member

JPWKU commented May 31, 2018

Circling back to this today..been a busy week.

@sfdye
Copy link
Member

sfdye commented Jun 4, 2018

Finally someone taking this up. Good job @s-t-e-v-e-n-k

@stale
Copy link

stale bot commented Aug 3, 2018

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.

@stale stale bot added the stale label Aug 3, 2018
@stale stale bot closed this Aug 10, 2018
@sfdye sfdye reopened this Aug 10, 2018
@stale stale bot removed the stale label Aug 10, 2018
@jiang-wei
Copy link

waiting for the merge for days ...

@sfdye
Copy link
Member

sfdye commented Aug 15, 2018

@JPWKU I really want to get this out. Do you have anything to add for the code review?

@JPWKU
Copy link
Member

JPWKU commented Aug 15, 2018

@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
@s-t-e-v-e-n-k
Copy link
Collaborator Author

@JPWKU Done! Let's get this merged! \o/

@sfdye
Copy link
Member

sfdye commented Aug 15, 2018

@JPWKU Any more comments?

@JPWKU
Copy link
Member

JPWKU commented Aug 15, 2018

Doing one last look through.

Copy link
Member

@JPWKU JPWKU left a comment

Choose a reason for hiding this comment

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

LGTM

@sfdye
Copy link
Member

sfdye commented Aug 15, 2018

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 😄

@JPWKU JPWKU merged commit a7c16c6 into PyGithub:master Aug 15, 2018
@s-t-e-v-e-n-k
Copy link
Collaborator Author

@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?

@sfdye
Copy link
Member

sfdye commented Aug 15, 2018

It's fine, I will reformat to release note style bullet points.

@sfdye
Copy link
Member

sfdye commented Aug 20, 2018

@s-t-e-v-e-n-k

I guess with this PR merged, Repository.get_protected_branch should also be removed right?

https://github.com/PyGithub/PyGithub/blob/080d807552718df5179e7998cc245e3bb9ea0262/github/Repository.py#L1314:L1325

@s-t-e-v-e-n-k
Copy link
Collaborator Author

@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.

@sfdye
Copy link
Member

sfdye commented Aug 20, 2018

Oh yeah, we can just remove it. I have issued a warning on the release note as well.

@s-t-e-v-e-n-k s-t-e-v-e-n-k deleted the branch-protection-update branch October 21, 2021 03:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants