thmspl
thmspl

Reputation: 2495

Download a bitbucket git repository via api

I am trying to make a script which get the repository from bitbucket and upload it to my ftp server.

My first problem is that i dont know how to get the repository.. Is there a way to download it with the official Bitbucket API? Or should i make a temporary folder and download it with git console?

Greez

Upvotes: 0

Views: 2933

Answers (2)

Alejandro Cotilla
Alejandro Cotilla

Reputation: 2621

The accepted answer does not use the Bitbucket API how the OP asked. For anyone else actually looking to use the API I hope this helps.

To download the repo you just need to make a GET request at:

https://bitbucket.org/<account>/<repo>/get/<branch>.<zip|gz|bz2>

This call requires Basic Auth, so make sure to pass that header with your username and password.

You could also pass the username and password in the url using this format:

https://username:[email protected]/<account>/<repo>/get/<branch>.<zip|gz|bz2>

(Not all platforms support this format)

Upvotes: 4

linuxbandit
linuxbandit

Reputation: 2492

If I interpreted your question correctly, you just need to:

  1. Generate an SSH key pair (ssh-keygen -t rsa -b 4096 -C "$(whoami)@$(hostname)-$(date -I)")
  2. Upload it to bitbucket (just your public key)
  3. Write the script that, thanks to the SSH keys, will not prompt you for any password any more during any git operations involving bitbucket (i.e. pull, push, fetch..)

You should be set - the SSH key is a direct translation of your "Bitbucket API" request, if I got the question correctly.

Edit: Just make sure that you use the correct notation for the push and pull (it is different when you use HTTPS or SSH, notably you access the URL with [email protected]:<username>/<reponame>.git)

Upvotes: 0

Related Questions