Add required_linear_history attribute to BranchProtection (#2643)

Co-authored-by: Jacob Beard <jake@minnow.io>
Co-authored-by: Paul Melnikow <github@paulmelnikow.com>
This commit is contained in:
Enrico Minack
2023-07-18 14:26:35 +02:00
committed by GitHub
co-authored by Jacob Beard Paul Melnikow
parent 2edc0f8f17
commit 7a80fad9bb
4 changed files with 24 additions and 24 deletions
+8
View File
@@ -51,6 +51,7 @@ class BranchProtection(github.GithubObject.CompletableGithubObject):
self._url: Attribute[str] = NotSet
self._required_status_checks: Attribute[RequiredStatusChecks] = NotSet
self._enforce_admins: Attribute[bool] = NotSet
self._required_linear_history: Attribute[bool] = github.GithubObject.NotSet
self._required_pull_request_reviews: Attribute[RequiredPullRequestReviews] = NotSet
self._user_push_restrictions: Opt[str] = NotSet
self._team_push_restrictions: Opt[str] = NotSet
@@ -70,6 +71,11 @@ class BranchProtection(github.GithubObject.CompletableGithubObject):
self._completeIfNotSet(self._enforce_admins)
return self._enforce_admins.value
@property
def required_linear_history(self) -> bool:
self._completeIfNotSet(self._required_linear_history)
return self._required_linear_history.value
@property
def required_pull_request_reviews(self) -> RequiredPullRequestReviews:
self._completeIfNotSet(self._required_pull_request_reviews)
@@ -105,6 +111,8 @@ class BranchProtection(github.GithubObject.CompletableGithubObject):
github.RequiredPullRequestReviews.RequiredPullRequestReviews,
attributes["required_pull_request_reviews"],
)
if "required_linear_history" in attributes: # pragma no branch
self._required_linear_history = self._makeBoolAttribute(attributes["required_linear_history"]["enabled"])
if "restrictions" in attributes: # pragma no branch
self._user_push_restrictions = attributes["restrictions"]["users_url"]
self._team_push_restrictions = attributes["restrictions"]["teams_url"]
+1
View File
@@ -61,6 +61,7 @@ class Branch(Framework.TestCase):
self.assertTrue(branch_protection.required_status_checks.strict)
self.assertEqual(branch_protection.required_status_checks.contexts, [])
self.assertTrue(branch_protection.enforce_admins)
self.assertFalse(branch_protection.required_linear_history)
self.assertFalse(branch_protection.required_pull_request_reviews.dismiss_stale_reviews)
self.assertTrue(branch_protection.required_pull_request_reviews.require_code_owner_reviews)
self.assertEqual(
+5 -4
View File
@@ -26,16 +26,17 @@ from . import Framework
class BranchProtection(Framework.TestCase):
def setUp(self):
super().setUp()
self.branch_protection = self.g.get_user().get_repo("PyGithub").get_branch("integrations").get_protection()
self.branch_protection = self.g.get_repo("curvewise-forks/PyGithub").get_branch("master").get_protection()
def testAttributes(self):
self.assertTrue(self.branch_protection.required_status_checks.strict)
self.assertEqual(self.branch_protection.required_status_checks.contexts, ["foo/bar"])
self.assertEqual(self.branch_protection.required_status_checks.contexts, ["build (3.10)"])
self.assertTrue(self.branch_protection.required_linear_history)
self.assertEqual(
self.branch_protection.url,
"https://api.github.com/repos/jacquev6/PyGithub/branches/integrations/protection",
"https://api.github.com/repos/curvewise-forks/PyGithub/branches/master/protection",
)
self.assertEqual(
self.branch_protection.__repr__(),
'BranchProtection(url="https://api.github.com/repos/jacquev6/PyGithub/branches/integrations/protection")',
'BranchProtection(url="https://api.github.com/repos/curvewise-forks/PyGithub/branches/master/protection")',
)
File diff suppressed because one or more lines are too long