diff --git a/pkg/hypervisor/hypervisor.go b/pkg/hypervisor/hypervisor.go index addc961d6b..a6356c87bc 100644 --- a/pkg/hypervisor/hypervisor.go +++ b/pkg/hypervisor/hypervisor.go @@ -484,6 +484,7 @@ func (hv *Hypervisor) hypervisorUpdateAvailable() http.HandlerFunc { Available bool `json:"available"` CurrentVersion string `json:"current_version"` AvailableVersion string `json:"available_version,omitempty"` + ReleaseURL string `json:"release_url,omitempty"` }{ Available: version != nil, CurrentVersion: buildinfo.Version(), @@ -491,6 +492,7 @@ func (hv *Hypervisor) hypervisorUpdateAvailable() http.HandlerFunc { if version != nil { output.AvailableVersion = version.String() + output.ReleaseURL = version.ReleaseURL() } httputil.WriteJSON(w, r, http.StatusOK, output) @@ -1189,6 +1191,7 @@ func (hv *Hypervisor) visorUpdateAvailable() http.HandlerFunc { Available bool `json:"available"` CurrentVersion string `json:"current_version"` AvailableVersion string `json:"available_version,omitempty"` + ReleaseURL string `json:"release_url,omitempty"` }{ Available: version != nil, CurrentVersion: summary.BuildInfo.Version, @@ -1196,6 +1199,7 @@ func (hv *Hypervisor) visorUpdateAvailable() http.HandlerFunc { if version != nil { output.AvailableVersion = version.String() + output.ReleaseURL = version.ReleaseURL() } httputil.WriteJSON(w, r, http.StatusOK, output) diff --git a/pkg/util/updater/version.go b/pkg/util/updater/version.go index b0a1282401..805af27936 100644 --- a/pkg/util/updater/version.go +++ b/pkg/util/updater/version.go @@ -2,6 +2,7 @@ package updater import ( "errors" + "fmt" "strconv" "strings" ) @@ -65,6 +66,11 @@ func (v *Version) String() string { return version } +// ReleaseURL returns GitHub release URL for this version. +func (v *Version) ReleaseURL() string { + return fmt.Sprintf("%s/tag/%s", releaseURL, v.String()) +} + // VersionFromString parses a Version from a string. func VersionFromString(s string) (*Version, error) { s = strings.TrimPrefix(s, "v") diff --git a/pkg/util/updater/version_test.go b/pkg/util/updater/version_test.go index bc3f324bcd..4584fb8bf6 100644 --- a/pkg/util/updater/version_test.go +++ b/pkg/util/updater/version_test.go @@ -294,3 +294,42 @@ func TestVersion_Cmp(t *testing.T) { }) } } + +func TestVersion_ReleaseURL(t *testing.T) { + type fields struct { + Major int + Minor int + Patch int + Additional string + } + tests := []struct { + name string + fields fields + want string + }{ + { + "Case 1", + fields{ + Major: 1, + Minor: 2, + Patch: 3, + Additional: "test", + }, + "https://github.com/skycoin/skywire/releases/tag/v1.2.3-test", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + v := &Version{ + Major: tt.fields.Major, + Minor: tt.fields.Minor, + Patch: tt.fields.Patch, + Additional: tt.fields.Additional, + } + if got := v.ReleaseURL(); got != tt.want { + t.Errorf("ReleaseURL() = %v, want %v", got, tt.want) + } + }) + } +}