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 diff --git a/command/issue.go b/command/issue.go index 2a24e790b..df30b6e52 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) @@ -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 04a1cf7e1..bff2b5747 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.String() != expectedOutput { + t.Errorf("expected %q, got %q", expectedOutput, output) + } +} + func TestIssueList(t *testing.T) { initBlankContext("OWNER/REPO", "master") http := initFakeHTTP() @@ -225,3 +257,27 @@ func TestIssueCreate(t *testing.T) { eq(t, output.String(), "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.String(), "Opening https://github.com/OWNER/REPO/issues/new in your browser.\n") +} 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, diff --git a/context/config_file.go b/context/config_file.go index 5236930a1..6c053286d 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) { @@ -72,10 +69,10 @@ 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, _ := 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/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) } } 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) }