From be299e269c81ab37434ba232b4d14dc35644e989 Mon Sep 17 00:00:00 2001 From: Vincent Boutour Date: Thu, 3 Jun 2021 09:15:55 +0200 Subject: [PATCH] fix(ketchup): Computing release URL with new version Signed-off-by: Vincent Boutour --- pkg/model/ketchup.go | 2 +- pkg/model/repository.go | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/pkg/model/ketchup.go b/pkg/model/ketchup.go index 0b548c9e..cabfb917 100644 --- a/pkg/model/ketchup.go +++ b/pkg/model/ketchup.go @@ -119,7 +119,7 @@ func NewRelease(repository Repository, pattern string, version semver.Version) R Repository: repository, Pattern: pattern, Version: version, - URL: repository.URL(pattern), + URL: repository.VersionURL(version.Name), } } diff --git a/pkg/model/repository.go b/pkg/model/repository.go index b5958e62..e8ec3e3e 100644 --- a/pkg/model/repository.go +++ b/pkg/model/repository.go @@ -108,11 +108,16 @@ func (r Repository) String() string { } } -// URL format the URL of given repository with current version +// URL format the URL of given repository with pattern version func (r Repository) URL(pattern string) string { + return r.VersionURL(r.Versions[pattern]) +} + +// VersionURL format the URL of given repository with given version +func (r Repository) VersionURL(version string) string { switch r.Kind { case Github: - return fmt.Sprintf("%s/%s/releases/tag/%s", githubURL, r.Name, r.Versions[pattern]) + return fmt.Sprintf("%s/%s/releases/tag/%s", githubURL, r.Name, version) case Helm: parts := strings.SplitN(r.Name, "@", 2) if len(parts) > 1 { @@ -122,16 +127,16 @@ func (r Repository) URL(pattern string) string { case Docker: switch strings.Count(r.Name, "/") { case 0: - return fmt.Sprintf("https://hub.docker.com/_/%s?tab=tags&page=1&ordering=last_updated&name=%s", r.Name, r.Versions[pattern]) + return fmt.Sprintf("https://hub.docker.com/_/%s?tab=tags&page=1&ordering=last_updated&name=%s", r.Name, version) case 1: - return fmt.Sprintf("https://hub.docker.com/r/%s/tags?page=1&ordering=last_updated&name=%s", r.Name, r.Versions[pattern]) + return fmt.Sprintf("https://hub.docker.com/r/%s/tags?page=1&ordering=last_updated&name=%s", r.Name, version) default: return fmt.Sprintf("https://%s", r.Name) } case NPM: - return fmt.Sprintf("https://www.npmjs.com/package/%s/v/%s", r.Name, r.Versions[pattern]) + return fmt.Sprintf("https://www.npmjs.com/package/%s/v/%s", r.Name, version) case Pypi: - return fmt.Sprintf("https://pypi.org/project/%s/%s/", r.Name, r.Versions[pattern]) + return fmt.Sprintf("https://pypi.org/project/%s/%s/", r.Name, version) default: return "#" }