def run(self) -> HandlerResults: # self.project is dist-git, we need to get upstream dg = DistGit(self.config, self.package_config) self.package_config.upstream_project_url = ( dg.get_project_url_from_distgit_spec() ) if not self.package_config.upstream_project_url: return HandlerResults( success=False, details={ "msg": "URL in specfile is not set. " "We don't know where the upstream project lives." }, ) n, r = get_namespace_and_repo_name(self.package_config.upstream_project_url) up = self.project.service.get_project(repo=r, namespace=n) self.local_project = LocalProject( git_project=up, working_dir=self.config.command_handler_work_dir ) self.api = PackitAPI(self.config, self.package_config, self.local_project) self.api.sync_from_downstream( # rev is a commit # we use branch on purpose so we get the latest thing # TODO: check if rev is HEAD on {branch}, warn then? dist_git_branch=self.distgit_event.branch, upstream_branch="master", # TODO: this should be configurable ) return HandlerResults(success=True, details={})
def run(self): # rev is a commit # we use branch on purpose so we get the latest thing # TODO: check if rev is HEAD on {branch}, warn then? branch = nested_get(self.event, "msg", "commit", "branch") # self.project is dist-git, we need to get upstream dg = DistGit(self.config, self.package_config) self.package_config.upstream_project_url = ( dg.get_project_url_from_distgit_spec()) if not self.package_config.upstream_project_url: raise PackitException( "URL in specfile is not set. We don't know where the upstream project lives." ) n, r = get_namespace_and_repo_name( self.package_config.upstream_project_url) up = self.upstream_service.get_project(repo=r, namespace=n) lp = LocalProject(git_project=up) api = PackitAPI(self.config, self.package_config, lp) api.sync_from_downstream( dist_git_branch=branch, upstream_branch="master", # TODO: this should be configurable )
def _parse_namespace_from_git_url(self): if self.git_url and (not self.namespace or not self.repo_name): namespace, repo_name = get_namespace_and_repo_name(self.git_url) if namespace == self.namespace and repo_name == self.repo_name: return False self.namespace, self.repo_name = namespace, repo_name logger.debug( f"Parsed namespace and repo name from url: {self.namespace}/{self.repo_name}" ) return True return False
def test_get_ns_repo_exc(): url = "*****@*****.**" with pytest.raises(PackitException) as ex: get_namespace_and_repo_name(url) msg = f"Invalid URL format, can't obtain namespace and repository name: {url}" assert msg in str(ex.value)
def test_get_ns_repo(url, namespace, repo_name): assert get_namespace_and_repo_name(url) == (namespace, repo_name)