Allow configuring the update notifier from the outside
To test the update notifier:
rm -f bin/gh; GH_VERSION=v0.2.3 LDFLAGS='-X main.updaterEnabled=github/homebrew-gh' make
This commit is contained in:
parent
67f0cf3ce3
commit
ba0a441e23
3 changed files with 6 additions and 5 deletions
|
|
@ -9,7 +9,7 @@ builds:
|
|||
- -s -w -X github.com/github/gh-cli/command.Version={{.Version}} -X github.com/github/gh-cli/command.BuildDate={{.Date}}
|
||||
- -X github.com/github/gh-cli/context.oauthClientID={{.Env.GH_OAUTH_CLIENT_ID}}
|
||||
- -X github.com/github/gh-cli/context.oauthClientSecret={{.Env.GH_OAUTH_CLIENT_SECRET}}
|
||||
- -X github.com/github/gh-cli.updaterEnabled=yes
|
||||
- -X main.updaterEnabled=github/homebrew-gh
|
||||
goos:
|
||||
- linux
|
||||
- darwin
|
||||
|
|
|
|||
2
Makefile
2
Makefile
|
|
@ -1,7 +1,7 @@
|
|||
BUILD_FILES = $(shell go list -f '{{range .GoFiles}}{{$$.Dir}}/{{.}}\
|
||||
{{end}}' ./...)
|
||||
|
||||
GH_VERSION = $(shell git describe --tags 2>/dev/null || git rev-parse --short HEAD)
|
||||
GH_VERSION ?= $(shell git describe --tags 2>/dev/null || git rev-parse --short HEAD)
|
||||
LDFLAGS := -X github.com/github/gh-cli/command.Version=$(GH_VERSION) $(LDFLAGS)
|
||||
LDFLAGS := -X github.com/github/gh-cli/command.BuildDate=$(shell date +%Y-%m-%d) $(LDFLAGS)
|
||||
ifdef GH_OAUTH_CLIENT_SECRET
|
||||
|
|
|
|||
7
main.go
7
main.go
|
|
@ -12,7 +12,7 @@ import (
|
|||
"github.com/mgutz/ansi"
|
||||
)
|
||||
|
||||
var updaterEnabled = "no"
|
||||
var updaterEnabled = ""
|
||||
|
||||
func main() {
|
||||
currentVersion := command.Version
|
||||
|
|
@ -42,7 +42,7 @@ Release notes: %s`, currentVersion, newRelease.Version, newRelease.URL)
|
|||
|
||||
func shouldCheckForUpdate() bool {
|
||||
errFd := os.Stderr.Fd()
|
||||
return updaterEnabled == "yes" && (isatty.IsTerminal(errFd) || isatty.IsCygwinTerminal(errFd))
|
||||
return updaterEnabled != "" && (isatty.IsTerminal(errFd) || isatty.IsCygwinTerminal(errFd))
|
||||
}
|
||||
|
||||
func checkForUpdate(currentVersion string) (*update.ReleaseInfo, error) {
|
||||
|
|
@ -55,5 +55,6 @@ func checkForUpdate(currentVersion string) (*update.ReleaseInfo, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return update.CheckForUpdate(client, "github/homebrew-gh", currentVersion)
|
||||
repo := updaterEnabled
|
||||
return update.CheckForUpdate(client, repo, currentVersion)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue