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

Create from template #2012

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3f54ace
Add create_repo_from_template to Organization and AuthenticatedUser
isouza-daitan Feb 11, 2020
deea076
Fix create_repo_from_template docstring url
isouza-daitan Feb 11, 2020
a91899b
Add is_template attribute to Repository
isouza-daitan Feb 11, 2020
ed363bb
Add tests for the new create_repo_from_template method
isouza-daitan Feb 12, 2020
ec44a8b
Fix name assertion
isouza-daitan Feb 12, 2020
1aac6e9
fix flake8 violation
isouza-daitan Feb 13, 2020
1e4e605
refactor assertions
isouza-daitan Feb 13, 2020
a29b3c4
Revert scripts/add_attribute.py change
isouza-daitan Feb 13, 2020
b4f5991
Restore file delete by mistake
isouza-daitan Feb 13, 2020
d1c282e
Merge branch 'master' into create-from-template
isouza-daitan Feb 27, 2020
30e7100
Merge branch 'master' into create-from-template
isouza-daitan Mar 12, 2020
2c384f3
Merge branch 'master' into create-from-template
isouza-daitan Sep 29, 2020
0bfe56d
Merge branch 'create-from-template' of github.com:isouza-daitan/PyGit…
isouza-daitan Sep 29, 2020
a95e448
Fix formatting
isouza-daitan Sep 29, 2020
8fa9341
Add create_repo_from_template to Organization and AuthenticatedUser
simkimsia Jul 31, 2021
18c1d07
Fix create_repo_from_template docstring url
isouza-daitan Feb 11, 2020
476ee42
Add is_template attribute to Repository
isouza-daitan Feb 11, 2020
b018853
Add tests for the new create_repo_from_template method
isouza-daitan Feb 12, 2020
aca2570
Fix name assertion
isouza-daitan Feb 12, 2020
3b53479
fix flake8 violation
isouza-daitan Feb 13, 2020
ba76eff
refactor assertions
isouza-daitan Feb 13, 2020
f0372a9
Revert scripts/add_attribute.py change
simkimsia Jul 31, 2021
efb9dc2
Restore file delete by mistake
isouza-daitan Feb 13, 2020
d8c105c
Fix formatting
isouza-daitan Sep 29, 2020
e35e31d
Merge pull request #1 from isouza-daitan/create-from-template
simkimsia Sep 26, 2021
6ddabf7
♻ Changes based on feedback at PR
simkimsia Oct 21, 2021
652bdcc
Merge branch 'master' into create-from-template
simkimsia Oct 21, 2021
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
82 changes: 82 additions & 0 deletions github/AuthenticatedUser.py
Expand Up @@ -501,6 +501,88 @@ def create_fork(self, repo):
self._requester, headers, data, completed=True
)

def create_repo_from_template(
self,
name,
repo,
description=github.GithubObject.NotSet,
private=github.GithubObject.NotSet,
):
"""
:calls: `POST /repos/:template_owner/:template_repo/generate <https://developer.github.com/v3/repos/#create-repository-using-a-repository-template>`
:param name: string
:param repo :class:`github.Repository.Repository`
:param description: string
:param private: bool
:rtype: :class:`github.Repository.Repository`
"""
assert isinstance(name, str), name
assert isinstance(repo, github.Repository.Repository), repo
assert description is github.GithubObject.NotSet or isinstance(
description, str
), description
assert private is github.GithubObject.NotSet or isinstance(
private, bool
), private
post_parameters = {
"name": name,
"owner": self.login,
}
if description is not github.GithubObject.NotSet:
post_parameters["description"] = description
if private is not github.GithubObject.NotSet:
post_parameters["private"] = private
headers, data = self._requester.requestJsonAndCheck(
"POST",
"/repos/" + repo.owner.login + "/" + repo.name + "/generate",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use an f-string

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be resolved by 6ddabf7

input=post_parameters,
headers={"Accept": Consts.mediaTypeTemplatesPreview},
)
return github.Repository.Repository(
self._requester, headers, data, completed=True
)

