Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Trying to initialise repository via REST API

maweeks April 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
Atlassian Team members are employees working across the company in a wide variety of roles.
May 3, 2018

Hi @maweeks,

 

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 

maweeks May 3, 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 # people like this
minnes February 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 ? 

Like Koen Gillard likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events