Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add release URL to update information #475

Merged
merged 1 commit into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/hypervisor/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,13 +484,15 @@ 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(),
}

if version != nil {
output.AvailableVersion = version.String()
output.ReleaseURL = version.ReleaseURL()
}

httputil.WriteJSON(w, r, http.StatusOK, output)
Expand Down Expand Up @@ -1189,13 +1191,15 @@ 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,
}

if version != nil {
output.AvailableVersion = version.String()
output.ReleaseURL = version.ReleaseURL()
}

httputil.WriteJSON(w, r, http.StatusOK, output)
Expand Down
6 changes: 6 additions & 0 deletions pkg/util/updater/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package updater

import (
"errors"
"fmt"
"strconv"
"strings"
)
Expand Down Expand Up @@ -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")
Expand Down
39 changes: 39 additions & 0 deletions pkg/util/updater/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
}