Ejemplo n.º 1
0
 def get_project_from_project_id(self, iid: int) -> "GitlabProject":
     gitlab_repo = self.gitlab_instance.projects.get(iid)
     return GitlabProject(
         repo=gitlab_repo.attributes["path"],
         namespace=gitlab_repo.attributes["namespace"]["full_path"],
         service=self,
         gitlab_repo=gitlab_repo,
     )
Ejemplo n.º 2
0
 def get_project(self,
                 repo=None,
                 namespace=None,
                 is_fork=False,
                 **kwargs) -> "GitlabProject":
     if is_fork:
         namespace = self.user.get_username()
     return GitlabProject(repo=repo,
                          namespace=namespace,
                          service=self,
                          **kwargs)
Ejemplo n.º 3
0
 def project_create(self, repo: str, namespace: str = None) -> "GitlabProject":
     data = {"name": repo}
     if namespace:
         try:
             group = self.gitlab_instance.groups.get(namespace)
         except gitlab.GitlabGetError:
             raise GitlabAPIException(f"Group {namespace} not found.")
         data["namespace_id"] = group.id
     new_project = self.gitlab_instance.projects.create(data)
     return GitlabProject(
         repo=repo, namespace=namespace, service=self, gitlab_repo=new_project
     )
Ejemplo n.º 4
0
    def list_projects(
        self,
        namespace: str = None,
        user: str = None,
        search_pattern: str = None,
        language: str = None,
    ) -> List[GitProject]:

        if namespace:
            group = self.gitlab_instance.groups.get(namespace)
            projects = group.projects.list(all=True)
        elif user:
            user_object = self.gitlab_instance.users.list(username=user)[0]
            projects = user_object.projects.list(all=True)
        else:
            raise OperationNotSupported

        gitlab_projects: List[GitProject]

        if language:
            # group.projects.list gives us a GroupProject instance
            # in order to be able to filter by language we need Project instance
            projects_to_convert = [
                self.gitlab_instance.projects.get(item.attributes["id"])
                for item in projects
                if language
                in self.gitlab_instance.projects.get(item.attributes["id"])
                .languages()
                .keys()
            ]
        else:
            projects_to_convert = projects
        gitlab_projects = [
            GitlabProject(
                repo=project.attributes["path"],
                namespace=project.attributes["namespace"]["full_path"],
                gitlab_repo=project,
                service=self,
            )
            for project in projects_to_convert
        ]

        return gitlab_projects
Ejemplo n.º 5
0
    def project_create(
        self,
        repo: str,
        namespace: Optional[str] = None,
        description: Optional[str] = None,
    ) -> "GitlabProject":
        data = {"name": repo}
        if namespace:
            try:
                group = self.gitlab_instance.groups.get(namespace)
            except gitlab.GitlabGetError as ex:
                raise GitlabAPIException(f"Group {namespace} not found.") from ex
            data["namespace_id"] = group.id

        if description:
            data["description"] = description
        try:
            new_project = self.gitlab_instance.projects.create(data)
        except gitlab.GitlabCreateError as ex:
            raise GitlabAPIException("Project already exists") from ex
        return GitlabProject(
            repo=repo, namespace=namespace, service=self, gitlab_repo=new_project
        )