def get_project(conn: Gitlab, project_id: int) -> Project: """get Gitlab project as object Args: conn (gitlab.Gitlab): Gitlab server connection object project_id (int): project id Raises: TypeError: parameter 'conn' is not of type 'gitlab.Gitlab' GitlabGetError: project not found ConnectionError: cannot connect to Gitlab project Returns: gitlab.v4.objects.Project: Gitlab project object """ if not isinstance(conn, gitlab.Gitlab): raise TypeError( f"parameter 'conn' must be of type 'gitlab.Gitlab', got '{type(conn)}'" ) try: project = conn.projects.get(project_id) except GitlabGetError as e: raise GitlabGetError( f"Project '{project_id}' not found. {e.error_message}") except Exception as e: raise ConnectionError(f"Unable to get Gitlab project. {str(e)}") return project
def test_get_repo_404(self): self.provider._api().projects.get.side_effect = \ GitlabGetError(response_code=404) with self.assertRaises(errors.RepoDoesNotExistError): self.provider.get_repo("token", "name")
def get(self, id): raise GitlabGetError('Not Found', 404)
def get(self, name, lazy): raise GitlabGetError('Project Not Found', 404)
def delete(self, hook_id): raise GitlabGetError('Not Found', 404)
def get(self, name): assert name == 'nonexistingsha' raise GitlabGetError('Branch Not Found', 404)
def get(self, sha): assert sha == 'nonexistingsha' raise GitlabGetError('Commit Not Found', 404)
def get(self, name): raise GitlabGetError('Branch Not Found', 404)
def mock_projects_get(user_name, repo_name): raise GitlabGetError()