Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new create_fork arguments #2493

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 12 additions & 6 deletions github/AuthenticatedUser.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,18 +495,24 @@ def create_authorization(
self._requester, headers, data, completed=True
)

def create_fork(self, repo):
@staticmethod
def create_fork(
repo,
name=github.GithubObject.NotSet,
default_branch_only=github.GithubObject.NotSet,
):
"""
:calls: `POST /repos/{owner}/{repo}/forks <http://docs.github.com/en/rest/reference/repos#forks>`_
:param repo: :class:`github.Repository.Repository`
:param name: string
:param default_branch_only: bool
:rtype: :class:`github.Repository.Repository`
"""
assert isinstance(repo, github.Repository.Repository), repo
headers, data = self._requester.requestJsonAndCheck(
"POST", f"/repos/{repo.owner.login}/{repo.name}/forks"
)
return github.Repository.Repository(
self._requester, headers, data, completed=True
return repo.create_fork(
organization=github.GithubObject.NotSet,
name=name,
default_branch_only=default_branch_only,
)

def create_repo_from_template(
Expand Down
7 changes: 6 additions & 1 deletion github/AuthenticatedUser.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ class AuthenticatedUser(CompletableGithubObject):
client_secret: Union[str, _NotSetType] = ...,
onetime_password: Union[str, None] = ...,
) -> Authorization: ...
def create_fork(self, repo: Repository) -> Repository: ...
@staticmethod
def create_fork(
repo: Repository,
name: Union[str, _NotSetType] = ...,
default_branch_only: Union[str, _NotSetType] = ...,
) -> Repository: ...
def create_gist(
self,
public: bool,
Expand Down
23 changes: 12 additions & 11 deletions github/Organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,23 +384,24 @@ def add_to_public_members(self, public_member):
"PUT", f"{self.url}/public_members/{public_member._identity}"
)

def create_fork(self, repo):
def create_fork(
self,
repo,
name=github.GithubObject.NotSet,
default_branch_only=github.GithubObject.NotSet,
):
"""
:calls: `POST /repos/{owner}/{repo}/forks <https://docs.github.com/en/rest/reference/repos#forks>`_
:param repo: :class:`github.Repository.Repository`
:param name: string
:param default_branch_only: bool
:rtype: :class:`github.Repository.Repository`
"""
assert isinstance(repo, github.Repository.Repository), repo
url_parameters = {
"org": self.login,
}
headers, data = self._requester.requestJsonAndCheck(
"POST",
f"/repos/{repo.owner.login}/{repo.name}/forks",
parameters=url_parameters,
)
return github.Repository.Repository(
self._requester, headers, data, completed=True
return repo.create_fork(
self,
name=name,
default_branch_only=default_branch_only,
)

def create_repo_from_template(
Expand Down
7 changes: 6 additions & 1 deletion github/Organization.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ class Organization(CompletableGithubObject):
@property
def company(self) -> Optional[str]: ...
def convert_to_outside_collaborator(self, member: NamedUser) -> None: ...
def create_fork(self, repo: Repository) -> Repository: ...
def create_fork(
self,
repo: Repository,
name: Union[str, _NotSetType] = ...,
default_branch_only: Union[str, _NotSetType] = ...,
) -> Repository: ...
def create_hook(
self,
name: str,
Expand Down
17 changes: 16 additions & 1 deletion github/Repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -2419,10 +2419,17 @@ def get_forks(self):
Repository, self._requester, f"{self.url}/forks", None
)

def create_fork(self, organization=github.GithubObject.NotSet):
def create_fork(
self,
organization=github.GithubObject.NotSet,
name=github.GithubObject.NotSet,
default_branch_only=github.GithubObject.NotSet,
):
"""
:calls: `POST /repos/{owner}/{repo}/forks <https://docs.github.com/en/rest/reference/repos#forks>`_
:param organization: :class:`github.Organization.Organization` or string
:param name: string
:param default_branch_only: bool
:rtype: :class:`github.Repository.Repository`
"""
post_parameters = {}
Expand All @@ -2432,6 +2439,14 @@ def create_fork(self, organization=github.GithubObject.NotSet):
post_parameters["organization"] = organization
else:
assert organization is github.GithubObject.NotSet, organization
assert name is github.GithubObject.NotSet or isinstance(name, str), name
assert default_branch_only is github.GithubObject.NotSet or isinstance(
default_branch_only, bool
), default_branch_only
if name is not github.GithubObject.NotSet:
post_parameters["name"] = name
if default_branch_only is not github.GithubObject.NotSet:
post_parameters["default_branch_only"] = default_branch_only
headers, data = self._requester.requestJsonAndCheck(
"POST",
f"{self.url}/forks",
Expand Down
5 changes: 4 additions & 1 deletion github/Repository.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,10 @@ class Repository(CompletableGithubObject):
def get_events(self) -> PaginatedList[Event]: ...
def get_forks(self) -> PaginatedList[Repository]: ...
def create_fork(
self, organization: Union[Organization, str, _NotSetType] = ...
self,
organization: Union[Organization, str, _NotSetType] = ...,
name: Union[str, _NotSetType] = ...,
default_branch_only: Union[str, _NotSetType] = ...,
) -> Repository: ...
def get_git_blob(self, sha: str) -> GitBlob: ...
def get_git_commit(self, sha: str) -> GitCommit: ...
Expand Down
1 change: 1 addition & 0 deletions tests/Framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ def __readNextRequest(self, verb, url, input, headers):
if isinstance(input, str):
trInput = input.replace("\n", "").replace("\r", "")
if input.startswith("{"):
assert expectedInput.startswith("{"), expectedInput
assert json.loads(trInput) == json.loads(expectedInput)
else:
assert trInput == expectedInput
Expand Down
4 changes: 2 additions & 2 deletions tests/ReplayData/AuthenticatedUser.testCreateFork.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ POST
api.github.com
None
/repos/nvie/gitflow/forks
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
None
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Content-Type': 'application/json'}
{}
202
[('status', '202 Accepted'), ('x-ratelimit-remaining', '4958'), ('content-length', '3486'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"92f5b171559bccda47d7ebb598ba4f73"'), ('date', 'Sat, 26 May 2012 20:23:35 GMT'), ('content-type', 'application/json; charset=utf-8')]
{"parent":{"clone_url":"https://github.com/nvie/gitflow.git","has_downloads":true,"watchers":3973,"updated_at":"2012-05-26T20:23:35Z","master_branch":"develop","homepage":"http://nvie.com/posts/a-successful-git-branching-model/","url":"https://api.github.com/repos/nvie/gitflow","has_wiki":true,"has_issues":true,"fork":false,"forks":331,"size":4602,"private":false,"open_issues":92,"svn_url":"https://github.com/nvie/gitflow","owner":{"url":"https://api.github.com/users/nvie","avatar_url":"https://secure.gravatar.com/avatar/c5a7f21b46df698f3db31c37ed0cf55a?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"c5a7f21b46df698f3db31c37ed0cf55a","login":"nvie","id":83844},"name":"gitflow","language":"Shell","description":"Git extensions to provide high-level repository operations for Vincent Driessen's branching model.","ssh_url":"git@github.com:nvie/gitflow.git","git_url":"git://github.com/nvie/gitflow.git","pushed_at":"2012-02-14T13:11:04Z","created_at":"2010-01-20T23:14:12Z","id":481366,"mirror_url":null,"html_url":"https://github.com/nvie/gitflow","full_name":"nvie/gitflow"},"clone_url":"https://github.com/jacquev6/gitflow.git","has_downloads":true,"watchers":1,"updated_at":"2012-05-26T20:23:35Z","source":{"clone_url":"https://github.com/nvie/gitflow.git","has_downloads":true,"watchers":3973,"updated_at":"2012-05-26T20:23:35Z","master_branch":"develop","homepage":"http://nvie.com/posts/a-successful-git-branching-model/","url":"https://api.github.com/repos/nvie/gitflow","has_wiki":true,"has_issues":true,"fork":false,"forks":331,"size":4602,"private":false,"open_issues":92,"svn_url":"https://github.com/nvie/gitflow","owner":{"url":"https://api.github.com/users/nvie","avatar_url":"https://secure.gravatar.com/avatar/c5a7f21b46df698f3db31c37ed0cf55a?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"c5a7f21b46df698f3db31c37ed0cf55a","login":"nvie","id":83844},"name":"gitflow","language":"Shell","description":"Git extensions to provide high-level repository operations for Vincent Driessen's branching model.","ssh_url":"git@github.com:nvie/gitflow.git","git_url":"git://github.com/nvie/gitflow.git","pushed_at":"2012-02-14T13:11:04Z","created_at":"2010-01-20T23:14:12Z","id":481366,"mirror_url":null,"html_url":"https://github.com/nvie/gitflow","full_name":"nvie/gitflow"},"permissions":{"pull":true,"admin":true,"push":true},"master_branch":"develop","homepage":"http://nvie.com/posts/a-successful-git-branching-model/","url":"https://api.github.com/repos/jacquev6/gitflow","has_wiki":true,"has_issues":false,"fork":true,"forks":0,"size":4602,"private":false,"open_issues":0,"svn_url":"https://github.com/jacquev6/gitflow","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":"gitflow","language":"Shell","description":"Git extensions to provide high-level repository operations for Vincent Driessen's branching model.","ssh_url":"git@github.com:jacquev6/gitflow.git","git_url":"git://github.com/jacquev6/gitflow.git","pushed_at":"2012-02-14T13:11:04Z","created_at":"2012-05-26T20:23:35Z","id":4457584,"mirror_url":null,"html_url":"https://github.com/jacquev6/gitflow","full_name":"jacquev6/gitflow"}
Expand Down
6 changes: 3 additions & 3 deletions tests/ReplayData/Organization.testCreateFork.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ https
POST
api.github.com
None
/repos/jacquev6/PyGithub/forks?org=BeaverSoftware
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
None
/repos/jacquev6/PyGithub/forks
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Content-Type': 'application/json'}
{"organization": "BeaverSoftware"}
202
[('status', '202 Accepted'), ('x-ratelimit-remaining', '4965'), ('content-length', '3681'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"e4abc3ca2f8a9ccbe868ead57057a0e8"'), ('date', 'Sun, 27 May 2012 05:23:18 GMT'), ('content-type', 'application/json; charset=utf-8')]
{"parent":{"clone_url":"https://github.com/jacquev6/PyGithub.git","has_downloads":true,"watchers":15,"updated_at":"2012-05-27T05:23:18Z","homepage":"http://vincent-jacques.net/PyGithub","url":"https://api.github.com/repos/jacquev6/PyGithub","mirror_url":null,"has_wiki":false,"has_pages":false,"has_issues":true,"fork":false,"forks":3,"git_url":"git://github.com/jacquev6/PyGithub.git","size":348,"private":false,"open_issues":15,"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":"Python library implementing the full Github API v3","ssh_url":"git@github.com:jacquev6/PyGithub.git","pushed_at":"2012-05-26T20:54:13Z","created_at":"2012-02-25T12:53:47Z","id":3544490,"html_url":"https://github.com/jacquev6/PyGithub","full_name":"jacquev6/PyGithub"},"organization":{"url":"https://api.github.com/users/BeaverSoftware","avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","login":"BeaverSoftware","id":1424031},"clone_url":"https://github.com/BeaverSoftware/PyGithub.git","has_downloads":true,"watchers":1,"updated_at":"2012-05-27T05:23:18Z","source":{"clone_url":"https://github.com/jacquev6/PyGithub.git","has_downloads":true,"watchers":15,"updated_at":"2012-05-27T05:23:18Z","homepage":"http://vincent-jacques.net/PyGithub","url":"https://api.github.com/repos/jacquev6/PyGithub","mirror_url":null,"has_wiki":false,"has_pages":false,"has_issues":true,"fork":false,"forks":3,"git_url":"git://github.com/jacquev6/PyGithub.git","size":348,"private":false,"open_issues":15,"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":"Python library implementing the full Github API v3","ssh_url":"git@github.com:jacquev6/PyGithub.git","pushed_at":"2012-05-26T20:54:13Z","created_at":"2012-02-25T12:53:47Z","id":3544490,"html_url":"https://github.com/jacquev6/PyGithub","full_name":"jacquev6/PyGithub"},"permissions":{"pull":true,"admin":true,"push":true},"homepage":"http://vincent-jacques.net/PyGithub","url":"https://api.github.com/repos/BeaverSoftware/PyGithub","mirror_url":null,"has_wiki":false,"has_pages":false,"has_issues":false,"fork":true,"forks":0,"git_url":"git://github.com/BeaverSoftware/PyGithub.git","size":348,"private":false,"open_issues":0,"svn_url":"https://github.com/BeaverSoftware/PyGithub","owner":{"url":"https://api.github.com/users/BeaverSoftware","avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","login":"BeaverSoftware","id":1424031},"name":"PyGithub","language":"Python","description":"Python library implementing the full Github API v3","ssh_url":"git@github.com:BeaverSoftware/PyGithub.git","pushed_at":"2012-05-26T20:54:13Z","created_at":"2012-05-27T05:23:17Z","id":4460027,"html_url":"https://github.com/BeaverSoftware/PyGithub","full_name":"BeaverSoftware/PyGithub"}