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

feat: show when new version is available #598

Merged
merged 4 commits into from
Apr 20, 2021
Merged
Changes from 1 commit
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
Next Next commit
feat: show when new version is available
Enda Phelan committed Apr 16, 2021
commit 831ca5e04e1a5c2a36116164a0336a32d81f7190
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ require (
github.com/fatih/color v1.10.0
github.com/gobuffalo/here v0.6.2 // indirect
github.com/golang/protobuf v1.5.1 // indirect
github.com/google/go-github/v35 v35.0.0
github.com/imdario/mergo v0.3.12 // indirect
github.com/kataras/tablewriter v0.0.0-20180708051242-e063d29b7c23 // indirect
github.com/landoop/tableprinter v0.0.0-20201125135848-89e81fc956e7
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -234,6 +234,11 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY=
github.com/google/go-github/v35 v35.0.0 h1:oLrHdYkSQvbhN4gJihpEkTFKAZnIFgTCj1p/OlE4Os4=
github.com/google/go-github/v35 v35.0.0/go.mod h1:s0515YVTI+IMrDoy9Y4pHt9ShGpzHvHO8rZ7L7acgvs=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g=
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
21 changes: 21 additions & 0 deletions pkg/cmd/login/login.go
Original file line number Diff line number Diff line change
@@ -9,9 +9,13 @@ import (
"net/http"
"net/url"

"github.com/redhat-developer/app-services-cli/internal/build"

"github.com/redhat-developer/app-services-cli/pkg/auth/login"
"github.com/redhat-developer/app-services-cli/pkg/auth/token"
"github.com/redhat-developer/app-services-cli/pkg/color"

"github.com/google/go-github/v35/github"
"github.com/redhat-developer/app-services-cli/internal/config"
"github.com/redhat-developer/app-services-cli/internal/localizer"
"github.com/redhat-developer/app-services-cli/pkg/cmd/factory"
@@ -195,6 +199,8 @@ func runLogin(opts *Options) (err error) {
}))
}

checkForNewVersion(logger)

return nil
}

@@ -224,3 +230,18 @@ func createTransport(insecure bool) *http.Transport {
TLSClientConfig: &tls.Config{InsecureSkipVerify: insecure},
}
}

func checkForNewVersion(logger logging.Logger) {
client := github.NewClient(nil)

latest, _, err := client.Repositories.GetLatestRelease(context.Background(), "redhat-developer", "app-services-cli")
if err != nil {
return
}

if latest.TagName != &build.Version {
logger.Info("")
logger.Info(color.Info("A new version of rhoas is available:"), color.CodeSnippet(*latest.TagName))
logger.Info(color.Info(latest.GetHTMLURL()))
}
}