From bab4180fd571a5234c321953166dfadf3e69010c Mon Sep 17 00:00:00 2001 From: Felipe Peter Date: Tue, 9 May 2023 02:16:36 +0800 Subject: [PATCH] Add allow_update_branch option to Organization (#2465) --- github/Organization.py | 7 +++++++ github/Repository.py | 20 +++++++++++++++++++ tests/Organization.py | 2 ++ ...ization.testCreateRepoWithAllArguments.txt | 4 ++-- .../Repository.testEditWithAllArguments.txt | 4 ++-- tests/Repository.py | 2 ++ 6 files changed, 35 insertions(+), 4 deletions(-) diff --git a/github/Organization.py b/github/Organization.py index 723629d4..a63cc8e3 100644 --- a/github/Organization.py +++ b/github/Organization.py @@ -517,6 +517,7 @@ class Organization(github.GithubObject.CompletableGithubObject): allow_merge_commit=github.GithubObject.NotSet, allow_rebase_merge=github.GithubObject.NotSet, delete_branch_on_merge=github.GithubObject.NotSet, + allow_update_branch=github.GithubObject.NotSet, ): """ :calls: `POST /orgs/{org}/repos `_ @@ -536,6 +537,7 @@ class Organization(github.GithubObject.CompletableGithubObject): :param allow_merge_commit: bool :param allow_rebase_merge: bool :param delete_branch_on_merge: bool + :param allow_update_branch: bool :rtype: :class:`github.Repository.Repository` """ assert isinstance(name, str), name @@ -587,6 +589,9 @@ class Organization(github.GithubObject.CompletableGithubObject): assert delete_branch_on_merge is github.GithubObject.NotSet or isinstance( delete_branch_on_merge, bool ), delete_branch_on_merge + assert allow_update_branch is github.GithubObject.NotSet or isinstance( + allow_update_branch, bool + ), allow_update_branch post_parameters = { "name": name, } @@ -622,6 +627,8 @@ class Organization(github.GithubObject.CompletableGithubObject): post_parameters["allow_rebase_merge"] = allow_rebase_merge if delete_branch_on_merge is not github.GithubObject.NotSet: post_parameters["delete_branch_on_merge"] = delete_branch_on_merge + if allow_update_branch is not github.GithubObject.NotSet: + post_parameters["allow_update_branch"] = allow_update_branch headers, data = self._requester.requestJsonAndCheck( "POST", f"{self.url}/repos", diff --git a/github/Repository.py b/github/Repository.py index 23e86707..8a64a3bf 100644 --- a/github/Repository.py +++ b/github/Repository.py @@ -191,6 +191,14 @@ class Repository(github.GithubObject.CompletableGithubObject): self._completeIfNotSet(self._allow_squash_merge) return self._allow_squash_merge.value + @property + def allow_update_branch(self): + """ + :type: bool + """ + self._completeIfNotSet(self._allow_update_branch) + return self._allow_update_branch.value + @property def archived(self): """ @@ -1566,6 +1574,7 @@ class Repository(github.GithubObject.CompletableGithubObject): allow_merge_commit=github.GithubObject.NotSet, allow_rebase_merge=github.GithubObject.NotSet, delete_branch_on_merge=github.GithubObject.NotSet, + allow_update_branch=github.GithubObject.NotSet, archived=github.GithubObject.NotSet, ): """ @@ -1583,6 +1592,7 @@ class Repository(github.GithubObject.CompletableGithubObject): :param allow_merge_commit: bool :param allow_rebase_merge: bool :param delete_branch_on_merge: bool + :param allow_update_branch: bool :param archived: bool :rtype: None """ @@ -1628,6 +1638,9 @@ class Repository(github.GithubObject.CompletableGithubObject): assert delete_branch_on_merge is github.GithubObject.NotSet or isinstance( delete_branch_on_merge, bool ), delete_branch_on_merge + assert allow_update_branch is github.GithubObject.NotSet or isinstance( + allow_update_branch, bool + ), allow_update_branch assert archived is github.GithubObject.NotSet or isinstance( archived, bool ), archived @@ -1660,6 +1673,8 @@ class Repository(github.GithubObject.CompletableGithubObject): post_parameters["allow_rebase_merge"] = allow_rebase_merge if delete_branch_on_merge is not github.GithubObject.NotSet: post_parameters["delete_branch_on_merge"] = delete_branch_on_merge + if allow_update_branch is not github.GithubObject.NotSet: + post_parameters["allow_update_branch"] = allow_update_branch if archived is not github.GithubObject.NotSet: post_parameters["archived"] = archived headers, data = self._requester.requestJsonAndCheck( @@ -3823,6 +3838,7 @@ class Repository(github.GithubObject.CompletableGithubObject): self._allow_merge_commit = github.GithubObject.NotSet self._allow_rebase_merge = github.GithubObject.NotSet self._allow_squash_merge = github.GithubObject.NotSet + self._allow_update_branch = github.GithubObject.NotSet self._archived = github.GithubObject.NotSet self._archive_url = github.GithubObject.NotSet self._assignees_url = github.GithubObject.NotSet @@ -3920,6 +3936,10 @@ class Repository(github.GithubObject.CompletableGithubObject): self._allow_squash_merge = self._makeBoolAttribute( attributes["allow_squash_merge"] ) + if "allow_update_branch" in attributes: # pragma no branch + self._allow_update_branch = self._makeBoolAttribute( + attributes["allow_update_branch"] + ) if "archived" in attributes: # pragma no branch self._archived = self._makeBoolAttribute(attributes["archived"]) if "archive_url" in attributes: # pragma no branch diff --git a/tests/Organization.py b/tests/Organization.py index 18b711b1..25b5336d 100644 --- a/tests/Organization.py +++ b/tests/Organization.py @@ -328,6 +328,7 @@ class Organization(Framework.TestCase): has_wiki=False, has_downloads=False, team_id=team.id, + allow_update_branch=True, allow_squash_merge=False, allow_merge_commit=False, allow_rebase_merge=True, @@ -336,6 +337,7 @@ class Organization(Framework.TestCase): self.assertEqual( repo.url, "https://api.github.com/repos/BeaverSoftware/TestPyGithub2" ) + self.assertTrue(repo.allow_update_branch) self.assertFalse(repo.has_wiki) self.assertFalse(repo.has_pages) diff --git a/tests/ReplayData/Organization.testCreateRepoWithAllArguments.txt b/tests/ReplayData/Organization.testCreateRepoWithAllArguments.txt index 9d93ada8..1405fb3c 100644 --- a/tests/ReplayData/Organization.testCreateRepoWithAllArguments.txt +++ b/tests/ReplayData/Organization.testCreateRepoWithAllArguments.txt @@ -15,7 +15,7 @@ api.github.com None /orgs/BeaverSoftware/repos {'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Accept': 'application/vnd.github.nebula-preview+json'} -{"has_wiki": false, "name": "TestPyGithub2", "has_downloads": false, "private": false, "visibility": "public", "team_id": 141496, "has_issues": false, "homepage": "http://foobar.com", "description": "Repo created by PyGithub", "has_projects": false, "allow_squash_merge": false, "allow_merge_commit": false, "allow_rebase_merge": true, "delete_branch_on_merge": false} +{"has_wiki": false, "name": "TestPyGithub2", "has_downloads": false, "private": false, "visibility": "public", "team_id": 141496, "has_issues": false, "homepage": "http://foobar.com", "description": "Repo created by PyGithub", "has_projects": false, "allow_update_branch": true, "allow_squash_merge": false, "allow_merge_commit": false, "allow_rebase_merge": true, "delete_branch_on_merge": false} 201 [('status', '201 Created'), ('x-ratelimit-remaining', '4969'), ('content-length', '1501'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"feb513e01eaf8e89967068fe8ed44cc7"'), ('date', 'Sun, 27 May 2012 05:20:43 GMT'), ('content-type', 'application/json; charset=utf-8'), ('location', 'https://api.github.com/repos/BeaverSoftware/TestPyGithub2')] -{"organization":{"url":"https://api.github.com/users/BeaverSoftware","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png","login":"BeaverSoftware","id":1424031},"clone_url":"https://github.com/BeaverSoftware/TestPyGithub2.git","has_downloads":false,"watchers":1,"updated_at":"2012-05-27T05:20:42Z","permissions":{"pull":true,"admin":true,"push":true},"homepage":"http://foobar.com","url":"https://api.github.com/repos/BeaverSoftware/TestPyGithub2","mirror_url":null,"has_wiki":false,"has_pages":false,"has_issues":false,"fork":false,"forks":1,"size":0,"private":false,"open_issues":0,"svn_url":"https://github.com/BeaverSoftware/TestPyGithub2","owner":{"url":"https://api.github.com/users/BeaverSoftware","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png","login":"BeaverSoftware","id":1424031},"name":"TestPyGithub2","language":null,"description":"Repo created by PyGithub","ssh_url":"git@github.com:BeaverSoftware/TestPyGithub2.git","pushed_at":"2012-05-27T05:20:42Z","created_at":"2012-05-27T05:20:42Z","id":4460019,"git_url":"git://github.com/BeaverSoftware/TestPyGithub2.git","html_url":"https://github.com/BeaverSoftware/TestPyGithub2","full_name":"BeaverSoftware/TestPyGithub2", "has_projects": false, "allow_squash_merge": false, "allow_merge_commit": false, "allow_rebase_merge": true, "delete_branch_on_merge": false} +{"organization":{"url":"https://api.github.com/users/BeaverSoftware","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png","login":"BeaverSoftware","id":1424031},"clone_url":"https://github.com/BeaverSoftware/TestPyGithub2.git","has_downloads":false,"watchers":1,"updated_at":"2012-05-27T05:20:42Z","permissions":{"pull":true,"admin":true,"push":true},"homepage":"http://foobar.com","url":"https://api.github.com/repos/BeaverSoftware/TestPyGithub2","mirror_url":null,"has_wiki":false,"has_pages":false,"has_issues":false,"fork":false,"forks":1,"size":0,"private":false,"open_issues":0,"svn_url":"https://github.com/BeaverSoftware/TestPyGithub2","owner":{"url":"https://api.github.com/users/BeaverSoftware","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png","login":"BeaverSoftware","id":1424031},"name":"TestPyGithub2","language":null,"description":"Repo created by PyGithub","ssh_url":"git@github.com:BeaverSoftware/TestPyGithub2.git","pushed_at":"2012-05-27T05:20:42Z","created_at":"2012-05-27T05:20:42Z","id":4460019,"git_url":"git://github.com/BeaverSoftware/TestPyGithub2.git","html_url":"https://github.com/BeaverSoftware/TestPyGithub2","full_name":"BeaverSoftware/TestPyGithub2", "has_projects": false, "allow_update_branch": true, "allow_squash_merge": false, "allow_merge_commit": false, "allow_rebase_merge": true, "delete_branch_on_merge": false} diff --git a/tests/ReplayData/Repository.testEditWithAllArguments.txt b/tests/ReplayData/Repository.testEditWithAllArguments.txt index d0d1e36f..57eec6aa 100644 --- a/tests/ReplayData/Repository.testEditWithAllArguments.txt +++ b/tests/ReplayData/Repository.testEditWithAllArguments.txt @@ -4,10 +4,10 @@ api.github.com None /repos/jacquev6/PyGithub {'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} -{"has_wiki": false, "name": "PyGithub", "has_downloads": true, "has_issues": true, "homepage": "http://vincent-jacques.net/PyGithub", "private": true, "description": "Description edited by PyGithub", "has_projects": false, "allow_forking": true, "allow_squash_merge": true, "allow_merge_commit": true, "allow_rebase_merge": true, "delete_branch_on_merge": true} +{"has_wiki": false, "name": "PyGithub", "has_downloads": true, "has_issues": true, "homepage": "http://vincent-jacques.net/PyGithub", "private": true, "description": "Description edited by PyGithub", "has_projects": false, "allow_update_branch": true, "allow_forking": true, "allow_squash_merge": true, "allow_merge_commit": true, "allow_rebase_merge": true, "delete_branch_on_merge": true} 200 [('status', '200 OK'), ('x-ratelimit-remaining', '4953'), ('content-length', '1109'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"749313ec2d171323deb61f9f4c85e84f"'), ('date', 'Sat, 26 May 2012 11:22:13 GMT'), ('content-type', 'application/json; charset=utf-8')] -{"clone_url":"https://github.com/jacquev6/PyGithub.git","has_downloads":true,"watchers":13,"updated_at":"2012-05-26T11:22:13Z","permissions":{"pull":true,"admin":true,"push":true},"homepage":"http://vincent-jacques.net/PyGithub","url":"https://api.github.com/repos/jacquev6/PyGithub","has_wiki":false,"has_issues":true,"fork":false,"forks":2,"size":412,"git_url":"git://github.com/jacquev6/PyGithub.git","private":false,"open_issues":16,"mirror_url":null,"svn_url":"https://github.com/jacquev6/PyGithub","owner":{"url":"https://api.github.com/users/jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146},"name":"PyGithub","language":"Python","description":"Description edited by PyGithub","ssh_url":"git@github.com:jacquev6/PyGithub.git","pushed_at":"2012-05-26T10:01:38Z","created_at":"2012-02-25T12:53:47Z","id":3544490,"html_url":"https://github.com/jacquev6/PyGithub","full_name":"jacquev6/PyGithub", "has_projects": false, "allow_forking": true, "allow_squash_merge": true, "allow_merge_commit": true, "allow_rebase_merge": true, "delete_branch_on_merge": true} +{"clone_url":"https://github.com/jacquev6/PyGithub.git","has_downloads":true,"watchers":13,"updated_at":"2012-05-26T11:22:13Z","permissions":{"pull":true,"admin":true,"push":true},"homepage":"http://vincent-jacques.net/PyGithub","url":"https://api.github.com/repos/jacquev6/PyGithub","has_wiki":false,"has_issues":true,"fork":false,"forks":2,"size":412,"git_url":"git://github.com/jacquev6/PyGithub.git","private":false,"open_issues":16,"mirror_url":null,"svn_url":"https://github.com/jacquev6/PyGithub","owner":{"url":"https://api.github.com/users/jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146},"name":"PyGithub","language":"Python","description":"Description edited by PyGithub","ssh_url":"git@github.com:jacquev6/PyGithub.git","pushed_at":"2012-05-26T10:01:38Z","created_at":"2012-02-25T12:53:47Z","id":3544490,"html_url":"https://github.com/jacquev6/PyGithub","full_name":"jacquev6/PyGithub", "has_projects": false, "allow_update_branch": true, "allow_forking": true, "allow_squash_merge": true, "allow_merge_commit": true, "allow_rebase_merge": true, "delete_branch_on_merge": true} https PATCH diff --git a/tests/Repository.py b/tests/Repository.py index bd182bd3..1f999c1d 100644 --- a/tests/Repository.py +++ b/tests/Repository.py @@ -135,6 +135,7 @@ class Repository(Framework.TestCase): has_wiki=False, has_downloads=True, allow_forking=True, + allow_update_branch=True, allow_squash_merge=True, allow_merge_commit=True, allow_rebase_merge=True, @@ -146,6 +147,7 @@ class Repository(Framework.TestCase): self.repo.description, "Python library implementing the full Github API v3" ) self.assertFalse(self.repo.archived) + self.assertTrue(self.repo.allow_update_branch) self.assertTrue(self.repo.has_issues) self.assertFalse(self.repo.has_projects) self.assertFalse(self.repo.has_wiki)