def setUp(self): self.token = os.environ.get("PAGURE_TOKEN") self.user = os.environ.get("PAGURE_USER") test_name = self.id() or "all" persistent_data_file = os.path.join( PERSISTENT_DATA_PREFIX, f"test_pagure_data_{test_name}.yaml") PersistentObjectStorage().storage_file = persistent_data_file if PersistentObjectStorage().is_write_mode and (not self.user or not self.token): raise EnvironmentError( "please set PAGURE_TOKEN PAGURE_USER env variables") self.service = PagureService(token=self.token) self.docker_py_project = self.service.get_project( namespace="rpms", repo="python-docker", username="******") self.abiword_project = self.service.get_project(namespace="rpms", repo="abiword", username="******") self.abiword_fork = self.service.get_project(namespace="rpms", repo="abiword", username="******", is_fork=True) self.service_pagure = PagureService(token=self.token, instance_url="https://pagure.io") self.ogr_test_project = self.service_pagure.get_project( namespace=None, repo="ogr-test", username="******")
def setUp(self): self.github_token = os.environ.get("GITHUB_TOKEN") self.github_user = os.environ.get("GITHUB_USER") self.pagure_token = os.environ.get("PAGURE_TOKEN") self.pagure_user = os.environ.get("PAGURE_USER") test_name = self.id() or "all" persistent_data_file = os.path.join( PERSISTENT_DATA_PREFIX, f"test_factory_data_{test_name}.yaml" ) PersistentObjectStorage().storage_file = persistent_data_file if PersistentObjectStorage().is_write_mode and ( not self.github_user or not self.github_token ): raise EnvironmentError("please set GITHUB_TOKEN GITHUB_USER env variables") if PersistentObjectStorage().is_write_mode and ( not self.pagure_user or not self.pagure_token ): raise EnvironmentError("please set PAGURE_TOKEN PAGURE_USER env variables") self.github_service = GithubService(token=self.github_token) self.pagure_service = PagureService(token=self.pagure_token)
def test_set_status_pagure( project, commit_sha, pr_id, pr_object, state, description, check_name, url, state_to_set, uid, ): project = PagureProject(None, None, PagureService()) reporter = StatusReporter.get_instance(project=project, commit_sha=commit_sha, pr_id=pr_id) act_upon = flexmock( pr_object.source_project) if pr_id else flexmock(PagureProject) act_upon.should_receive("set_commit_status").with_args(commit_sha, state_to_set, url, description, check_name, trim=True).once() if pr_id is not None: flexmock(PagureProject).should_receive("get_pr").with_args( pr_id).and_return(pr_object) reporter.set_status(state, description, check_name, url)
def test_get_user_config_new_authentication(tmp_path): user_config_file_path = tmp_path / ".packit.yaml" user_config_file_path.write_text( "---\n" "debug: true\n" "fas_user: rambo\n" "keytab_path: './rambo.keytab'\n" "authentication:\n" " github.com:\n" " token: GITHUB_TOKEN\n" " pagure:\n" " token: PAGURE_TOKEN\n" ' instance_url: "https://my.pagure.org"\n') flexmock(os).should_receive("getenv").with_args( "XDG_CONFIG_HOME").and_return(str(tmp_path)) config = Config.get_user_config() assert config.debug and isinstance(config.debug, bool) assert config.fas_user == "rambo" assert config.keytab_path == "./rambo.keytab" assert config.kerberos_realm == "FEDORAPROJECT.ORG" assert GithubService(token="GITHUB_TOKEN") in config.services assert (PagureService(token="PAGURE_TOKEN", instance_url="https://my.pagure.org") in config.services)
def local_project(self): """ return an instance of LocalProject """ if self._local_project is None: pagure_service = PagureService( token=self.pagure_user_token, instance_url=self.package_config.dist_git_base_url, read_only=self.config.dry_run, ) if self.package_config.dist_git_clone_path: self._local_project = LocalProject( working_dir=self.package_config.dist_git_clone_path, git_url=self.package_config.dist_git_package_url, namespace=self.package_config.dist_git_namespace, repo_name=self.package_config.downstream_package_name, git_service=pagure_service, ) else: tmpdir = tempfile.mkdtemp(prefix="packit-dist-git") f = FedPKG(fas_username=self.fas_user, directory=tmpdir) f.init_ticket(self.config.keytab_path) f.clone( self.package_config.downstream_package_name, tmpdir, anonymous=not cccolutils.has_creds(), ) self._local_project = LocalProject( working_dir=tmpdir, git_url=self.package_config.dist_git_package_url, namespace=self.package_config.dist_git_namespace, repo_name=self.package_config.downstream_package_name, git_service=pagure_service, ) self._local_project.working_dir_temporary = True return self._local_project
def setUp(self): super().setUp() print(PersistentObjectStorage().storage_file) self.github_token = os.environ.get("GITHUB_TOKEN") self.pagure_token = os.environ.get("PAGURE_TOKEN") self.gitlab_token = os.environ.get("GITLAB_TOKEN") or "some_token" if PersistentObjectStorage().mode == StorageMode.write: if not self.github_token: raise EnvironmentError( "You are in requre write mode, please set GITHUB_TOKEN env variables" ) if not self.pagure_token: raise EnvironmentError( "You are in requre write mode, please set PAGURE_TOKEN env variables" ) if not os.environ.get("GITLAB_TOKEN"): raise EnvironmentError( "You are in requre write mode, please set GITLAB_TOKEN env variables" ) self.github_service = GithubService(token=self.github_token) self.pagure_service = PagureService(token=self.pagure_token) self.gitlab_service = GitlabService( token=self.gitlab_token, instance_url="https://gitlab.com" ) self.custom_instances = [ self.github_service, self.pagure_service, self.gitlab_service, ]
def setUp(self): self.github_token = os.environ.get("GITHUB_TOKEN") self.pagure_token = os.environ.get("PAGURE_TOKEN") self.gitlab_token = os.environ.get("GITLAB_TOKEN") or "some_token" test_name = self.id() or "all" persistent_data_file = os.path.join( PERSISTENT_DATA_PREFIX, f"test_factory_data_{test_name}.yaml") PersistentObjectStorage().storage_file = persistent_data_file if PersistentObjectStorage().is_write_mode and not self.github_token: raise EnvironmentError("please set GITHUB_TOKEN env variables") if PersistentObjectStorage().is_write_mode and not self.pagure_token: raise EnvironmentError("please set PAGURE_TOKEN env variables") if PersistentObjectStorage( ).is_write_mode and not os.environ.get("GITLAB_TOKEN"): raise EnvironmentError("please set GITLAB_TOKEN env variables") self.github_service = GithubService(token=self.github_token) self.pagure_service = PagureService(token=self.pagure_token) self.gitlab_service = GitlabService(token=self.gitlab_token, instance_url="https://gitlab.com") self.custom_instances = [ self.github_service, self.pagure_service, self.gitlab_service, ]
def get_project(self): """ Create ogr project instance based on provided configuration. Project instance is used for manipulating with Github/Pagure repo. :return: ogr Github/Pagure project instance or None """ # Return instance for github app if self.github_app_id: github_cert = Path(self.github_app_cert_path).read_text() if self.github_app_installation_id: # github token will be used as a credential over http (commit/push) github_app = GitHubApp(self.github_app_id, self.github_app_cert_path) self.github_token = github_app.get_installation_access_token( self.github_app_installation_id) return get_project(url=self.clone_url, custom_instances=[ GithubService( token=None, github_app_id=self.github_app_id, github_app_private_key=github_cert) ]) # Return instance for regular user (local machine) return get_project(url=self.clone_url, custom_instances=[ GithubService(token=self.github_token), PagureService( token=self.pagure_token, instance_url=self.pagure_instance_url) ])
def dist_git_svc(self) -> PagureService: if self._dist_git_svc is None: self._dist_git_svc = PagureService( instance_url=f"https://{self.dist_git_host}", token=self.dist_git_token, max_retries=self._retries, ) return self._dist_git_svc
def setup_class(cls): service_config = ServiceConfig() service_config.services = { GithubService(token="12345"), PagureService(instance_url="https://git.stg.centos.org", token="6789"), } service_config.dry_run = False service_config.github_requests_log_path = "/path" ServiceConfig.service_config = service_config
def setUp(self): super().setUp() self.token = os.environ.get("PAGURE_OGR_TEST_TOKEN", "") if PersistentObjectStorage().mode == StorageMode.write and (not self.token): raise EnvironmentError("please set PAGURE_OGR_TEST_TOKEN env variables") self.service = PagureService(token=self.token, instance_url="https://pagure.io") self._user = None self._ogr_project = None self._ogr_fork = None
def get_test_config(): conf = Config() pagure_user_token = os.environ.get("PAGURE_TOKEN", "test") github_token = os.environ.get("GITHUB_TOKEN", "test") conf.services = { PagureService(token=pagure_user_token), GithubService(token=github_token), } conf.dry_run = True return conf
def load_authentication(raw_dict): services = set() deprecated_keys = [ "github_app_id", "github_app_cert_path", "github_token", "pagure_user_token", "pagure_instance_url", "pagure_fork_token", ] if "authentication" in raw_dict: services = get_instances_from_dict(instances=raw_dict["authentication"]) elif any(key in raw_dict for key in deprecated_keys): logger.warning( "Please, " "use 'authentication' key in the user configuration " "to set tokens for GitHub and Pagure. " "New method supports more services and direct keys will be removed in the future.\n" "Example:\n" "authentication:\n" " github.com:\n" " token: GITHUB_TOKEN\n" " pagure:\n" " token: PAGURE_TOKEN\n" ' instance_url: "https://src.fedoraproject.org"\n' "See our documentation for more information " "http://packit.dev/docs/configuration/#user-configuration-file. " ) github_app_id = raw_dict.get("github_app_id") github_app_cert_path = raw_dict.get("github_app_cert_path") github_token = raw_dict.get("github_token") services.add( GithubService( token=github_token, github_app_id=github_app_id, github_app_private_key_path=github_app_cert_path, ) ) pagure_user_token = raw_dict.get("pagure_user_token") pagure_instance_url = raw_dict.get( "pagure_instance_url", "https://src.fedoraproject.org" ) if raw_dict.get("pagure_fork_token"): warnings.warn( "packit no longer accepts 'pagure_fork_token'" " value (https://github.com/packit-service/packit/issues/495)" ) services.add( PagureService(token=pagure_user_token, instance_url=pagure_instance_url) ) return services
def get_project(self): """ Create ogr project instance based on provided configuration. Project instance is used for manipulating with Github/Pagure repo. :return: ogr Github/Pagure project instance or None """ return get_project(url=self.clone_url, custom_instances=[ GithubService(token=self.github_token), PagureService( token=self.pagure_token, instance_url=self.pagure_instance_url) ])
def setUp(self): self.token = os.environ.get("PAGURE_TOKEN") test_name = self.id() or "all" self.persistent_data_file = os.path.join( PERSISTENT_DATA_PREFIX, f"test_pagure_data_{test_name}.yaml") PersistentObjectStorage().storage_file = self.persistent_data_file if PersistentObjectStorage().is_write_mode and (not self.token): raise EnvironmentError("please set PAGURE_TOKEN env variables") self.service = PagureService(token=self.token, instance_url="https://pagure.io") self._user = None self._ogr_project = None self._ogr_fork = None
def test_get_user_config(tmpdir): user_config_file_path = Path(tmpdir) / ".packit.yaml" user_config_file_path.write_text("---\n" "debug: true\n" "fas_user: rambo\n" "keytab_path: './rambo.keytab'\n" "github_token: GITHUB_TOKEN\n" "pagure_user_token: PAGURE_TOKEN\n") flexmock(os).should_receive("getenv").with_args( "XDG_CONFIG_HOME").and_return(str(tmpdir)) config = Config.get_user_config() assert config.debug and isinstance(config.debug, bool) assert config.fas_user == "rambo" assert config.keytab_path == "./rambo.keytab" assert GithubService(token="GITHUB_TOKEN") in config.services assert PagureService(token="PAGURE_TOKEN") in config.services
def setUp(self): self.token = os.environ.get("PAGURE_TOKEN") self.user = os.environ.get("PAGURE_USER") or LAST_GENERATED_BY test_name = self.id() or "all" persistent_data_file = os.path.join( PERSISTENT_DATA_PREFIX, f"test_pagure_data_{test_name}.yaml") PersistentObjectStorage().storage_file = persistent_data_file if PersistentObjectStorage().is_write_mode and (not self.user or not self.token): raise EnvironmentError( "please set PAGURE_TOKEN PAGURE_USER env variables") self.service = PagureService(token=self.token, instance_url="https://pagure.io") self.ogr_project = self.service.get_project(namespace=None, repo="ogr-tests") self.ogr_fork = self.service.get_project(namespace=None, repo="ogr-tests", username=self.user, is_fork=True)
{"some-url": GithubService}, None, True, GithubProject( namespace="packit-service", repo="ogr", service=GithubService() ), ), ( "https://github.com/packit-service/ogr", {"github.com": PagureService}, None, True, PagureProject( namespace="packit-service", repo="ogr", service=PagureService(instance_url="https://github.com"), ), ), ( "https://src.fedoraproject.org/rpms/python-ogr", None, None, True, PagureProject( namespace="rpms", repo="python-ogr", service=PagureService(instance_url="https://src.fedoraproject.org"), ), ), ( "https://pagure.io/ogr",
}, None, GithubProject(namespace="packit-service", repo="ogr", service=GithubService()), ), ( "https://github.com/packit-service/ogr", { "github.com": PagureService }, None, PagureProject( namespace="packit-service", repo="ogr", service=PagureService(instance_url="https://github.com"), ), ), ( "https://src.fedoraproject.org/rpms/python-ogr", None, None, PagureProject( namespace="rpms", repo="python-ogr", service=PagureService( instance_url="https://src.fedoraproject.org"), ), ), ( "https://pagure.io/ogr",
def service(self): if not self._service: self._service = PagureService(token=self.token, instance_url="https://pagure.io") return self._service
def pagure_service(self): if not self._pagure_service: self._pagure_service = PagureService(token=self.pagure_token) return self._pagure_service
def get_project(self) -> GitProject: pagure_service = PagureService(token=service_config.pagure_user_token, read_only=service_config.dry_run) return pagure_service.get_project(repo=self.repo_name, namespace=self.repo_namespace)
def test_hostname(self): assert PagureService().hostname == "src.fedoraproject.org" assert PagureService( instance_url="https://pagure.io").hostname == "pagure.io"