def project_create( self, repo: str, namespace: Optional[str] = None, description: Optional[str] = None, ) -> "GithubProject": if namespace: try: owner = self.github.get_organization(namespace) except UnknownObjectException: raise GithubAPIException(f"Group {namespace} not found.") else: owner = self.github.get_user() new_repo = owner.create_repo( name=repo, description=description if description else github.GithubObject.NotSet, ) return GithubProject( repo=repo, namespace=namespace or owner.login, service=self, github_repo=new_repo, )
def list_projects( self, namespace: str = None, user: str = None, search_pattern: str = None, language: str = None, ) -> List[GitProject]: search_query = "" if user: search_query += f"user:{user}" if language: search_query += f" language:{language}" projects: List[GitProject] projects = [ GithubProject( repo=repo.name, namespace=repo.owner.login, github_repo=repo, service=self, ) for repo in self.github.search_repositories(search_query, order="asc") ] if search_pattern: projects = [ project for project in projects if re.search(search_pattern, project.repo) ] return projects
def github_project(mock_github_repo): github_project = GithubProject(repo="test_repo", service="test_service", namespace="test_namespace") parent_github_project = GithubProject( repo="test_parent_repo", service="test_service", namespace="test_parent_namespace", ) flexmock(github_project) flexmock(parent_github_project) github_project.should_receive("github_repo").and_return(mock_github_repo()) parent_github_project.should_receive("github_repo").and_return( mock_github_repo()) github_project.should_receive("parent").and_return(parent_github_project) return github_project
def get_project_from_github_repository( self, github_repo: PyGithubRepository.Repository) -> "GithubProject": return GithubProject( repo=github_repo.name, namespace=github_repo.owner.login, github_repo=github_repo, service=self, read_only=self.read_only, )
def get_projects(self) -> List["ogr_github.GithubProject"]: raw_repos = self._github_user.get_repos(affiliation="owner") return [ GithubProject( repo=repo.name, namespace=repo.owner.login, github_repo=repo, service=self.service, ) for repo in raw_repos ]
def test_github_proj_no_app_creds(self): service = GithubService(github_app_id="123", github_app_private_key=TESTING_PRIVATE_KEY) project = GithubProject(repo="packit", service=service, namespace="packit") with pytest.raises(OgrException) as exc: assert project.github_instance mes = str(exc.value) assert "No installation ID provided for packit/packit" in mes assert "make sure that you provided correct credentials" in mes
def get_project( self, repo=None, namespace=None, is_fork=False, **kwargs ) -> "GithubProject": if is_fork: namespace = self.user.get_username() return GithubProject( repo=repo, namespace=namespace, service=self, read_only=self.read_only, **kwargs, )