From 47dee65b63022ef14b2a57a03d3f2a6ba270d564 Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Sat, 3 Nov 2012 09:49:01 +0100 Subject: [PATCH] Implement default_branch in Repository.edit (issue #107) See http://developer.github.com/changes/2012-10-24-set-default-branch/ --- doc/ReferenceOfClasses.md | 3 ++- github/Repository.py | 5 ++++- .../ReplayData/Repository.testEditWithDefaultBranch.txt | 5 +++++ github/tests/Repository.py | 5 +++++ 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 github/tests/ReplayData/Repository.testEditWithDefaultBranch.txt diff --git a/doc/ReferenceOfClasses.md b/doc/ReferenceOfClasses.md index 35e4fdd2..930153b2 100644 --- a/doc/ReferenceOfClasses.md +++ b/doc/ReferenceOfClasses.md @@ -1375,7 +1375,7 @@ Milestones Modification ------------ -* `edit( name, [description, homepage, public, has_issues, has_wiki, has_downloads] )` +* `edit( name, [description, homepage, public, has_issues, has_wiki, has_downloads, default_branch] )` * `name`: string * `description`: string * `homepage`: string @@ -1383,6 +1383,7 @@ Modification * `has_issues`: bool * `has_wiki`: bool * `has_downloads`: bool + * `default_branch`: string Pulls ----- diff --git a/github/Repository.py b/github/Repository.py index 93156d78..b8311270 100644 --- a/github/Repository.py +++ b/github/Repository.py @@ -467,7 +467,7 @@ class Repository(GithubObject.GithubObject): None ) - def edit(self, name, description=GithubObject.NotSet, homepage=GithubObject.NotSet, public=GithubObject.NotSet, has_issues=GithubObject.NotSet, has_wiki=GithubObject.NotSet, has_downloads=GithubObject.NotSet): + def edit(self, name, description=GithubObject.NotSet, homepage=GithubObject.NotSet, public=GithubObject.NotSet, has_issues=GithubObject.NotSet, has_wiki=GithubObject.NotSet, has_downloads=GithubObject.NotSet, default_branch=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 @@ -475,6 +475,7 @@ class Repository(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 default_branch is GithubObject.NotSet or isinstance(default_branch, (str, unicode)), default_branch post_parameters = { "name": name, } @@ -490,6 +491,8 @@ class Repository(GithubObject.GithubObject): post_parameters["has_wiki"] = has_wiki if has_downloads is not GithubObject.NotSet: post_parameters["has_downloads"] = has_downloads + if default_branch is not GithubObject.NotSet: + post_parameters["default_branch"] = default_branch headers, data = self._requester.requestAndCheck( "PATCH", self.url, diff --git a/github/tests/ReplayData/Repository.testEditWithDefaultBranch.txt b/github/tests/ReplayData/Repository.testEditWithDefaultBranch.txt new file mode 100644 index 00000000..81524825 --- /dev/null +++ b/github/tests/ReplayData/Repository.testEditWithDefaultBranch.txt @@ -0,0 +1,5 @@ +https PATCH api.github.com None /repos/jacquev6/PyGithub {'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed'} {"default_branch": "master", "name": "PyGithub"} +200 +[('status', '200 OK'), ('content-length', '1264'), ('x-github-media-type', 'github.beta; format=json'), ('x-content-type-options', 'nosniff'), ('x-ratelimit-remaining', '4971'), ('server', 'nginx'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"4493662efd70c37f486a910d29ef99c1"'), ('cache-control', 'max-age=0, private, must-revalidate'), ('date', 'Sat, 03 Nov 2012 08:41:07 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"master_branch":"master","watchers":97,"pushed_at":"2012-11-03T08:25:58Z","watchers_count":97,"forks":27,"svn_url":"https://github.com/jacquev6/PyGithub","description":"Python library implementing the full Github API v3","owner":{"url":"https://api.github.com/users/jacquev6","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","login":"jacquev6","id":327146},"open_issues":11,"open_issues_count":11,"url":"https://api.github.com/repos/jacquev6/PyGithub","updated_at":"2012-11-03T08:41:07Z","permissions":{"push":true,"pull":true,"admin":true},"default_branch":"master","html_url":"https://github.com/jacquev6/PyGithub","clone_url":"https://github.com/jacquev6/PyGithub.git","language":"Python","has_downloads":true,"ssh_url":"git@github.com:jacquev6/PyGithub.git","size":256,"mirror_url":null,"fork":false,"full_name":"jacquev6/PyGithub","forks_count":27,"name":"PyGithub","created_at":"2012-02-25T12:53:47Z","git_url":"git://github.com/jacquev6/PyGithub.git","homepage":"http://vincent-jacques.net/PyGithub","has_issues":true,"private":false,"id":3544490,"network_count":27,"has_wiki":true} + diff --git a/github/tests/Repository.py b/github/tests/Repository.py index efbdd6f2..578b6106 100644 --- a/github/tests/Repository.py +++ b/github/tests/Repository.py @@ -67,6 +67,11 @@ class Repository(Framework.TestCase): self.repo.edit("PyGithub", "Python library implementing the full Github API v3") self.assertEqual(self.repo.description, "Python library implementing the full Github API v3") + def testEditWithDefaultBranch(self): + self.assertEqual(self.repo.master_branch, None) + self.repo.edit("PyGithub", default_branch="master") + self.assertEqual(self.repo.master_branch, "master") + def testDelete(self): repo = self.g.get_user().get_repo("TestPyGithub") repo.delete()