From 9becb5f790c4b37e3b7ba558eebd8723ad6bb5c0 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Fri, 13 Dec 2019 16:16:46 -0800 Subject: [PATCH 1/7] Have one place manage the config dir location --- context/config_file.go | 9 +++------ context/context.go | 11 ++++++++--- main.go | 8 +++----- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/context/config_file.go b/context/config_file.go index 5236930a1..49b0bf559 100644 --- a/context/config_file.go +++ b/context/config_file.go @@ -8,7 +8,6 @@ import ( "os" "path" - "github.com/mitchellh/go-homedir" "gopkg.in/yaml.v3" ) @@ -36,11 +35,9 @@ func parseConfigFile(fn string) (*configEntry, error) { return parseConfig(f) } -// ParseDefaultConfig reads the configuration from ~/.config/gh +// ParseDefaultConfig reads the configuration file func ParseDefaultConfig() (*configEntry, error) { - // FIXME: this duplicates fsContext.configFile - fn, _ := homedir.Expand("~/.config/gh") - return parseConfigFile(fn) + return parseConfigFile(configFile()) } func parseConfig(r io.Reader) (*configEntry, error) { @@ -75,7 +72,7 @@ func parseConfig(r io.Reader) (*configEntry, error) { // If ~/.config/gh is a file, convert it to a directory and place the file // into ~/.config/gh/config.yml func migrateConfigFile() { - p, _ := homedir.Expand("~/.config/gh") + p := ConfigDir() fi, err := os.Stat(p) if err != nil { // This means the file doesn't exist, and that is fine. return diff --git a/context/context.go b/context/context.go index 20a921ffc..e5d74634c 100644 --- a/context/context.go +++ b/context/context.go @@ -1,6 +1,7 @@ package context import ( + "path" "strings" "github.com/github/gh-cli/git" @@ -39,14 +40,18 @@ type fsContext struct { authToken string } -func (c *fsContext) configFile() string { - dir, _ := homedir.Expand("~/.config/gh/config.yml") +func ConfigDir() string { + dir, _ := homedir.Expand("~/.config/gh") return dir } +func configFile() string { + return path.Join(ConfigDir(), "config.yml") +} + func (c *fsContext) getConfig() (*configEntry, error) { if c.config == nil { - entry, err := parseOrSetupConfigFile(c.configFile()) + entry, err := parseOrSetupConfigFile(configFile()) if err != nil { return nil, err } diff --git a/main.go b/main.go index f09edb18d..726b50784 100644 --- a/main.go +++ b/main.go @@ -3,14 +3,15 @@ package main import ( "fmt" "os" + "path" "strings" "github.com/github/gh-cli/command" + "github.com/github/gh-cli/context" "github.com/github/gh-cli/update" "github.com/github/gh-cli/utils" "github.com/mattn/go-isatty" "github.com/mgutz/ansi" - "github.com/mitchellh/go-homedir" ) var updaterEnabled = "" @@ -61,9 +62,6 @@ func checkForUpdate(currentVersion string) (*update.ReleaseInfo, error) { } repo := updaterEnabled - stateFilePath, err := homedir.Expand("~/.config/gh/state.yml") - if err != nil { - return nil, err - } + stateFilePath := path.Join(context.ConfigDir(), "state.yml") return update.CheckForUpdate(client, stateFilePath, repo, currentVersion) } From d1905f5824d7914f0e912a5f7e8993d6644a4ca0 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Fri, 13 Dec 2019 16:17:28 -0800 Subject: [PATCH 2/7] update comment --- context/config_file.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/context/config_file.go b/context/config_file.go index 49b0bf559..6c053286d 100644 --- a/context/config_file.go +++ b/context/config_file.go @@ -69,8 +69,8 @@ func parseConfig(r io.Reader) (*configEntry, error) { // This is a temporary function that will migrate the config file. It can be removed // in January. // -// If ~/.config/gh is a file, convert it to a directory and place the file -// into ~/.config/gh/config.yml +// If the config dir is a file, convert it to a directory and place the file +// into a file named config.yml func migrateConfigFile() { p := ConfigDir() fi, err := os.Stat(p) From 5d6b095f1ad0bc367053e991af81e206b850f96d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Mon, 16 Dec 2019 13:39:22 +0100 Subject: [PATCH 3/7] Add "Opening URL in your browser" notice to `issue create --web` --- command/issue.go | 1 + command/issue_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/command/issue.go b/command/issue.go index ec4f7b188..d35853f28 100644 --- a/command/issue.go +++ b/command/issue.go @@ -248,6 +248,7 @@ func issueCreate(cmd *cobra.Command, args []string) error { if stat, err := os.Stat(".github/ISSUE_TEMPLATE"); err == nil && stat.IsDir() { openURL += "/choose" } + cmd.Printf("Opening %s in your browser.\n", openURL) return utils.OpenInBrowser(openURL) } diff --git a/command/issue_test.go b/command/issue_test.go index b5f8f0272..0ae050721 100644 --- a/command/issue_test.go +++ b/command/issue_test.go @@ -225,3 +225,27 @@ func TestIssueCreate(t *testing.T) { eq(t, output, "https://github.com/OWNER/REPO/issues/12\n") } + +func TestIssueCreate_web(t *testing.T) { + initBlankContext("OWNER/REPO", "master") + initFakeHTTP() + + var seenCmd *exec.Cmd + restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable { + seenCmd = cmd + return &outputStub{} + }) + defer restoreCmd() + + output, err := RunCommand(issueCreateCmd, `issue create --web`) + if err != nil { + t.Errorf("error running command `issue create`: %v", err) + } + + if seenCmd == nil { + t.Fatal("expected a command to run") + } + url := seenCmd.Args[len(seenCmd.Args)-1] + eq(t, url, "https://github.com/OWNER/REPO/issues/new") + eq(t, output, "Opening https://github.com/OWNER/REPO/issues/new in your browser.\n") +} From 57c7266328c64f1bd19a1a3a9e90a7f5db9a3725 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Mon, 16 Dec 2019 14:08:55 +0100 Subject: [PATCH 4/7] Fix displaying "There are no issues assigned to you" notice --- command/issue.go | 4 ++-- command/issue_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/command/issue.go b/command/issue.go index ec4f7b188..15c0a7177 100644 --- a/command/issue.go +++ b/command/issue.go @@ -169,10 +169,10 @@ func issueStatus(cmd *cobra.Command, args []string) error { out := colorableOut(cmd) printHeader(out, "Issues assigned to you") - if issuePayload.Assigned != nil { + if len(issuePayload.Assigned) > 0 { printIssues(out, " ", issuePayload.Assigned...) } else { - message := fmt.Sprintf(" There are no issues assgined to you") + message := fmt.Sprintf(" There are no issues assigned to you") printMessage(out, message) } fmt.Fprintln(out) diff --git a/command/issue_test.go b/command/issue_test.go index b5f8f0272..5b6e4c3e3 100644 --- a/command/issue_test.go +++ b/command/issue_test.go @@ -40,6 +40,38 @@ func TestIssueStatus(t *testing.T) { } } +func TestIssueStatus_blankSlate(t *testing.T) { + initBlankContext("OWNER/REPO", "master") + http := initFakeHTTP() + + http.StubResponse(200, bytes.NewBufferString(` + { "data": { + "assigned": { "issues": { "nodes": [] } }, + "mentioned": { "issues": { "nodes": [] } }, + "authored": { "issues": { "nodes": [] } } + } } + `)) + + output, err := RunCommand(issueStatusCmd, "issue status") + if err != nil { + t.Errorf("error running command `issue status`: %v", err) + } + + expectedOutput := `Issues assigned to you + There are no issues assigned to you + +Issues mentioning you + There are no issues mentioning you + +Issues opened by you + There are no issues opened by you + +` + if output != expectedOutput { + t.Errorf("expected %q, got %q", expectedOutput, output) + } +} + func TestIssueList(t *testing.T) { initBlankContext("OWNER/REPO", "master") http := initFakeHTTP() From d7513ef3f6cf252b6418613622e60593718be9af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Mon, 16 Dec 2019 14:56:44 +0100 Subject: [PATCH 5/7] Fix test assertion when running on Windows --- git/git_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/git/git_test.go b/git/git_test.go index dc1446c33..ebf10baf9 100644 --- a/git/git_test.go +++ b/git/git_test.go @@ -3,7 +3,7 @@ package git import ( "fmt" "os" - "strings" + "regexp" "testing" "github.com/github/gh-cli/test" @@ -51,7 +51,8 @@ func Test_UncommittedChangeCount(t *testing.T) { GitCommand = test.StubExecCommand("TestGitStatusHelperProcess", "boom") _, err := UncommittedChangeCount() - if !strings.HasSuffix(err.Error(), "git.test: exit status 1") { + errorRE := regexp.MustCompile(`git\.test(\.exe)?: exit status 1$`) + if !errorRE.MatchString(err.Error()) { t.Errorf("got unexpected error message: %s", err) } } From 030c99730152f5f4406eed64694da3250d57fd4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Mon, 16 Dec 2019 15:52:14 +0100 Subject: [PATCH 6/7] Avoid long first line of gh help This splits help text over paragraphs and lines to make the output of `gh` easier to read. It takes care not to go over 80 characters in width and wraps the URL in `<...>` which will help the URL get auto-linked when these docs are converted to man and HTML formats. --- command/root.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/command/root.go b/command/root.go index c925285ed..28fa1a6fa 100644 --- a/command/root.go +++ b/command/root.go @@ -43,7 +43,10 @@ type FlagError struct { var RootCmd = &cobra.Command{ Use: "gh", Short: "GitHub CLI", - Long: `Work seamlessly with GitHub from the command line. GitHub CLI is in early stages of development, and we'd love to hear your feedback at https://forms.gle/pBt3kujJi7nXZmcM6`, + Long: `Work seamlessly with GitHub from the command line. + +GitHub CLI is in early stages of development, and we'd love to hear your +feedback at `, SilenceErrors: true, SilenceUsage: true, From 1d9ad0001b950aa57b3eb6d96ab66a6886d61446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Mon, 16 Dec 2019 15:56:45 +0100 Subject: [PATCH 7/7] Simplify date format in gh version information Currently, goreleaser injects the date that includes time & timezone information, but this is visually noisy. This configures it to inject the simpler `2019-12-16` date format into the build, which also matches what our Makefile does in development. --- .goreleaser.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 39a4df536..c7041c2f7 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -6,7 +6,7 @@ before: builds: - binary: bin/gh ldflags: - - -s -w -X github.com/github/gh-cli/command.Version={{.Version}} -X github.com/github/gh-cli/command.BuildDate={{.Date}} + - -s -w -X github.com/github/gh-cli/command.Version={{.Version}} -X github.com/github/gh-cli/command.BuildDate={{time "2006-01-02"}} - -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 main.updaterEnabled=github/homebrew-gh