mirror of
https://github.com/status-im/PyGithub.git
synced 2026-09-02 03:41:08 +00:00
Update Branch Protection to current GitHub API
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
This commit is contained in:
@@ -2468,37 +2468,6 @@ class Repository(github.GithubObject.CompletableGithubObject):
|
||||
else:
|
||||
return github.Commit.Commit(self._requester, headers, data, completed=True)
|
||||
|
||||
def protect_branch(self, branch, enabled, enforcement_level=github.GithubObject.NotSet, contexts=github.GithubObject.NotSet):
|
||||
"""
|
||||
:calls: `PATCH /repos/:owner/:repo/branches/:branch <https://developer.github.com/v3/repos/#enabling-and-disabling-branch-protection>`_
|
||||
:param branch: string
|
||||
:param enabled: boolean
|
||||
:param enforcement_level: string
|
||||
:param contexts: list of strings
|
||||
:rtype: None
|
||||
"""
|
||||
|
||||
assert isinstance(branch, (str, unicode))
|
||||
assert isinstance(enabled, bool)
|
||||
assert enforcement_level is github.GithubObject.NotSet or isinstance(enforcement_level, (str, unicode)), enforcement_level
|
||||
assert contexts is github.GithubObject.NotSet or all(isinstance(element, (str, unicode)) or isinstance(element, (str, unicode)) for element in contexts), contexts
|
||||
|
||||
post_parameters = {
|
||||
"protection": {}
|
||||
}
|
||||
if enabled is not github.GithubObject.NotSet:
|
||||
post_parameters["protection"]["enabled"] = enabled
|
||||
if enforcement_level is not github.GithubObject.NotSet:
|
||||
post_parameters["protection"]["required_status_checks"] = {}
|
||||
post_parameters["protection"]["required_status_checks"]["enforcement_level"] = enforcement_level
|
||||
if contexts is not github.GithubObject.NotSet:
|
||||
post_parameters["protection"]["required_status_checks"]["contexts"] = contexts
|
||||
headers, data = self._requester.requestJsonAndCheck(
|
||||
"PATCH",
|
||||
self.url + "/branches/" + branch,
|
||||
input=post_parameters
|
||||
)
|
||||
|
||||
def replace_topics(self, topics):
|
||||
"""
|
||||
:calls: `PUT /repos/:owner/:repo/topics <http://developer.github.com/v3/repos>`_
|
||||
|
||||
Reference in New Issue
Block a user