Repository: PyGithub/PyGithub

Issue:
Support for create_fork in http://developer.github.com/v3/repos/forks
According to http://developer.github.com/v3/repos/forks

You can create a fork via a POST to the repositories /forks URL however this is not supported via PyGithub yet.


Discussion:

Resolving patch:
diff --git a/github/Repository.py b/github/Repository.py
--- a/github/Repository.py
+++ b/github/Repository.py
@@ -1867,6 +1867,23 @@ def get_forks(self):
             None
         )
 
+    def create_fork(self, organization=github.GithubObject.NotSet):
+        """
+        :calls: `POST /repos/:owner/:repo/forks <http://developer.github.com/v3/repos/forks>`_
+        :param organization: string or "none" or "*"
+        :rtype: :class:`github.Repository.Repository`
+        """
+        assert organization is github.GithubObject.NotSet or isinstance(organization, (str, six.text_type)), organization
+        post_parameters = {}
+        if organization is not None:
+            post_parameters["organization"] = organization
+        headers, data = self._requester.requestJsonAndCheck(
+            "POST",
+            self.url + "/forks",
+            input=post_parameters,
+        )
+        return Repository(self._requester, headers, data, completed=True)
+
     def get_git_blob(self, sha):
         """
         :calls: `GET /repos/:owner/:repo/git/blobs/:sha <http://developer.github.com/v3/git/blobs>`_


Test patch:
diff --git a/tests/ReplayData/Repository.testCreateFork.txt b/tests/ReplayData/Repository.testCreateFork.txt
new file mode 100644
--- /dev/null
+++ b/tests/ReplayData/Repository.testCreateFork.txt
@@ -0,0 +1,11 @@
+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
--- a/tests/Repository.py
+++ b/tests/Repository.py
@@ -370,6 +370,9 @@ def testGetEvents(self):
     def testGetForks(self):
         self.assertListKeyEqual(self.repo.get_forks(), lambda r: r.owner.login, ["abersager"])
 
+    def testCreateFork(self):
+        self.assertEqual(self.repo.create_fork("prtg-dev").full_name, "prtg-dev/PyGithub")
+
     def testGetGitRefs(self):
         self.assertListKeyEqual(self.repo.get_git_refs(), lambda r: r.ref, ["refs/heads/develop", "refs/heads/master", "refs/heads/topic/DependencyGraph", "refs/heads/topic/RewriteWithGeneratedCode", "refs/tags/v0.1", "refs/tags/v0.2", "refs/tags/v0.3", "refs/tags/v0.4", "refs/tags/v0.5", "refs/tags/v0.6", "refs/tags/v0.7"])