feat: add gitlab source for gitlab package registry

cleanup http source
This commit is contained in:
Technofab 2023-09-25 14:40:39 +02:00
parent 8ffad5a3ea
commit d655269156
No known key found for this signature in database
GPG key ID: A0AA746B951C8830
7 changed files with 180 additions and 70 deletions

View file

@ -14,6 +14,7 @@
package deps
import (
"net/url"
"os"
"path/filepath"
"strings"
@ -58,9 +59,10 @@ func (d Dependency) LegacyName() string {
}
type Source struct {
GitSource *Git `json:"git,omitempty"`
LocalSource *Local `json:"local,omitempty"`
HttpSource *Http `json:"http,omitempty"`
GitSource *Git `json:"git,omitempty"`
LocalSource *Local `json:"local,omitempty"`
HttpSource *Http `json:"http,omitempty"`
GitlabRegistrySource *GitlabRegistry `json:"gitlab,omitempty"`
}
func (s Source) Name() string {
@ -70,7 +72,13 @@ func (s Source) Name() string {
case s.LocalSource != nil:
return s.LegacyName()
case s.HttpSource != nil:
return s.LegacyName()
parsed, err := url.Parse(s.HttpSource.Url)
if err != nil {
return "http/" + s.LegacyName()
}
return parsed.Hostname() + "/" + s.LegacyName()
case s.GitlabRegistrySource != nil:
return "gitlab.com/" + s.LegacyName()
default:
return ""
}
@ -96,6 +104,8 @@ func (s Source) LegacyName() string {
return strings.TrimSuffix(file, ".tar.gz")
}
return strings.Replace(file, filepath.Ext(file), "", 1)
case s.GitlabRegistrySource != nil:
return s.GitlabRegistrySource.Package
default:
return ""
}
@ -144,3 +154,10 @@ func parseHttp(uri string) *Dependency {
Version: "",
}
}
type GitlabRegistry struct {
Project string `json:"project"`
Package string `json:"package"`
Host string `json:"host,omitempty"`
Filename string `json:"filename,omitempty"`
}