From 3a22ab7eba1971ef7bb760b5f497499390cd37cc Mon Sep 17 00:00:00 2001 From: ShubhankarKG Date: Thu, 8 Oct 2020 12:04:57 +0530 Subject: [PATCH 1/4] Update shouldCheckForUpdate --- cmd/gh/main.go | 4 +++- internal/config/config_type.go | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cmd/gh/main.go b/cmd/gh/main.go index db329c3cd..5fc4c2385 100644 --- a/cmd/gh/main.go +++ b/cmd/gh/main.go @@ -186,7 +186,9 @@ func printError(out io.Writer, err error, cmd *cobra.Command, debug bool) { } func shouldCheckForUpdate() bool { - return updaterEnabled != "" && !isCompletionCommand() && utils.IsTerminal(os.Stderr) + isCIEnvironment := (os.Getenv("CI") != "") || (os.Getenv("BUILD_NUMBER") != "") || (os.Getenv("RUN_ID") != "") + isGlobalDisabled := os.Getenv("GH_NO_UPDATE_NOTIFIER") == "disabled" + return updaterEnabled != "" && !isCompletionCommand() && utils.IsTerminal(os.Stderr) && !isCIEnvironment && !isGlobalDisabled } func isCompletionCommand() bool { diff --git a/internal/config/config_type.go b/internal/config/config_type.go index 0fd85d7f0..e9bf00f28 100644 --- a/internal/config/config_type.go +++ b/internal/config/config_type.go @@ -11,9 +11,11 @@ import ( ) const ( - defaultGitProtocol = "https" - PromptsDisabled = "disabled" - PromptsEnabled = "enabled" + defaultGitProtocol = "https" + PromptsDisabled = "disabled" + PromptsEnabled = "enabled" + UpdateCheckEnabled = "enabled" + UpdateCheckDisabled = "disabled" ) // This interface describes interacting with some persistent configuration for gh. From fa536990e6f91a239010f0af3feaba71aa8cd785 Mon Sep 17 00:00:00 2001 From: ShubhankarKG Date: Thu, 8 Oct 2020 12:19:17 +0530 Subject: [PATCH 2/4] revert accidentally committed config options --- internal/config/config_type.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/internal/config/config_type.go b/internal/config/config_type.go index e9bf00f28..0fd85d7f0 100644 --- a/internal/config/config_type.go +++ b/internal/config/config_type.go @@ -11,11 +11,9 @@ import ( ) const ( - defaultGitProtocol = "https" - PromptsDisabled = "disabled" - PromptsEnabled = "enabled" - UpdateCheckEnabled = "enabled" - UpdateCheckDisabled = "disabled" + defaultGitProtocol = "https" + PromptsDisabled = "disabled" + PromptsEnabled = "enabled" ) // This interface describes interacting with some persistent configuration for gh. From 78b67fabdd38721927d98039c2dacace85849550 Mon Sep 17 00:00:00 2001 From: ShubhankarKG Date: Thu, 8 Oct 2020 21:22:26 +0530 Subject: [PATCH 3/4] 1. Added GH_NO_UPDATE_NOTIFIER to hhelp_topics 2. Updated test to check if passed variable is not empty --- cmd/gh/main.go | 2 +- pkg/cmd/root/help_topic.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/cmd/gh/main.go b/cmd/gh/main.go index 5fc4c2385..b4ed862fd 100644 --- a/cmd/gh/main.go +++ b/cmd/gh/main.go @@ -187,7 +187,7 @@ 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") == "disabled" + isGlobalDisabled := os.Getenv("GH_NO_UPDATE_NOTIFIER") != "" return updaterEnabled != "" && !isCompletionCommand() && utils.IsTerminal(os.Stderr) && !isCIEnvironment && !isGlobalDisabled } diff --git a/pkg/cmd/root/help_topic.go b/pkg/cmd/root/help_topic.go index bd23bc68a..02218a818 100644 --- a/pkg/cmd/root/help_topic.go +++ b/pkg/cmd/root/help_topic.go @@ -39,6 +39,8 @@ 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. `) cmd := &cobra.Command{ 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 4/4] :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{