Skip to content
This repository was archived by the owner on Aug 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions bitbucket/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/',
}


Expand Down Expand Up @@ -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 ''
Expand Down
12 changes: 11 additions & 1 deletion bitbucket/tests/private/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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
Expand Down