I'm currently trying to write a script in Python to clone all the repositories owned by a particular user. I should have write access to all of these repositories, which number 320 by my last count. I've tried to accomplish this by accessing the repositories' cloning URLs through the Python client like so:
from bitbucket.client import Client
cli=Client('my_user','my_pword','the_owner')
d=cli.get_repositories()
From what I understand, each element in the list d['values'] corresponds to a repository under the aforementioned owner. However, while d['size']=319, there are only 10 terms in d['values']. Each term in d['values'] does indeed correspond to one of the repositories I'm trying to clone and contains the necessary link, but again these barely cover the 320 repos I'd like to clone.
Am I just reading the paginated output incorrectly? Am I possibly running into a permissions problem? Or is there some other reason get_repositories() isn't yielding all of the repositories under the said owner? Thanks in advance.
Edit: Also, there's other information that's necessary from the output of get_repositories() that I need such as the date and time of each repository's latest update and their slug.
I ended up solving this issue using my original code. The problem I was running into was because get_repositories() gets a default pagelen parameter of 10. Given that the maximum value of pagelen is 100, it's necessary to cycle through additional pages of output to access all the necessary repositories. This is achieved by the following code:
cli=Client('username','password','owner')
cont=True
pg=1
repos=[]
while cont:
d=cli.get_repositories(params={'pagelen':100,'page':pg})['values']
repos=repos+d
pg+=1
cont=cont and len(d)>0
#Python script to clone all #repositories from a given #Bitbucket team
# -*- coding: utf-8 -*-
"""
coinify-tools
clooney
~~~~~~~~~~~~
Little script to clone all repos from a given BitBucket team/user.
"""
from git import Repo
from requests.auth import HTTPBasicAuth
import argparse
import json
import os
import requests
import sys
def get_repos(username, password, team):
bitbucket_api_root = 'https://api.bitbucket.org/1.0/users/'
raw_request = requests.get(bitbucket_api_root + team, auth=HTTPBasicAuth(username, password))
dict_request = json.loads(raw_request.content.decode('utf-8'))
repos = dict_request['repositories']
return repos
Full tested code
https://thepythoncoding.blogspot.com/2019/06/python-script-to-clone-all-repositories.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, I'll try parsing through that. However, I'm trying to learn to use the bitbucket API and am still curious to know what's going wrong with my code.
Edit: Also, there's other information that's necessary from the output of get_repositories() that I need such as the date and time of each repository's latest update and their slug.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.