-
Notifications
You must be signed in to change notification settings - Fork 674
Description
Disclaimer: I'm currently working with three of the python-gitlab maintainers (@nejch, @max-wittig, @bufferoverflow ) and we discussed today that it would be convenient if python-gitlab was supporting downloading/uploading more package types. This would be helpful for us in the context of Gitlab migrations, but also for Congregate that has plans to replace its own API wrappers by python-gitlab 🚀
Description of feature
Right now, only generic packages can be downloaded/uploaded using python-gitlab.
Even if (most of) the GitLab package APIs exhibit this kind of warning:
This API is used by the Maven package manager client and is generally not meant for manual consumption.
It is also true that the GitLab documentation has greatly improve and can generally be considered as stable (because of the pkg clients). For instance, we can see this hint for the Maven path:
The Maven package path, in the format
<groupId>/<artifactId>/<version>. Replace any.in thegroupIdwith/.
Expected Behavior
Taking again the maven example, we could have something like:
project = gl.projects.get(1, lazy=True)
package_file = project.maven_packages.download(
package_name="foo.bar.mypkg",
package_version="1.0-SNAPSHOT",
file_name="mypkg-1.0-SNAPSHOT.jar",
)Envisioned Behavior
Right now, except for generic packages, the solution is to rely on Lower-level APIs but custom logic often needs to be implemented regarding package names, metadata, etc.
from gitlab import Gitlab
from requests import Response
package_name = "foo.bar.mypkg"
package_version = "1.0-SNAPSHOT"
maven_file = "mypkg-1.0-SNAPSHOT.jar"
download_path = f"/projects/1/packages/maven/{package_name.replace('.', '/')}/{package_version}/{maven_file}"
source_gl = Gitlab("https://gitlab.com", "glpat-...", ssl_verify=True)
source_gl.auth()
download_response: Response = source_gl.http_get(
download_path,
streamed=True,
raw=True,
verify=True,
timeout=60.0,
) # type: ignore
with open(maven_file, "wb") as f:
for chunk in download_response.iter_content(chunk_size=8192):
f.write(chunk)Specifications
- python-gitlab version: 8.1.0
- Gitlab server version (or gitlab.com): N/A