From ce8f37aca207f7444b93dcd44189869301046360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Fri, 9 Oct 2020 18:14:15 +0200 Subject: [PATCH] :nail_care: tweak update notifier --- cmd/gh/main.go | 14 +++++++++++--- pkg/cmd/root/help_topic.go | 4 +++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/cmd/gh/main.go b/cmd/gh/main.go index b4ed862fd..242df7ed2 100644 --- a/cmd/gh/main.go +++ b/cmd/gh/main.go @@ -186,9 +186,17 @@ func printError(out io.Writer, err error, cmd *cobra.Command, debug bool) { } func shouldCheckForUpdate() bool { - isCIEnvironment := (os.Getenv("CI") != "") || (os.Getenv("BUILD_NUMBER") != "") || (os.Getenv("RUN_ID") != "") - isGlobalDisabled := os.Getenv("GH_NO_UPDATE_NOTIFIER") != "" - return updaterEnabled != "" && !isCompletionCommand() && utils.IsTerminal(os.Stderr) && !isCIEnvironment && !isGlobalDisabled + if os.Getenv("GH_NO_UPDATE_NOTIFIER") != "" { + return false + } + return updaterEnabled != "" && !isCI() && !isCompletionCommand() && utils.IsTerminal(os.Stderr) +} + +// based on https://github.com/watson/ci-info/blob/HEAD/index.js +func isCI() bool { + return os.Getenv("CI") != "" || // GitHub Actions, Travis CI, CircleCI, Cirrus CI, GitLab CI, AppVeyor, CodeShip, dsari + os.Getenv("BUILD_NUMBER") != "" || // Jenkins, TeamCity + os.Getenv("RUN_ID") != "" // TaskCluster, dsari } func isCompletionCommand() bool { diff --git a/pkg/cmd/root/help_topic.go b/pkg/cmd/root/help_topic.go index 02218a818..d88109ad3 100644 --- a/pkg/cmd/root/help_topic.go +++ b/pkg/cmd/root/help_topic.go @@ -40,7 +40,9 @@ func NewHelpTopic(topic string) *cobra.Command { CLICOLOR_FORCE: set to a value other than "0" to keep ANSI colors in output even when the output is piped. - GH_NO_UPDATE_NOTIFIER: set to "1" to disable checking for updates. + GH_NO_UPDATE_NOTIFIER: set to any value to disable update notifications. By default, gh + checks for new releases once every 24 hours and displays an upgrade notice on standard + error if a newer version was found. `) cmd := &cobra.Command{