Skip to content

Commit

Permalink
Merge pull request #475 from nkryuchkov/feature/release-url
Browse files Browse the repository at this point in the history
Add release URL to update information
  • Loading branch information
jdknives authored Aug 31, 2020
2 parents 786d2ec + 281672d commit 7e1e334
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
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)
}
})
}
}

0 comments on commit 7e1e334

Please sign in to comment.