diff --git a/github/Repository.py b/github/Repository.py index 671a5aa87b..6b4af5a6e6 100644 --- a/github/Repository.py +++ b/github/Repository.py @@ -2325,15 +2325,16 @@ def get_forks(self): def create_fork(self, organization=github.GithubObject.NotSet): """ :calls: `POST /repos/{owner}/{repo}/forks `_ - :param organization: string or "none" or "*" + :param organization: :class:`github.Organization.Organization` or string :rtype: :class:`github.Repository.Repository` """ - assert organization is github.GithubObject.NotSet or isinstance( - organization, str - ), organization post_parameters = {} - if organization is not github.GithubObject.NotSet: + if isinstance(organization, github.Organization.Organization): + post_parameters["organization"] = organization.login + elif isinstance(organization, str): post_parameters["organization"] = organization + else: + assert organization is github.GithubObject.NotSet, organization headers, data = self._requester.requestJsonAndCheck( "POST", f"{self.url}/forks", diff --git a/github/Repository.pyi b/github/Repository.pyi index eb0dffdd14..53282ec56c 100644 --- a/github/Repository.pyi +++ b/github/Repository.pyi @@ -355,7 +355,7 @@ class Repository(CompletableGithubObject): def get_events(self) -> PaginatedList[Event]: ... def get_forks(self) -> PaginatedList[Repository]: ... def create_fork( - self, organization: Union[str, _NotSetType] = ... + self, organization: Union[Organization, str, _NotSetType] = ... ) -> Repository: ... def get_git_blob(self, sha: str) -> GitBlob: ... def get_git_commit(self, sha: str) -> GitCommit: ... diff --git a/tests/ReplayData/Repository.testCreateForkOrg.txt b/tests/ReplayData/Repository.testCreateForkOrg.txt new file mode 100644 index 0000000000..801997ae9b --- /dev/null +++ b/tests/ReplayData/Repository.testCreateForkOrg.txt @@ -0,0 +1,21 @@ +https +GET +api.github.com +None +/orgs/prtg-dev +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4960'), ('content-length', '928'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('date', 'Sat, 26 May 2012 20:23:33 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"login":"prtg-dev","id":54651306,"node_id":"MDEyOk9yZ2FuaXphdGlvbjU0NjUxMzA2","avatar_url":"https://avatars1.githubusercontent.com/u/54651306?v=4","gravatar_id":"","url":"https://api.github.com/users/prtg-dev","html_url":"https://github.com/prtg-dev","followers_url":"https://api.github.com/users/prtg-dev/followers","following_url":"https://api.github.com/users/prtg-dev/following{/other_user}","gists_url":"https://api.github.com/users/prtg-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/prtg-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prtg-dev/subscriptions","organizations_url":"https://api.github.com/users/prtg-dev/orgs","repos_url":"https://api.github.com/users/prtg-dev/repos","events_url":"https://api.github.com/users/prtg-dev/events{/privacy}","received_events_url":"https://api.github.com/users/prtg-dev/received_events","type":"Organization","site_admin":false} + +https +POST +api.github.com +None +/repos/jacquev6/PyGithub/forks +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Content-Type': 'application/json'} +{"organization": "prtg-dev"} +202 +[('Date', 'Wed, 27 Nov 2019 23:00:13 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Content-Length', '16034'), ('Server', 'GitHub.com'), ('Status', '202 Accepted'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4932'), ('X-RateLimit-Reset', '1574899126'), ('X-OAuth-Scopes', 'repo'), ('X-Accepted-OAuth-Scopes', ''), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('X-GitHub-Request-Id', 'E2F5:3ECF:1DE67F:229B58:5DDEFFFC')] +{"id":224531141,"node_id":"MDEwOlJlcG9zaXRvcnkyMjQ1MzExNDE=","name":"PyGithub","full_name":"prtg-dev/PyGithub","private":false,"owner":{"login":"prtg-dev","id":54651306,"node_id":"MDEyOk9yZ2FuaXphdGlvbjU0NjUxMzA2","avatar_url":"https://avatars1.githubusercontent.com/u/54651306?v=4","gravatar_id":"","url":"https://api.github.com/users/prtg-dev","html_url":"https://github.com/prtg-dev","followers_url":"https://api.github.com/users/prtg-dev/followers","following_url":"https://api.github.com/users/prtg-dev/following{/other_user}","gists_url":"https://api.github.com/users/prtg-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/prtg-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prtg-dev/subscriptions","organizations_url":"https://api.github.com/users/prtg-dev/orgs","repos_url":"https://api.github.com/users/prtg-dev/repos","events_url":"https://api.github.com/users/prtg-dev/events{/privacy}","received_events_url":"https://api.github.com/users/prtg-dev/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/prtg-dev/PyGithub","description":"Typed interactions with the GitHub API v3","fork":true,"url":"https://api.github.com/repos/prtg-dev/PyGithub","forks_url":"https://api.github.com/repos/prtg-dev/PyGithub/forks","keys_url":"https://api.github.com/repos/prtg-dev/PyGithub/keys{/key_id}","collaborators_url":"https://api.github.com/repos/prtg-dev/PyGithub/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/prtg-dev/PyGithub/teams","hooks_url":"https://api.github.com/repos/prtg-dev/PyGithub/hooks","issue_events_url":"https://api.github.com/repos/prtg-dev/PyGithub/issues/events{/number}","events_url":"https://api.github.com/repos/prtg-dev/PyGithub/events","assignees_url":"https://api.github.com/repos/prtg-dev/PyGithub/assignees{/user}","branches_url":"https://api.github.com/repos/prtg-dev/PyGithub/branches{/branch}","tags_url":"https://api.github.com/repos/prtg-dev/PyGithub/tags","blobs_url":"https://api.github.com/repos/prtg-dev/PyGithub/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/prtg-dev/PyGithub/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/prtg-dev/PyGithub/git/refs{/sha}","trees_url":"https://api.github.com/repos/prtg-dev/PyGithub/git/trees{/sha}","statuses_url":"https://api.github.com/repos/prtg-dev/PyGithub/statuses/{sha}","languages_url":"https://api.github.com/repos/prtg-dev/PyGithub/languages","stargazers_url":"https://api.github.com/repos/prtg-dev/PyGithub/stargazers","contributors_url":"https://api.github.com/repos/prtg-dev/PyGithub/contributors","subscribers_url":"https://api.github.com/repos/prtg-dev/PyGithub/subscribers","subscription_url":"https://api.github.com/repos/prtg-dev/PyGithub/subscription","commits_url":"https://api.github.com/repos/prtg-dev/PyGithub/commits{/sha}","git_commits_url":"https://api.github.com/repos/prtg-dev/PyGithub/git/commits{/sha}","comments_url":"https://api.github.com/repos/prtg-dev/PyGithub/comments{/number}","issue_comment_url":"https://api.github.com/repos/prtg-dev/PyGithub/issues/comments{/number}","contents_url":"https://api.github.com/repos/prtg-dev/PyGithub/contents/{+path}","compare_url":"https://api.github.com/repos/prtg-dev/PyGithub/compare/{base}...{head}","merges_url":"https://api.github.com/repos/prtg-dev/PyGithub/merges","archive_url":"https://api.github.com/repos/prtg-dev/PyGithub/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/prtg-dev/PyGithub/downloads","issues_url":"https://api.github.com/repos/prtg-dev/PyGithub/issues{/number}","pulls_url":"https://api.github.com/repos/prtg-dev/PyGithub/pulls{/number}","milestones_url":"https://api.github.com/repos/prtg-dev/PyGithub/milestones{/number}","notifications_url":"https://api.github.com/repos/prtg-dev/PyGithub/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/prtg-dev/PyGithub/labels{/name}","releases_url":"https://api.github.com/repos/prtg-dev/PyGithub/releases{/id}","deployments_url":"https://api.github.com/repos/prtg-dev/PyGithub/deployments","created_at":"2019-11-27T23:00:12Z","updated_at":"2019-11-26T22:54:53Z","pushed_at":"2019-11-27T22:40:33Z","git_url":"git://github.com/prtg-dev/PyGithub.git","ssh_url":"git@github.com:prtg-dev/PyGithub.git","clone_url":"https://github.com/prtg-dev/PyGithub.git","svn_url":"https://github.com/prtg-dev/PyGithub","homepage":"https://pygithub.readthedocs.io/","size":12092,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":0,"license":{"key":"lgpl-3.0","name":"GNU Lesser General Public License v3.0","spdx_id":"LGPL-3.0","url":"https://api.github.com/licenses/lgpl-3.0","node_id":"MDc6TGljZW5zZTEy"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master","permissions":{"admin":true,"push":true,"pull":true},"organization":{"login":"prtg-dev","id":54651306,"node_id":"MDEyOk9yZ2FuaXphdGlvbjU0NjUxMzA2","avatar_url":"https://avatars1.githubusercontent.com/u/54651306?v=4","gravatar_id":"","url":"https://api.github.com/users/prtg-dev","html_url":"https://github.com/prtg-dev","followers_url":"https://api.github.com/users/prtg-dev/followers","following_url":"https://api.github.com/users/prtg-dev/following{/other_user}","gists_url":"https://api.github.com/users/prtg-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/prtg-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prtg-dev/subscriptions","organizations_url":"https://api.github.com/users/prtg-dev/orgs","repos_url":"https://api.github.com/users/prtg-dev/repos","events_url":"https://api.github.com/users/prtg-dev/events{/privacy}","received_events_url":"https://api.github.com/users/prtg-dev/received_events","type":"Organization","site_admin":false},"parent":{"id":178836424,"node_id":"MDEwOlJlcG9zaXRvcnkxNzg4MzY0MjQ=","name":"PyGithub","full_name":"jacquev6/PyGithub","private":false,"owner":{"login":"jacquev6","id":47873678,"node_id":"MDQ6VXNlcjQ3ODczNjc4","avatar_url":"https://avatars1.githubusercontent.com/u/47873678?v=4","gravatar_id":"","url":"https://api.github.com/users/jacquev6","html_url":"https://github.com/jacquev6","followers_url":"https://api.github.com/users/jacquev6/followers","following_url":"https://api.github.com/users/jacquev6/following{/other_user}","gists_url":"https://api.github.com/users/jacquev6/gists{/gist_id}","starred_url":"https://api.github.com/users/jacquev6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacquev6/subscriptions","organizations_url":"https://api.github.com/users/jacquev6/orgs","repos_url":"https://api.github.com/users/jacquev6/repos","events_url":"https://api.github.com/users/jacquev6/events{/privacy}","received_events_url":"https://api.github.com/users/jacquev6/received_events","type":"User","site_admin":false},"html_url":"https://github.com/jacquev6/PyGithub","description":"Typed interactions with the GitHub API v3","fork":true,"url":"https://api.github.com/repos/jacquev6/PyGithub","forks_url":"https://api.github.com/repos/jacquev6/PyGithub/forks","keys_url":"https://api.github.com/repos/jacquev6/PyGithub/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jacquev6/PyGithub/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jacquev6/PyGithub/teams","hooks_url":"https://api.github.com/repos/jacquev6/PyGithub/hooks","issue_events_url":"https://api.github.com/repos/jacquev6/PyGithub/issues/events{/number}","events_url":"https://api.github.com/repos/jacquev6/PyGithub/events","assignees_url":"https://api.github.com/repos/jacquev6/PyGithub/assignees{/user}","branches_url":"https://api.github.com/repos/jacquev6/PyGithub/branches{/branch}","tags_url":"https://api.github.com/repos/jacquev6/PyGithub/tags","blobs_url":"https://api.github.com/repos/jacquev6/PyGithub/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jacquev6/PyGithub/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jacquev6/PyGithub/git/refs{/sha}","trees_url":"https://api.github.com/repos/jacquev6/PyGithub/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jacquev6/PyGithub/statuses/{sha}","languages_url":"https://api.github.com/repos/jacquev6/PyGithub/languages","stargazers_url":"https://api.github.com/repos/jacquev6/PyGithub/stargazers","contributors_url":"https://api.github.com/repos/jacquev6/PyGithub/contributors","subscribers_url":"https://api.github.com/repos/jacquev6/PyGithub/subscribers","subscription_url":"https://api.github.com/repos/jacquev6/PyGithub/subscription","commits_url":"https://api.github.com/repos/jacquev6/PyGithub/commits{/sha}","git_commits_url":"https://api.github.com/repos/jacquev6/PyGithub/git/commits{/sha}","comments_url":"https://api.github.com/repos/jacquev6/PyGithub/comments{/number}","issue_comment_url":"https://api.github.com/repos/jacquev6/PyGithub/issues/comments{/number}","contents_url":"https://api.github.com/repos/jacquev6/PyGithub/contents/{+path}","compare_url":"https://api.github.com/repos/jacquev6/PyGithub/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jacquev6/PyGithub/merges","archive_url":"https://api.github.com/repos/jacquev6/PyGithub/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jacquev6/PyGithub/downloads","issues_url":"https://api.github.com/repos/jacquev6/PyGithub/issues{/number}","pulls_url":"https://api.github.com/repos/jacquev6/PyGithub/pulls{/number}","milestones_url":"https://api.github.com/repos/jacquev6/PyGithub/milestones{/number}","notifications_url":"https://api.github.com/repos/jacquev6/PyGithub/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jacquev6/PyGithub/labels{/name}","releases_url":"https://api.github.com/repos/jacquev6/PyGithub/releases{/id}","deployments_url":"https://api.github.com/repos/jacquev6/PyGithub/deployments","created_at":"2019-04-01T10:06:27Z","updated_at":"2019-11-26T22:54:53Z","pushed_at":"2019-11-27T22:40:33Z","git_url":"git://github.com/jacquev6/PyGithub.git","ssh_url":"git@github.com:jacquev6/PyGithub.git","clone_url":"https://github.com/jacquev6/PyGithub.git","svn_url":"https://github.com/jacquev6/PyGithub","homepage":"https://pygithub.readthedocs.io/","size":12092,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":0,"license":{"key":"lgpl-3.0","name":"GNU Lesser General Public License v3.0","spdx_id":"LGPL-3.0","url":"https://api.github.com/licenses/lgpl-3.0","node_id":"MDc6TGljZW5zZTEy"},"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"},"source":{"id":3544490,"node_id":"MDEwOlJlcG9zaXRvcnkzNTQ0NDkw","name":"PyGithub","full_name":"PyGithub/PyGithub","private":false,"owner":{"login":"PyGithub","id":11288996,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExMjg4OTk2","avatar_url":"https://avatars0.githubusercontent.com/u/11288996?v=4","gravatar_id":"","url":"https://api.github.com/users/PyGithub","html_url":"https://github.com/PyGithub","followers_url":"https://api.github.com/users/PyGithub/followers","following_url":"https://api.github.com/users/PyGithub/following{/other_user}","gists_url":"https://api.github.com/users/PyGithub/gists{/gist_id}","starred_url":"https://api.github.com/users/PyGithub/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PyGithub/subscriptions","organizations_url":"https://api.github.com/users/PyGithub/orgs","repos_url":"https://api.github.com/users/PyGithub/repos","events_url":"https://api.github.com/users/PyGithub/events{/privacy}","received_events_url":"https://api.github.com/users/PyGithub/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/PyGithub/PyGithub","description":"Typed interactions with the GitHub API v3","fork":false,"url":"https://api.github.com/repos/PyGithub/PyGithub","forks_url":"https://api.github.com/repos/PyGithub/PyGithub/forks","keys_url":"https://api.github.com/repos/PyGithub/PyGithub/keys{/key_id}","collaborators_url":"https://api.github.com/repos/PyGithub/PyGithub/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/PyGithub/PyGithub/teams","hooks_url":"https://api.github.com/repos/PyGithub/PyGithub/hooks","issue_events_url":"https://api.github.com/repos/PyGithub/PyGithub/issues/events{/number}","events_url":"https://api.github.com/repos/PyGithub/PyGithub/events","assignees_url":"https://api.github.com/repos/PyGithub/PyGithub/assignees{/user}","branches_url":"https://api.github.com/repos/PyGithub/PyGithub/branches{/branch}","tags_url":"https://api.github.com/repos/PyGithub/PyGithub/tags","blobs_url":"https://api.github.com/repos/PyGithub/PyGithub/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/PyGithub/PyGithub/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/PyGithub/PyGithub/git/refs{/sha}","trees_url":"https://api.github.com/repos/PyGithub/PyGithub/git/trees{/sha}","statuses_url":"https://api.github.com/repos/PyGithub/PyGithub/statuses/{sha}","languages_url":"https://api.github.com/repos/PyGithub/PyGithub/languages","stargazers_url":"https://api.github.com/repos/PyGithub/PyGithub/stargazers","contributors_url":"https://api.github.com/repos/PyGithub/PyGithub/contributors","subscribers_url":"https://api.github.com/repos/PyGithub/PyGithub/subscribers","subscription_url":"https://api.github.com/repos/PyGithub/PyGithub/subscription","commits_url":"https://api.github.com/repos/PyGithub/PyGithub/commits{/sha}","git_commits_url":"https://api.github.com/repos/PyGithub/PyGithub/git/commits{/sha}","comments_url":"https://api.github.com/repos/PyGithub/PyGithub/comments{/number}","issue_comment_url":"https://api.github.com/repos/PyGithub/PyGithub/issues/comments{/number}","contents_url":"https://api.github.com/repos/PyGithub/PyGithub/contents/{+path}","compare_url":"https://api.github.com/repos/PyGithub/PyGithub/compare/{base}...{head}","merges_url":"https://api.github.com/repos/PyGithub/PyGithub/merges","archive_url":"https://api.github.com/repos/PyGithub/PyGithub/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/PyGithub/PyGithub/downloads","issues_url":"https://api.github.com/repos/PyGithub/PyGithub/issues{/number}","pulls_url":"https://api.github.com/repos/PyGithub/PyGithub/pulls{/number}","milestones_url":"https://api.github.com/repos/PyGithub/PyGithub/milestones{/number}","notifications_url":"https://api.github.com/repos/PyGithub/PyGithub/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/PyGithub/PyGithub/labels{/name}","releases_url":"https://api.github.com/repos/PyGithub/PyGithub/releases{/id}","deployments_url":"https://api.github.com/repos/PyGithub/PyGithub/deployments","created_at":"2012-02-25T12:53:47Z","updated_at":"2019-11-27T19:00:09Z","pushed_at":"2019-11-27T22:40:35Z","git_url":"git://github.com/PyGithub/PyGithub.git","ssh_url":"git@github.com:PyGithub/PyGithub.git","clone_url":"https://github.com/PyGithub/PyGithub.git","svn_url":"https://github.com/PyGithub/PyGithub","homepage":"https://pygithub.readthedocs.io/","size":12220,"stargazers_count":3016,"watchers_count":3016,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1001,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":57,"license":{"key":"lgpl-3.0","name":"GNU Lesser General Public License v3.0","spdx_id":"LGPL-3.0","url":"https://api.github.com/licenses/lgpl-3.0","node_id":"MDc6TGljZW5zZTEy"},"forks":1001,"open_issues":57,"watchers":3016,"default_branch":"master"},"network_count":1001,"subscribers_count":0} diff --git a/tests/Repository.py b/tests/Repository.py index 564b8b1146..6c39b63a8e 100644 --- a/tests/Repository.py +++ b/tests/Repository.py @@ -753,6 +753,10 @@ def testCreateFork(self): self.repo.create_fork("prtg-dev").full_name, "prtg-dev/PyGithub" ) + def testCreateForkOrg(self): + c = self.g.get_organization("prtg-dev") + self.assertEqual(self.repo.create_fork(c).full_name, "prtg-dev/PyGithub") + def testGetGitRefs(self): self.assertListKeyEqual( self.repo.get_git_refs(),