From ba0a441e23a5ece2575dfc444f3df73c7c6c86ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 4 Dec 2019 14:57:24 +0100 Subject: [PATCH] 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 --- .goreleaser.yml | 2 +- Makefile | 2 +- main.go | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 7782698a1..39a4df536 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -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 diff --git a/Makefile b/Makefile index 0aa490445..14b33040f 100644 --- a/Makefile +++ b/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 diff --git a/main.go b/main.go index 67f4b3e3c..56c205335 100644 --- a/main.go +++ b/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) }