Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List registry repository tags #2649

Open
celalsahin opened this issue Aug 23, 2023 · 10 comments
Open

List registry repository tags #2649

celalsahin opened this issue Aug 23, 2023 · 10 comments

Comments

@celalsahin
Copy link

Description of the problem, including code/CLI snippet

From the documentation I am not able to figure out finding the relevant method to match the API https://docs.gitlab.com/ee/api/container_registry.html#list-registry-repository-tags from gitlab.

What I can find is https://python-gitlab.readthedocs.io/en/stable/gl_objects/repositories.html which gets all registry repositories - not a single one, given that I have the container registry repository ID at hand.
"delete" method seems to take id= as parameter but same is missing for list method & there is no get method for project.repositories either.

Expected Behavior

A method is available to match https://docs.gitlab.com/ee/api/container_registry.html#list-registry-repository-tags

Actual Behavior

Not able to fetch a single container registry repository when we have the ID of the repository at hand.

Specifications

  • python-gitlab version: 3.15.0
  • API version you are using (v3/v4): v4
  • Gitlab server version (or gitlab.com):16.2.3
@nejch
Copy link
Member

nejch commented Aug 23, 2023

Hi @celalsahin! Please take a look at https://python-gitlab.readthedocs.io/en/stable/gl_objects/repository_tags.html.

Looking at the page, not sure if the docs are 100% clear, but there should be enough info there. Just let us know and reopen if you think it's confusing!

@nejch nejch closed this as completed Aug 23, 2023
@celalsahin
Copy link
Author

Hello @nejch I checked the documentation - thanks for the hint
Problems is I want to fetch only a single container registry repository like https://docs.gitlab.com/ee/api/container_registry.html#list-registry-repository-tags - given that I have the container "registry repository ID".

Currently I fetch all registry repos of a gitlab project via repositories = project.repositories.list() & loop through it to find the matching ID

@nejch nejch reopened this Aug 23, 2023
@nejch
Copy link
Member

nejch commented Aug 23, 2023

Ah, thanks for the clarification, I got a bit confused because you were referring to registry repository tags.

So GitLab does not actually have a GET endpoint for project-level registry repositories, only instance-level (which we've implemented):
https://docs.gitlab.com/ee/api/container_registry.html#get-details-of-a-single-repository

But the registry repository tags API uses the project-level style URL, so that cannot be reused.

We could actually make this work by adding the GetMixin to our registry repository manager and you'd always do project.repositories.get(your_id, lazy=True). But this would be misleading since there's no real endpoint behind it.

What we could do for convenience, is allow a kind of "lazy-only" option to our GetMixin, so people could do this without having the impression there's some API calls there. @JohnVillalovos do you know of any other endpoints with this kind of discrepancy?

@celalsahin
Copy link
Author

Thanks for the hint regarding the other endpoint, following its prints now I found:

https://python-gitlab.readthedocs.io/en/stable/api/gitlab.v4.html#gitlab.v4.objects.RegistryRepositoryManager

I can use the get method of this to get a registry repository given that I have its ID
I guess when we have this, the other one should not be necessary, as the registry repository ID should be unique instance wide
Am I mistaken?

@nejch
Copy link
Member

nejch commented Aug 23, 2023

@celalsahin if you just need to retrieve the registry repository by ID, then that is enough, yes.

But if you need to then list/manipulate the tags for it, unfortunately no, as that relies on the project-level endpoint. It's a consequence of how python-gitlab follows the GitLab API's URL scheme to structure parent/child resources. A similar problem is described in https://python-gitlab.readthedocs.io/en/stable/faq.html#i-cannot-edit-the-merge-request-issue-i-ve-just-retrieved.

I have an idea to work around this limitation (see #1760 (comment)) but I've never gotten to it :)

@celalsahin
Copy link
Author

Ah I talked too soon - yes gitlab.registry_repositories.get gets the registry_repository but it is missing the "tags" field in the returned object - not sure if I did anything wrong there

image

at least in the api example tags is also exists along with all the others

@celalsahin
Copy link
Author

Ah I see - thanks for providing the answer even before my realization :)

@celalsahin
Copy link
Author

@nejch one of my colleagues corrected me that RegistryRepositoryManager will actually work with retrieving tags & it actually does

repository = gitlab_api.registry_repositories.get(id=registry_repository_id, tags=True, get_all=True)

When fetched like that it also fetches all tags - so at least from my point now I found the answer to my question, thanks :)

@nejch
Copy link
Member

nejch commented Aug 24, 2023

Thanks @celalsahin! I'll keep this open to track the use case where users might also manipulate those tags. Also not sure if the array in the instance level response paginates well with many tag entries, but that's a nice and simple solution for now :)

@celalsahin
Copy link
Author

Thanks for the heads up - we will keep an eye on the pagination issue - for now some container registry with 929 tags worked fine - at least apparently more testing will follow :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants