4

There's any way to fork a repository using BB's API?

From what I've read on the API's docs, there isn't any explicit one: https://confluence.atlassian.com/display/BITBUCKET/Repositories

My idea is to create a new repo and point that it's a fork of another one, so I can create pull requests later.

dmmd
  • 2,938
  • 4
  • 33
  • 41

4 Answers4

3

You can use the API to fork a repository, either using Basic authorization or OAuth.

The method to fork a repository:

Using a authorized POST-request with required post data "name". https://bitbucket.org/api/1.0/repositories/{accountname}/{repo_slug}/fork/

Full documentation with optional parameters here: http://restbrowser.bitbucket.org/

Ogglas
  • 62,132
  • 37
  • 328
  • 418
2

So..

Tried to contact support via twitter and comments on the API page. Didn't get an answer...

And it seems that they really don't have a method to create forks.

My solution:

  • Created a cURL interface to interact with BitBucket's website, and from there I could fork and create pull requests

If you have a better solution for that, or if they actually have the method on the API, please fell free to drop your answer here.

Follow up: https://bitbucket.org/site/master/issue/4376/api-method-to-fork-a-repository

dmmd
  • 2,938
  • 4
  • 33
  • 41
2

.

you can to fork the repositories using Bitbucket API without need to username and password, only using bitbucket application.

There is HERE the doc's for POST a new fork.

Also you need to base knowledge of OAuth, following links are helpful .

  1. OAuth on Bitbucket

  2. Use the Bitbucket REST APIs

  3. Bitbucket API version 1

  4. Bitbucket API version 2

  5. Bitbucket REST API Browser

If you are a wordpress developer, this plugin can be helpful for you.

.

code.png

0

2022 TLDR;

Bitbucket cloud 2.0 API with minimal required fields (API Ref) as far as I can tell:

POST https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/forks

{
  "is_private": true,
  "scm": "git",
  "name": {new_workspace},
  "workspace":{
      "slug":{new_reposlug}
  }
}

For example, imagine you have repo foo in workspace sandbox. And you want to make a fork foo-fork in the same workspace.

POST https://api.bitbucket.org/2.0/repositories/sandbox/foo/forks

{
  "is_private": true,
  "scm": "git",
  "name": "foo-fork",
  "workspace":{
      "slug":"sandbox"
  }
}

The response is quite large and will show al the other optional request fields

Adam Hughes
  • 14,601
  • 12
  • 83
  • 122