def fetch_repositories(url, user=None, token=None): """Fetch repositories from Review Board. Args: url (unicode): The configured url for the connection. user (unicode): The configured user for the connection. token (unicode): The configured API token for the user. """ logging.info('Fetching repositories from Review Board: %s', url) # TODO: merge with COOKIE_FILE/AGENT in tasks.py root = RBClient(url, username=user, api_token=token, cookie_file='reviewbot-cookies.txt', agent='ReviewBot').get_root() for tool_type in ('Mercurial', 'Git'): repos = root.get_repositories(tool=tool_type, only_links='', only_fields='path,mirror_path,name') for repo in repos.all_items: repo_source = None for path in (repo.path, repo.mirror_path): if (os.path.exists(path) or path.startswith('http') or path.startswith('git')): repo_source = path break if repo_source: init_repository(repo.name, tool_type.lower(), repo_source) else: logging.warn('Cannot find usable path for repository: %s', repo.name)