From 88152440e0f37ae3def602d4bfb0137d3fece95e Mon Sep 17 00:00:00 2001 From: ysuga Date: Mon, 3 Mar 2014 14:07:28 +0900 Subject: [PATCH] Add fork function in bitbucket/repository module. Also added test module for fork function --- README.md | 1 + bitbucket/repository.py | 7 +++++++ bitbucket/tests/private/repository.py | 12 +++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 052313a..9d37aa6 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ It allows you to access most repositories, services (hooks) and ssh keys related * Access public user informations * Access public or private repositories, tags or branches * Create, update or delete one of your repository +* Fork repository * Access, create, update or delete a service (hook) * Access, create or delete an SSH key * Download a repository as an archive diff --git a/bitbucket/repository.py b/bitbucket/repository.py index b900b9b..5c965ed 100644 --- a/bitbucket/repository.py +++ b/bitbucket/repository.py @@ -10,6 +10,8 @@ 'DELETE_REPO': 'repositories/%(username)s/%(repo_slug)s/', # Get archive 'GET_ARCHIVE': 'repositories/%(username)s/%(repo_slug)s/%(format)s/master/', + + 'POST_FORK': 'repositories/%(accountname)s/%(repo_slug)s/fork/', } @@ -81,6 +83,11 @@ def create(self, repo_name, scm='git', private=True, **kwargs): url = self.bitbucket.url('CREATE_REPO') return self.bitbucket.dispatch('POST', url, auth=self.bitbucket.auth, name=repo_name, scm=scm, is_private=private, **kwargs) + def fork(self, accountname, repo_slug, name, **kwargs): + """ Fork repository on {Bitbucket accountname}/repo_slug to {own Bitbucket account}/name and return it.""" + url = self.bitbucket.url('POST_FORK', accountname=accountname, repo_slug=repo_slug) + return self.bitbucket.dispatch('POST', url, auth=self.bitbucket.auth, accountname=accountname, repo_slug=repo_slug, name=name, **kwargs) + def update(self, repo_slug=None, **kwargs): """ Updates repository on own Bitbucket account and return it.""" repo_slug = repo_slug or self.bitbucket.repo_slug or '' diff --git a/bitbucket/tests/private/repository.py b/bitbucket/tests/private/repository.py index c3465ec..62afd40 100644 --- a/bitbucket/tests/private/repository.py +++ b/bitbucket/tests/private/repository.py @@ -10,7 +10,8 @@ from bitbucket.tests.private.private import AuthenticatedBitbucketTest TEST_REPO_SLUG = "test_repository_creation" - +FORK_ACCOUT_NAME = "foo" +FORK_REPO_SLUG = "bar" def skipUnlessHasGit(f): """ This decorator pass the test if git is not found.""" @@ -49,6 +50,15 @@ def test_create(self): success, result = self.bb.repository.delete(repo_slug=TEST_REPO_SLUG) assert success + def test_fork(self): + """ Test repository fork.""" + success, result = self.bb.repository.fork(accountname=FORK_ACCOUNT_NAME, repo_slug=FORK_REPO_SLUG, name=TEST_REPO_SLUG) + self.assertTrue(success) + self.assertIsInstance(result, dict) + # Delete repo + success, result = self.bb.repository.delete(repo_slug=TEST_REPO_SLUG) + assert success + def test_update(self): """ Test repository update.""" # Try to change description