Github: check for new release immediately on startup

This commit is contained in:
andig 2022-12-09 13:51:03 +01:00
parent e4d808688b
commit 32aba08ec8
2 changed files with 14 additions and 2 deletions

View file

@ -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
}

View file

@ -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)