Skip to content

Commit e598762

Browse files
committed
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.
1 parent 882fe7a commit e598762

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

gitlab/v4/objects/projects.py

+10
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,16 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO
186186
variables: ProjectVariableManager
187187
wikis: ProjectWikiManager
188188

189+
def __repr__(self) -> str:
190+
project_repr = super().__repr__()
191+
192+
if hasattr(self, "name_with_namespace"):
193+
return (
194+
f'{project_repr[:-1]} name_with_namespace:"{self.name_with_namespace}">'
195+
)
196+
else:
197+
return project_repr
198+
189199
@cli.register_custom_action("Project", ("forked_from_id",))
190200
@exc.on_http_error(exc.GitlabCreateError)
191201
def create_fork_relation(self, forked_from_id: int, **kwargs: Any) -> None:

0 commit comments

Comments
 (0)