def find_bitbucket_repository(user, password, email): bitbucket = Client( BasicAuthenticator(user, password, email) ) try: print("Finding run project in bitbucket...") repository = Repository.find_repository_by_name_and_owner( repository_name="run", client=bitbucket ) except HTTPError: print("Project not found") print("Creating project run...") repository = Repository.create( payload=RepositoryPayload({ "name": "run", "is_private": True, "fork_policy": RepositoryForkPolicy.NO_FORKS, }), client=bitbucket ) for link in repository.links["clone"]: if link["name"] == "https": return link["href"]
def test_response_is_a_repository(self): httpretty.register_uri(httpretty.GET, self.url, content_type='application/json', body=self.resource_data(), status=200) response = Repository.find_repository_by_name_and_owner( repository_name=self.name, client=self.test_client) assert isinstance(response, Repository)
def __init__(self, package_name, owner_name, repo_name, client, strip_v=True): """ Arguments --------- repository_name: str of the form username/repo """ # XXX test repository resolution Repository.find_repository_by_name_and_owner(repo_name, owner_name, client=client) self.name = package_name self.owner_name = owner_name self.repo_name = repo_name self.client = client self.do_strip_v = strip_v
def process_repository(repository, url): table_name = "bitbucket_repository" user_name = get_config("bitbucket.user_name") user_name, repo_name = repository.split("/") repository = Repository.find_repository_by_name_and_owner( repository_name=repo_name, owner=user_name, client=bitbucket_client) logger.debug("Bitbucket repository - {}".format(repository)) repository_info = vars(get_repository_info(repository.data)) logger.debug("BitBucket repository owner - {}".format( repository_info['owner_uuid'])) process_user(repository_info['owner_uuid'], url) print(f'https://{url}/{table_name}') r = requests.post( f'https://{url}/{table_name}', json={ "repository": json.dumps(repository_info, sort_keys=True, default=str) }, headers={"AUTH_TOKEN": get_config("azimu_api.auth_token")}) if r.status_code != 200: raise Exception(r.status_code) return r.json()