From 260e7db7768c854635aac013fee48a80d9997cb0 Mon Sep 17 00:00:00 2001 From: Evan Wies Date: Mon, 22 Nov 2021 10:32:49 -0500 Subject: [PATCH] Add FormatPackageURL public helper --- generic_packages.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/generic_packages.go b/generic_packages.go index a2db4b154..ba875fa35 100644 --- a/generic_packages.go +++ b/generic_packages.go @@ -61,6 +61,23 @@ type GenericPackagesFile struct { NewFilePath string `json:"new_file_path"` } +// FormatPackageURL returns the GitLab Package Registry URL for the given artifact metadata, without the BaseURL. +// This does not make a GitLab API request, but rather computes it based on their documentation. +func (s *GenericPackagesService) FormatPackageURL(pid interface{}, packageName, packageVersion, fileName string) (string, error) { + project, err := parseID(pid) + if err != nil { + return "", err + } + u := fmt.Sprintf( + "projects/%s/packages/generic/%s/%s/%s", + pathEscape(project), + pathEscape(packageName), + pathEscape(packageVersion), + pathEscape(fileName), + ) + return u, nil +} + // PublishPackageFileOptions represents the available PublishPackageFile() // options. //