Github: check for new release immediately on startup
This commit is contained in:
parent
e4d808688b
commit
32aba08ec8
2 changed files with 14 additions and 2 deletions
|
|
@ -6,6 +6,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
|
@ -13,6 +14,7 @@ import (
|
|||
"github.com/evcc-io/evcc/util/request"
|
||||
"github.com/google/go-github/v32/github"
|
||||
"github.com/hashicorp/go-version"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -30,11 +32,21 @@ type Repo struct {
|
|||
|
||||
// NewRepo creates repository adapter
|
||||
func NewRepo(log *util.Logger, owner, repository string) *Repo {
|
||||
client := request.NewClient(log)
|
||||
|
||||
if token := os.Getenv("GITHUB_TOKEN"); token != "" {
|
||||
ctx := context.WithValue(context.Background(), oauth2.HTTPClient, client)
|
||||
client = oauth2.NewClient(ctx, oauth2.StaticTokenSource(&oauth2.Token{
|
||||
AccessToken: token,
|
||||
}))
|
||||
}
|
||||
|
||||
r := &Repo{
|
||||
owner: owner,
|
||||
repository: repository,
|
||||
Client: github.NewClient(request.NewClient(log)),
|
||||
Client: github.NewClient(client),
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ func (u *watch) Send(key string, val interface{}) {
|
|||
}
|
||||
|
||||
func (u *watch) watchReleases(installed string, out chan *github.RepositoryRelease) {
|
||||
for range time.NewTicker(6 * time.Hour).C {
|
||||
for ; true; <-time.NewTicker(6 * time.Hour).C {
|
||||
rel, err := u.findReleaseUpdate(installed)
|
||||
if err != nil {
|
||||
u.log.ERROR.Printf("version check failed: %v", err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue