From f80df9e429659ecd49ddd1d19f9bfa364f1a9cad Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Sat, 3 Nov 2012 10:06:52 +0100 Subject: [PATCH] Add auto_init and gitignore_template to create_repo (issue #106) http://developer.github.com/changes/2012-9-28-auto-init-for-repositories/ --- doc/ReferenceOfClasses.md | 8 ++++++-- github/AuthenticatedUser.py | 8 +++++++- github/Organization.py | 8 +++++++- github/tests/AuthenticatedUser.py | 4 ++++ github/tests/Organization.py | 4 ++++ ...AuthenticatedUser.testCreateRepositoryWithAutoInit.txt | 5 +++++ .../Organization.testCreateRepositoryWithAutoInit.txt | 5 +++++ 7 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 github/tests/ReplayData/AuthenticatedUser.testCreateRepositoryWithAutoInit.txt create mode 100644 github/tests/ReplayData/Organization.testCreateRepositoryWithAutoInit.txt diff --git a/doc/ReferenceOfClasses.md b/doc/ReferenceOfClasses.md index 930153b2..048354cc 100644 --- a/doc/ReferenceOfClasses.md +++ b/doc/ReferenceOfClasses.md @@ -170,7 +170,7 @@ Orgs Repos ----- -* `create_repo( name, [description, homepage, private, has_issues, has_wiki, has_downloads] )`: `Repository` +* `create_repo( name, [description, homepage, private, has_issues, has_wiki, has_downloads, auto_init, gitignore_template] )`: `Repository` * `name`: string * `description`: string * `homepage`: string @@ -178,6 +178,8 @@ Repos * `has_issues`: bool * `has_wiki`: bool * `has_downloads`: bool + * `auto_init`: bool + * `gitignore_template`: string * `get_repo( name )`: `Repository` * `name`: string * `get_repos( [type, sort, direction] )`: `PaginatedList` of `Repository` @@ -965,7 +967,7 @@ Public_members Repos ----- -* `create_repo( name, [description, homepage, private, has_issues, has_wiki, has_downloads, team_id] )`: `Repository` +* `create_repo( name, [description, homepage, private, has_issues, has_wiki, has_downloads, team_id, auto_init, gitignore_template] )`: `Repository` * `name`: string * `description`: string * `homepage`: string @@ -974,6 +976,8 @@ Repos * `has_wiki`: bool * `has_downloads`: bool * `team_id`: `Team` + * `auto_init`: bool + * `gitignore_template`: string * `get_repo( name )`: `Repository` * `name`: string * `get_repos( [type] )`: `PaginatedList` of `Repository` diff --git a/github/AuthenticatedUser.py b/github/AuthenticatedUser.py index 9be73ea9..f131d625 100644 --- a/github/AuthenticatedUser.py +++ b/github/AuthenticatedUser.py @@ -262,7 +262,7 @@ class AuthenticatedUser(GithubObject.GithubObject): ) return UserKey.UserKey(self._requester, data, completed=True) - def create_repo(self, name, description=GithubObject.NotSet, homepage=GithubObject.NotSet, private=GithubObject.NotSet, has_issues=GithubObject.NotSet, has_wiki=GithubObject.NotSet, has_downloads=GithubObject.NotSet): + def create_repo(self, name, description=GithubObject.NotSet, homepage=GithubObject.NotSet, private=GithubObject.NotSet, has_issues=GithubObject.NotSet, has_wiki=GithubObject.NotSet, has_downloads=GithubObject.NotSet, auto_init=GithubObject.NotSet, gitignore_template=GithubObject.NotSet): assert isinstance(name, (str, unicode)), name assert description is GithubObject.NotSet or isinstance(description, (str, unicode)), description assert homepage is GithubObject.NotSet or isinstance(homepage, (str, unicode)), homepage @@ -270,6 +270,8 @@ class AuthenticatedUser(GithubObject.GithubObject): assert has_issues is GithubObject.NotSet or isinstance(has_issues, bool), has_issues assert has_wiki is GithubObject.NotSet or isinstance(has_wiki, bool), has_wiki assert has_downloads is GithubObject.NotSet or isinstance(has_downloads, bool), has_downloads + assert auto_init is GithubObject.NotSet or isinstance(auto_init, bool), auto_init + assert gitignore_template is GithubObject.NotSet or isinstance(gitignore_template, (str, unicode)), gitignore_template post_parameters = { "name": name, } @@ -285,6 +287,10 @@ class AuthenticatedUser(GithubObject.GithubObject): post_parameters["has_wiki"] = has_wiki if has_downloads is not GithubObject.NotSet: post_parameters["has_downloads"] = has_downloads + if auto_init is not GithubObject.NotSet: + post_parameters["auto_init"] = auto_init + if gitignore_template is not GithubObject.NotSet: + post_parameters["gitignore_template"] = gitignore_template headers, data = self._requester.requestAndCheck( "POST", "/user/repos", diff --git a/github/Organization.py b/github/Organization.py index ab724a89..a64134fc 100644 --- a/github/Organization.py +++ b/github/Organization.py @@ -166,7 +166,7 @@ class Organization(GithubObject.GithubObject): ) return Repository.Repository(self._requester, data, completed=True) - def create_repo(self, name, description=GithubObject.NotSet, homepage=GithubObject.NotSet, private=GithubObject.NotSet, has_issues=GithubObject.NotSet, has_wiki=GithubObject.NotSet, has_downloads=GithubObject.NotSet, team_id=GithubObject.NotSet): + def create_repo(self, name, description=GithubObject.NotSet, homepage=GithubObject.NotSet, private=GithubObject.NotSet, has_issues=GithubObject.NotSet, has_wiki=GithubObject.NotSet, has_downloads=GithubObject.NotSet, team_id=GithubObject.NotSet, auto_init=GithubObject.NotSet, gitignore_template=GithubObject.NotSet): assert isinstance(name, (str, unicode)), name assert description is GithubObject.NotSet or isinstance(description, (str, unicode)), description assert homepage is GithubObject.NotSet or isinstance(homepage, (str, unicode)), homepage @@ -175,6 +175,8 @@ class Organization(GithubObject.GithubObject): assert has_wiki is GithubObject.NotSet or isinstance(has_wiki, bool), has_wiki assert has_downloads is GithubObject.NotSet or isinstance(has_downloads, bool), has_downloads assert team_id is GithubObject.NotSet or isinstance(team_id, Team.Team), team_id + assert auto_init is GithubObject.NotSet or isinstance(auto_init, bool), auto_init + assert gitignore_template is GithubObject.NotSet or isinstance(gitignore_template, (str, unicode)), gitignore_template post_parameters = { "name": name, } @@ -192,6 +194,10 @@ class Organization(GithubObject.GithubObject): post_parameters["has_downloads"] = has_downloads if team_id is not GithubObject.NotSet: post_parameters["team_id"] = team_id._identity + if auto_init is not GithubObject.NotSet: + post_parameters["auto_init"] = auto_init + if gitignore_template is not GithubObject.NotSet: + post_parameters["gitignore_template"] = gitignore_template headers, data = self._requester.requestAndCheck( "POST", self.url + "/repos", diff --git a/github/tests/AuthenticatedUser.py b/github/tests/AuthenticatedUser.py index b58aaa30..19e35fc8 100644 --- a/github/tests/AuthenticatedUser.py +++ b/github/tests/AuthenticatedUser.py @@ -122,6 +122,10 @@ class AuthenticatedUser(Framework.TestCase): repo = self.user.create_repo("TestPyGithub", "Repo created by PyGithub", "http://foobar.com", private=False, has_issues=False, has_wiki=False, has_downloads=False) self.assertEqual(repo.url, "https://api.github.com/repos/jacquev6/TestPyGithub") + def testCreateRepositoryWithAutoInit(self): + repo = self.user.create_repo("TestPyGithub", auto_init=True, gitignore_template="Python") + self.assertEqual(repo.url, "https://api.github.com/repos/jacquev6/TestPyGithub") + def testCreateAuthorizationWithoutArguments(self): authorization = self.user.create_authorization() self.assertEqual(authorization.id, 372259) diff --git a/github/tests/Organization.py b/github/tests/Organization.py index c69e6106..08db9120 100644 --- a/github/tests/Organization.py +++ b/github/tests/Organization.py @@ -113,6 +113,10 @@ class Organization(Framework.TestCase): repo = self.org.create_repo("TestPyGithub2", "Repo created by PyGithub", "http://foobar.com", False, False, False, False, team) self.assertEqual(repo.url, "https://api.github.com/repos/BeaverSoftware/TestPyGithub2") + def testCreateRepositoryWithAutoInit(self): + repo = self.org.create_repo("TestPyGithub", auto_init=True, gitignore_template="Python") + self.assertEqual(repo.url, "https://api.github.com/repos/BeaverSoftware/TestPyGithub") + def testCreateFork(self): pygithub = self.g.get_user("jacquev6").get_repo("PyGithub") repo = self.org.create_fork(pygithub) diff --git a/github/tests/ReplayData/AuthenticatedUser.testCreateRepositoryWithAutoInit.txt b/github/tests/ReplayData/AuthenticatedUser.testCreateRepositoryWithAutoInit.txt new file mode 100644 index 00000000..eddc90a5 --- /dev/null +++ b/github/tests/ReplayData/AuthenticatedUser.testCreateRepositoryWithAutoInit.txt @@ -0,0 +1,5 @@ +https POST api.github.com None /user/repos {'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed'} {"gitignore_template": "Python", "name": "TestPyGithub", "auto_init": true} +201 +[('status', '201 Created'), ('content-length', '1176'), ('x-github-media-type', 'github.beta; format=json'), ('x-content-type-options', 'nosniff'), ('x-ratelimit-limit', '5000'), ('x-ratelimit-remaining', '4999'), ('server', 'nginx'), ('connection', 'keep-alive'), ('etag', '"762d15bfe4477f7ec15c3c08a07da857"'), ('location', 'https://api.github.com/repos/jacquev6/TestPyGithub'), ('cache-control', 'max-age=0, private, must-revalidate'), ('date', 'Sat, 03 Nov 2012 09:01:00 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"watchers":0,"pushed_at":"2012-11-03T09:00:59Z","forks":0,"has_issues":true,"has_downloads":true,"open_issues_count":0,"description":null,"html_url":"https://github.com/jacquev6/TestPyGithub","owner":{"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","url":"https://api.github.com/users/jacquev6","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146},"url":"https://api.github.com/repos/jacquev6/TestPyGithub","updated_at":"2012-11-03T09:01:00Z","permissions":{"push":true,"pull":true,"admin":true},"mirror_url":null,"clone_url":"https://github.com/jacquev6/TestPyGithub.git","language":null,"has_wiki":true,"ssh_url":"git@github.com:jacquev6/TestPyGithub.git","svn_url":"https://github.com/jacquev6/TestPyGithub","size":0,"fork":false,"full_name":"jacquev6/TestPyGithub","open_issues":0,"git_url":"git://github.com/jacquev6/TestPyGithub.git","forks_count":0,"name":"TestPyGithub","created_at":"2012-11-03T09:00:59Z","homepage":null,"private":false,"id":6517838,"master_branch":"master","network_count":0,"watchers_count":0} + diff --git a/github/tests/ReplayData/Organization.testCreateRepositoryWithAutoInit.txt b/github/tests/ReplayData/Organization.testCreateRepositoryWithAutoInit.txt new file mode 100644 index 00000000..cb71243b --- /dev/null +++ b/github/tests/ReplayData/Organization.testCreateRepositoryWithAutoInit.txt @@ -0,0 +1,5 @@ +https POST api.github.com None /orgs/BeaverSoftware/repos {'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed'} {"gitignore_template": "Python", "name": "TestPyGithub", "auto_init": true} +201 +[('status', '201 Created'), ('content-length', '1559'), ('x-github-media-type', 'github.beta; format=json'), ('x-content-type-options', 'nosniff'), ('x-ratelimit-limit', '5000'), ('x-ratelimit-remaining', '4996'), ('server', 'nginx'), ('connection', 'keep-alive'), ('etag', '"2f35ceac1b69bbfc8c38907877514e9d"'), ('location', 'https://api.github.com/repos/BeaverSoftware/TestPyGithub'), ('cache-control', 'max-age=0, private, must-revalidate'), ('date', 'Sat, 03 Nov 2012 09:03:49 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"watchers":0,"pushed_at":"2012-11-03T09:03:49Z","forks":0,"has_issues":true,"has_downloads":true,"open_issues_count":0,"description":null,"html_url":"https://github.com/BeaverSoftware/TestPyGithub","owner":{"avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-org-420.png","url":"https://api.github.com/users/BeaverSoftware","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","login":"BeaverSoftware","id":1424031},"url":"https://api.github.com/repos/BeaverSoftware/TestPyGithub","updated_at":"2012-11-03T09:03:49Z","organization":{"avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-org-420.png","url":"https://api.github.com/users/BeaverSoftware","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","login":"BeaverSoftware","id":1424031},"permissions":{"push":true,"pull":true,"admin":true},"mirror_url":null,"clone_url":"https://github.com/BeaverSoftware/TestPyGithub.git","language":null,"has_wiki":true,"ssh_url":"git@github.com:BeaverSoftware/TestPyGithub.git","svn_url":"https://github.com/BeaverSoftware/TestPyGithub","size":0,"fork":false,"full_name":"BeaverSoftware/TestPyGithub","open_issues":0,"git_url":"git://github.com/BeaverSoftware/TestPyGithub.git","forks_count":0,"name":"TestPyGithub","created_at":"2012-11-03T09:03:49Z","homepage":null,"private":false,"id":6517856,"master_branch":"master","network_count":0,"watchers_count":0} +