It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Trying to initialise repository via REST API

Maw Apr 29, 2018

Hello, I am trying to initialise a repository via REST API and can't seem to find the right endpoint.

I have managed to:

  • Create the repository (/rest/projects/{projectKey}/repos)
  • Add file when branch exists (/rest/projects/{projectKey}/repos/{repositorySlug}/browse/{path:.*})
  • Create a branch from an existing branch (/rest/projects/{projectKey}/repos/{repositorySlug}/branches)
  • Add repository settings (/rest/projects/{projectKey}/repos/{repositorySlug}/settings/pull-requests)

 

How can I initialise the repository using only the REST API straight after creating the repository?

1 answer

0 votes
Caterina Curti Atlassian Team May 03, 2018

Hi @Maw,

 

Can you let us know what is not possible to automate at the moment?

Is it about adding the source code, in other words pushing the git repository?

 

I see that you have been able to identify the REST API to perform various the initial creation and apply various configuration.

 

Cheers,

Caterina - Atlassian 

Maw May 03, 2018

Hello,

I am currently unable to make the initial commit to a repository in a project on bitbucket server.

I can create the repository but I am unable to commit any changes without a branch to reference.

I know on bitbucket.org I can use a POST to:

https://api.bitbucket.org/2.0/repositories/username/zzz/src/

without specifying a branch and it will create the master branch.

But I am unable to find the same functionality on bitbucket server for a repository in a project.

Current calls:

Bitbucket.org:

Create repository - works as expected
POST - https://api.bitbucket.org/2.0/repositories/username/zzz
body = {
"name": "zzz test",
"scm": "git"
}

Create README.md / initial commit: - works as expected
POST - https://api.bitbucket.org/2.0/repositories/username/zzz/src/
body = x-www-form-urlencoded
/README.md = # zzz repository

Create file once a branch exists: - works as expected
POST - https://api.bitbucket.org/2.0/repositories/username/zzz/src/
body = x-www-form-urlencoded
/Y.md = testData


Bitbucket server:

Create repository: - works as expected
POST - %{base_url}/rest/api/1.0/projects/%{project}/repos
body = {
"name": "zzz test",
"scmId": "git"
}

Create README.md / initial commit: - NEEDED

Create file once a branch exists: - works as expected
PUT - %{base_url}/rest/api/1.0/projects/%{project}/repos/%{repository}/browse/Y.md
body = x-www-form-urlencoded
branch = master
content = testData
message = SecondCommit

%{base_url}/rest/api/1.0/projects/%{project}/repos/%{repository}/browse/* cannot be used without specifying a branch and specifying master doesn't work as it doesn't exist initially.

Is there a way to either initialize the repository with the master branch / README in the create repository call, or is there another REST call that I can use to make the initial commit like I do on bitbucket.org?

(I realize that I could script the clone, commit, push but would rather not do that if I can do it via a REST call.)

Like Sébastien Minne likes this
Sébastien Minne I'm New Here Feb 15, 2019

Any luck with this issue ? 

I(m trying to do the exact same stuff and no way to create a branch because : 

repo is empty - branches cannot be created in empty repositories.

 

but no way to make a first commit ? 

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Bitbucket Pipelines

Building a Bitbucket Pipe as a casual coder

...ipe.sh :  #!/bin/bash source "$(dirname "$0")/common.sh" enable_debug extra_args="" if [[ "${DEBUG}" == "true" ]]; then extra_args="--verbose" fi # mandatory variables R...

1,617 views 2 18
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you