From 6c53e5442a80094025b390772d3e00a0d8443a75 Mon Sep 17 00:00:00 2001 From: Ibrahim Hussaini Date: Thu, 15 Dec 2022 14:05:02 +1100 Subject: [PATCH] feat: add allow_forking to Repository (#2380) * chore(dependency): flake8 has moved to github * feat: add allow_forking to Repository * chore: linting Co-authored-by: hussaiia --- .pre-commit-config.yaml | 2 +- github/Repository.py | 17 +++++++++++++++++ .../Repository.testEditWithAllArguments.txt | 4 ++-- tests/Repository.py | 2 ++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 48942775..17da8828 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,7 +11,7 @@ repos: rev: v5.10.1 hooks: - id: isort - - repo: https://gitlab.com/pycqa/flake8 + - repo: https://github.com/pycqa/flake8 rev: 3.9.2 hooks: - id: flake8 diff --git a/github/Repository.py b/github/Repository.py index 954dd767..25751006 100644 --- a/github/Repository.py +++ b/github/Repository.py @@ -158,6 +158,14 @@ class Repository(github.GithubObject.CompletableGithubObject): def __repr__(self): return self.get__repr__({"full_name": self._full_name.value}) + @property + def allow_forking(self): + """ + :type: bool + """ + self._completeIfNotSet(self._allow_forking) + return self._allow_forking.value + @property def allow_merge_commit(self): """ @@ -1552,6 +1560,7 @@ class Repository(github.GithubObject.CompletableGithubObject): has_wiki=github.GithubObject.NotSet, has_downloads=github.GithubObject.NotSet, default_branch=github.GithubObject.NotSet, + allow_forking=github.GithubObject.NotSet, allow_squash_merge=github.GithubObject.NotSet, allow_merge_commit=github.GithubObject.NotSet, allow_rebase_merge=github.GithubObject.NotSet, @@ -1603,6 +1612,9 @@ class Repository(github.GithubObject.CompletableGithubObject): assert default_branch is github.GithubObject.NotSet or isinstance( default_branch, str ), default_branch + assert allow_forking is github.GithubObject.NotSet or isinstance( + allow_forking, bool + ), allow_forking assert allow_squash_merge is github.GithubObject.NotSet or isinstance( allow_squash_merge, bool ), allow_squash_merge @@ -1639,6 +1651,8 @@ class Repository(github.GithubObject.CompletableGithubObject): post_parameters["default_branch"] = default_branch if allow_squash_merge is not github.GithubObject.NotSet: post_parameters["allow_squash_merge"] = allow_squash_merge + if allow_forking is not github.GithubObject.NotSet: + post_parameters["allow_forking"] = allow_forking if allow_merge_commit is not github.GithubObject.NotSet: post_parameters["allow_merge_commit"] = allow_merge_commit if allow_rebase_merge is not github.GithubObject.NotSet: @@ -3787,6 +3801,7 @@ class Repository(github.GithubObject.CompletableGithubObject): ) def _initAttributes(self): + self._allow_forking = github.GithubObject.NotSet self._allow_merge_commit = github.GithubObject.NotSet self._allow_rebase_merge = github.GithubObject.NotSet self._allow_squash_merge = github.GithubObject.NotSet @@ -3873,6 +3888,8 @@ class Repository(github.GithubObject.CompletableGithubObject): self._watchers_count = github.GithubObject.NotSet def _useAttributes(self, attributes): + if "allow_forking" in attributes: # pragma no branch + self._allow_forking = self._makeBoolAttribute(attributes["allow_forking"]) if "allow_merge_commit" in attributes: # pragma no branch self._allow_merge_commit = self._makeBoolAttribute( attributes["allow_merge_commit"] diff --git a/tests/ReplayData/Repository.testEditWithAllArguments.txt b/tests/ReplayData/Repository.testEditWithAllArguments.txt index 9e02090a..d0d1e36f 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_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_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_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_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 b34a1041..bd182bd3 100644 --- a/tests/Repository.py +++ b/tests/Repository.py @@ -134,6 +134,7 @@ class Repository(Framework.TestCase): has_projects=False, has_wiki=False, has_downloads=True, + allow_forking=True, allow_squash_merge=True, allow_merge_commit=True, allow_rebase_merge=True, @@ -149,6 +150,7 @@ class Repository(Framework.TestCase): self.assertFalse(self.repo.has_projects) self.assertFalse(self.repo.has_wiki) self.assertTrue(self.repo.has_downloads) + self.assertTrue(self.repo.allow_forking) self.assertTrue(self.repo.allow_squash_merge) self.assertTrue(self.repo.allow_merge_commit) self.assertTrue(self.repo.allow_rebase_merge)