def create_repo_from_template(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is duplicated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 6ddabf7

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also missing type hints for the new methods.

NOt too sure what this means. Can advise after my commit 6ddabf7

self,
name,
repo,
description=github.GithubObject.NotSet,
private=github.GithubObject.NotSet,
):
"""
:calls: `POST /repos/:template_owner/:template_repo/generate <https://developer.github.com/v3/repos/#create-repository-using-a-repository-template>`
:param name: string
:param repo :class:`github.Repository.Repository`
:param description: string
:param private: bool
:rtype: :class:`github.Repository.Repository`
"""
assert isinstance(name, str), name
assert isinstance(repo, github.Repository.Repository), repo
assert description is github.GithubObject.NotSet or isinstance(
description, str
), description
assert private is github.GithubObject.NotSet or isinstance(
private, bool
), private
post_parameters = {
"name": name,
"owner": self.login,
}
if description is not github.GithubObject.NotSet:
post_parameters["description"] = description
if private is not github.GithubObject.NotSet:
post_parameters["private"] = private
headers, data = self._requester.requestJsonAndCheck(
"POST",
"/repos/" + repo.owner.login + "/" + repo.name + "/generate",
input=post_parameters,
headers={"Accept": Consts.mediaTypeTemplatesPreview},
)
return github.Repository.Repository(
self._requester, headers, data, completed=True
)

def create_gist(self, public, files, description=github.GithubObject.NotSet):
"""
:calls: `POST /gists <http://docs.github.com/en/rest/reference/gists>`_
Expand Down
5 changes: 4 additions & 1 deletion github/Consts.py
Expand Up @@ -99,7 +99,10 @@
# https://developer.github.com/changes/2018-05-24-user-migration-api/
mediaTypeMigrationPreview = "application/vnd.github.wyandotte-preview+json"

# https://docs.github.com/en/rest/reference/search#highlighting-code-search-results-1
# https://developer.github.com/changes/2019-07-16-repository-templates-api/
mediaTypeTemplatesPreview = "application/vnd.github.baptiste-preview+json"

# https://developer.github.com/v3/search/#highlighting-code-search-results-1
highLightSearchPreview = "application/vnd.github.v3.text-match+json"

# https://developer.github.com/changes/2018-02-22-protected-branches-required-signatures/
Expand Down
41 changes: 41 additions & 0 deletions github/Organization.py
Expand Up @@ -403,6 +403,47 @@ def create_fork(self, repo):
self._requester, headers, data, completed=True
)

def create_repo_from_template(
self,
name,
repo,
description=github.GithubObject.NotSet,
private=github.GithubObject.NotSet,
):
"""self.name
:calls: `POST /repos/:template_owner/:template_repo/generate <https://developer.github.com/v3/repos/#create-repository-using-a-repository-template>`_
:param name: string
:param repo :class:`github.Repository.Repository`
:param description: string
:param private: bool
:rtype: :class:`github.Repository.Repository`
"""
assert isinstance(name, str), name
assert isinstance(repo, github.Repository.Repository), repo
assert description is github.GithubObject.NotSet or isinstance(
description, str
), description
assert private is github.GithubObject.NotSet or isinstance(
private, bool
), private
post_parameters = {
"name": name,
"owner": self.login,
}
if description is not github.GithubObject.NotSet:
post_parameters["description"] = description
if private is not github.GithubObject.NotSet:
post_parameters["private"] = private
headers, data = self._requester.requestJsonAndCheck(
"POST",
"/repos/" + repo.owner.login + "/" + repo.name + "/generate",
input=post_parameters,
headers={"Accept": Consts.mediaTypeTemplatesPreview},
)
return github.Repository.Repository(
self._requester, headers, data, completed=True
)

def create_hook(
self,
name,
Expand Down