Skip to content

Commit

Permalink
Allow configuring the update notifier from the outside
Browse files Browse the repository at this point in the history
To test the update notifier:

    rm -f bin/gh; GH_VERSION=v0.2.3 LDFLAGS='-X main.updaterEnabled=github/homebrew-gh' make
  • Loading branch information
mislav committed Dec 4, 2019
1 parent 67f0cf3 commit ba0a441
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/mgutz/ansi"
)

var updaterEnabled = "no"
var updaterEnabled = ""

func main() {
currentVersion := command.Version
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
}

0 comments on commit ba0a441

Please sign in to comment.