def import_project(project_id): if not config.validation.is_valid_project_id(project_id): raise ValueError('Invalid project id: %s' % project_id) project = projects.get_project(project_id) if project is None: raise NotFoundError('project %s not found' % project_id) if project.config_location.storage_type != GITILES_LOCATION_TYPE: raise Error('project %s is not a Gitiles project' % project_id) loc = gitiles.Location.parse_resolve(project.config_location.url) # Adjust location cfg = get_gitiles_config() if not loc.treeish or loc.treeish == 'HEAD': loc = loc._replace(treeish=cfg.project_config_default_ref) loc = loc._replace( path=loc.path.strip('/') or cfg.project_config_default_path, ) # Update project repo info. repo_url = str(loc._replace(treeish=None, path=None)) projects.update_import_info( project_id, projects.RepositoryType.GITILES, repo_url) _import_config_set('projects/%s' % project_id, loc)
def import_project(project_id, location): cfg = get_gitiles_config() # Adjust location treeish = location.treeish if not treeish or treeish == 'HEAD': treeish = cfg.project_config_default_ref location = location._replace( treeish=treeish, path=location.path.strip('/') or cfg.project_config_default_path, ) # Update project repo info. repo_url = str(location._replace(treeish=None, path=None)) projects.update_import_info( project_id, projects.RepositoryType.GITILES, repo_url) import_config_set('projects/%s' % project_id, location) # Import refs for ref in projects.get_refs(project_id): assert ref.name assert ref.name.startswith('refs/'), ref.name ref_location = location._replace( treeish=ref.name, path=ref.config_path or cfg.ref_config_default_path, ) import_config_set( 'projects/%s/%s' % (project_id, ref.name), ref_location)
def import_project(project_id): if not config.validation.is_valid_project_id(project_id): raise ValueError('Invalid project id: %s' % project_id) config_set = 'projects/%s' % project_id project = projects.get_project(project_id) if project is None: raise NotFoundError('project %s not found' % project_id) if project.config_location.storage_type != GITILES_LOCATION_TYPE: raise Error('project %s is not a Gitiles project' % project_id) try: loc = _resolved_location(project.config_location.url) except gitiles.TreeishResolutionError: @ndb.transactional def txn(): key = ndb.Key(storage.ConfigSet, config_set) if key.get(): logging.warning( 'treeish was not resolved in URL "%s" => delete project', project.config_location.url) key.delete() txn() return # Update project repo info. repo_url = str(loc._replace(treeish=None, path=None)) projects.update_import_info(project_id, projects.RepositoryType.GITILES, repo_url) _import_config_set(config_set, loc, project_id)
def import_project(project_id, location): cfg = get_gitiles_config() # Adjust location treeish = location.treeish if not treeish or treeish == 'HEAD': treeish = cfg.project_config_default_branch location = location._replace( treeish=treeish, path=location.path.strip('/') or cfg.project_config_default_path, ) # Update project repo info. repo_url = str(location._replace(treeish=None, path=None)) projects.update_import_info( project_id, projects.RepositoryType.GITILES, repo_url) import_config_set('projects/%s' % project_id, location) # Import branches for branch in projects.get_branches(project_id): branch_location = location._replace( treeish=branch.name, path=branch.config_path or cfg.branch_config_default_path, ) import_config_set( 'projects/%s/branches/%s' % (project_id, branch.name), branch_location)
def import_project(project_id, loc=None): if not config.validation.is_valid_project_id(project_id): raise ValueError('Invalid project id: %s' % project_id) if loc is None: project = projects.get_project(project_id) if project is None: raise NotFoundError('project %s not found' % project_id) if project.config_location.storage_type != GITILES_LOCATION_TYPE: raise Error('project %s is not a Gitiles project' % project_id) loc = gitiles.Location.parse_resolve(project.config_location.url) # Adjust location cfg = get_gitiles_config() if not loc.treeish or loc.treeish == 'HEAD': loc = loc._replace(treeish=cfg.project_config_default_ref) loc = loc._replace( path=loc.path.strip('/') or cfg.project_config_default_path, ) # Update project repo info. repo_url = str(loc._replace(treeish=None, path=None)) projects.update_import_info( project_id, projects.RepositoryType.GITILES, repo_url) _import_config_set('projects/%s' % project_id, loc)
def import_project(project_id): if not config.validation.is_valid_project_id(project_id): raise ValueError('Invalid project id: %s' % project_id) config_set = 'projects/%s' % project_id project = projects.get_project(project_id) if project is None: raise NotFoundError('project %s not found' % project_id) if project.HasField('gitiles_location'): loc = _make_gitiles_location(project.gitiles_location) else: raise Error('project %s does not have a gitiles location' % project_id) # Update project repo info. repo_url = str(loc._replace(treeish=None, path=None)) projects.update_import_info(project_id, projects.RepositoryType.GITILES, repo_url) _import_config_set(config_set, loc, project_id)
def test_repo_info(self): self.assertEqual(projects.get_repo("x"), (None, None)) projects.update_import_info("x", projects.RepositoryType.GITILES, "http://localhost/x") # Second time for coverage. projects.update_import_info("x", projects.RepositoryType.GITILES, "http://localhost/x") self.assertEqual(projects.get_repo("x"), (projects.RepositoryType.GITILES, "http://localhost/x")) # Change it projects.update_import_info("x", projects.RepositoryType.GITILES, "http://localhost/y")
def test_repo_info(self): self.assertEqual(projects.get_repo('x'), (None, None)) projects.update_import_info( 'x', projects.RepositoryType.GITILES, 'http://localhost/x') # Second time for coverage. projects.update_import_info( 'x', projects.RepositoryType.GITILES, 'http://localhost/x') self.assertEqual( projects.get_repo('x'), (projects.RepositoryType.GITILES, 'http://localhost/x')) # Change it projects.update_import_info( 'x', projects.RepositoryType.GITILES, 'http://localhost/y')
def test_repo_info(self): self.assertEqual( projects.get_repos_async(['x']).get_result(), {'x': (None, None)}) projects.update_import_info('x', projects.RepositoryType.GITILES, 'http://localhost/x') # Second time for coverage. projects.update_import_info('x', projects.RepositoryType.GITILES, 'http://localhost/x') self.assertEqual( projects.get_repos_async(['x']).get_result(), {'x': (projects.RepositoryType.GITILES, 'http://localhost/x')}) # Change it projects.update_import_info('x', projects.RepositoryType.GITILES, 'http://localhost/y')