diff options
| author | Laurent Peuch <cortex@worlddomination.be> | 2022-04-29 17:54:52 +0200 |
|---|---|---|
| committer | Laurent Peuch <cortex@worlddomination.be> | 2022-04-29 18:07:33 +0200 |
| commit | e5987626ca1643521b16658555f088412be2a339 (patch) | |
| tree | 71665fbe7dd9c76e16b7f50961318dd7ffba3928 /gitlab | |
| parent | 882fe7a681ae1c5120db5be5e71b196ae555eb3e (diff) | |
| download | gitlab-e5987626ca1643521b16658555f088412be2a339.tar.gz | |
feat(ux): display project.name_with_namespace on project repr
This change the repr from:
$ gitlab.projects.get(id=some_id)
<Project id:some_id>
To:
$ gitlab.projects.get(id=some_id)
<Project id:some_id name_with_namespace:"group_name / project_name">
This is especially useful when working on random projects or listing of
projects since users generally don't remember projects ids.
Diffstat (limited to 'gitlab')
| -rw-r--r-- | gitlab/v4/objects/projects.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/gitlab/v4/objects/projects.py b/gitlab/v4/objects/projects.py index 81eb624..7d9c834 100644 --- a/gitlab/v4/objects/projects.py +++ b/gitlab/v4/objects/projects.py @@ -186,6 +186,16 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO variables: ProjectVariableManager wikis: ProjectWikiManager + def __repr__(self) -> str: + project_repr = super().__repr__() + + if hasattr(self, "name_with_namespace"): + return ( + f'{project_repr[:-1]} name_with_namespace:"{self.name_with_namespace}">' + ) + else: + return project_repr + @cli.register_custom_action("Project", ("forked_from_id",)) @exc.on_http_error(exc.GitlabCreateError) def create_fork_relation(self, forked_from_id: int, **kwargs: Any) -> None: |
