support tcnksm/go-gitconfig.GithubToken()

This commit is contained in:
Songmu 2018-01-18 19:33:31 +09:00
parent cee0f07401
commit 179b999395

View file

@ -3,14 +3,16 @@ package selfupdate
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/blang/semver"
"github.com/google/go-github/github"
"golang.org/x/oauth2"
"net/http" "net/http"
"os" "os"
"regexp" "regexp"
"runtime" "runtime"
"strings" "strings"
"github.com/blang/semver"
"github.com/google/go-github/github"
gitconfig "github.com/tcnksm/go-gitconfig"
"golang.org/x/oauth2"
) )
var reVersion = regexp.MustCompile(`\d+\.\d+\.\d+`) var reVersion = regexp.MustCompile(`\d+\.\d+\.\d+`)
@ -65,6 +67,9 @@ func findSuitableReleaseAndAsset(rels []*github.RepositoryRelease) (*github.Repo
// NewDetector crates a new detector instance. It initializes GitHub API client. // NewDetector crates a new detector instance. It initializes GitHub API client.
func NewDetector() *ReleaseDetector { func NewDetector() *ReleaseDetector {
token := os.Getenv("GITHUB_TOKEN") token := os.Getenv("GITHUB_TOKEN")
if token == "" {
token, _ = gitconfig.GithubToken()
}
ctx := context.Background() ctx := context.Background()
var auth *http.Client var auth *http.Client