From a89f45b1edd34d64a6dda9e2e0c31e97d719186d Mon Sep 17 00:00:00 2001 From: Ben Wells Date: Wed, 10 Jun 2020 21:42:38 +0100 Subject: [PATCH 1/5] Validate pr and issue limit flag --- command/issue.go | 9 +++++---- command/issue_test.go | 12 ++++++++++++ command/pr.go | 9 ++++++--- command/pr_test.go | 11 +++++++++++ 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/command/issue.go b/command/issue.go index 305b6f832..e2904d7bd 100644 --- a/command/issue.go +++ b/command/issue.go @@ -125,6 +125,9 @@ func issueList(cmd *cobra.Command, args []string) error { if err != nil { return err } + if limit <= 0 { + return fmt.Errorf("invalid limit: %v", limit) + } author, err := cmd.Flags().GetString("author") if err != nil { @@ -238,11 +241,9 @@ func issueView(cmd *cobra.Command, args []string) error { if web { fmt.Fprintf(cmd.ErrOrStderr(), "Opening %s in your browser.\n", openURL) return utils.OpenInBrowser(openURL) - } else { - out := colorableOut(cmd) - return printIssuePreview(out, issue) } - + out := colorableOut(cmd) + return printIssuePreview(out, issue) } func issueStateTitleWithColor(state string) string { diff --git a/command/issue_test.go b/command/issue_test.go index a612cfab4..418de25d3 100644 --- a/command/issue_test.go +++ b/command/issue_test.go @@ -181,6 +181,18 @@ No issues match your search in OWNER/REPO eq(t, reqBody.Variables.Author, "foo") } +func TestIssueList_withInvalidLimitFlag(t *testing.T) { + initBlankContext("", "OWNER/REPO", "master") + http := initFakeHTTP() + http.StubRepoResponse("OWNER", "REPO") + + _, err := RunCommand("issue list --limit=0") + + if err == nil || err.Error() != "invalid limit: 0" { + t.Errorf("error running command `issue list`: %v", err) + } +} + func TestIssueList_nullAssigneeLabels(t *testing.T) { initBlankContext("", "OWNER/REPO", "master") http := initFakeHTTP() diff --git a/command/pr.go b/command/pr.go index e92fa7cf0..360837f6e 100644 --- a/command/pr.go +++ b/command/pr.go @@ -183,6 +183,10 @@ func prList(cmd *cobra.Command, args []string) error { if err != nil { return err } + if limit <= 0 { + return fmt.Errorf("invalid limit: %v", limit) + } + state, err := cmd.Flags().GetString("state") if err != nil { return err @@ -316,10 +320,9 @@ func prView(cmd *cobra.Command, args []string) error { if web { fmt.Fprintf(cmd.ErrOrStderr(), "Opening %s in your browser.\n", openURL) return utils.OpenInBrowser(openURL) - } else { - out := colorableOut(cmd) - return printPrPreview(out, pr) } + out := colorableOut(cmd) + return printPrPreview(out, pr) } func prClose(cmd *cobra.Command, args []string) error { diff --git a/command/pr_test.go b/command/pr_test.go index a11c60820..4c31198b0 100644 --- a/command/pr_test.go +++ b/command/pr_test.go @@ -437,6 +437,17 @@ func TestPRList_filteringAssigneeLabels(t *testing.T) { } } +func TestPRList_withInvalidLimitFlag(t *testing.T) { + initBlankContext("", "OWNER/REPO", "master") + http := initFakeHTTP() + http.StubRepoResponse("OWNER", "REPO") + + _, err := RunCommand(`pr list --limit=0`) + if err == nil && err.Error() != "invalid limit: 0" { + t.Errorf("error running command `issue list`: %v", err) + } +} + func TestPRView_Preview(t *testing.T) { tests := map[string]struct { ownerRepo string From c6c366e8f50d5ccadf11db52e1c033c82ff1e843 Mon Sep 17 00:00:00 2001 From: micnncim Date: Thu, 11 Jun 2020 19:53:09 +0900 Subject: [PATCH 2/5] Fix gh config examples in documentations --- command/config.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/command/config.go b/command/config.go index 7e2a541f7..a896016a8 100644 --- a/command/config.go +++ b/command/config.go @@ -36,6 +36,7 @@ var configGetCmd = &cobra.Command{ Long: `Get the value for a given configuration key. Examples: + $ gh config get git_protocol https `, @@ -49,6 +50,7 @@ var configSetCmd = &cobra.Command{ Long: `Update the configuration by setting a key to a value. Examples: + $ gh config set editor vim `, Args: cobra.ExactArgs(2), From 26987c14346e0fc4edee277a64012124c29d3819 Mon Sep 17 00:00:00 2001 From: AliabbasMerchant Date: Thu, 11 Jun 2020 17:27:18 +0530 Subject: [PATCH 3/5] Fix error when Milestone is empty during PR create --- command/title_body_survey.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/command/title_body_survey.go b/command/title_body_survey.go index d6fe11bbf..1dcf3c668 100644 --- a/command/title_body_survey.go +++ b/command/title_body_survey.go @@ -371,10 +371,8 @@ func titleBodySurvey(cmd *cobra.Command, issueState *issueMetadataState, apiClie issueState.Assignees = values.Assignees issueState.Labels = values.Labels issueState.Projects = values.Projects - issueState.Milestones = []string{values.Milestone} - - if len(issueState.Milestones) > 0 && issueState.Milestones[0] == noMilestone { - issueState.Milestones = issueState.Milestones[0:0] + if values.Milestone != "" && values.Milestone != noMilestone { + issueState.Milestones = []string{values.Milestone} } allowPreview = !issueState.HasMetadata() From 8e90c27c460d1ca4c296488cd20374f229786d3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 11 Jun 2020 16:44:08 +0200 Subject: [PATCH 4/5] Use Cobra's `Example` field for `config get/set` examples --- command/config.go | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/command/config.go b/command/config.go index a896016a8..a4511061e 100644 --- a/command/config.go +++ b/command/config.go @@ -32,13 +32,10 @@ Current respected settings: var configGetCmd = &cobra.Command{ Use: "get ", - Short: "Prints the value of a given configuration key", - Long: `Get the value for a given configuration key. - -Examples: - - $ gh config get git_protocol - https + Short: "Print the value of a given configuration key", + Example: ` + $ gh config get git_protocol + https `, Args: cobra.ExactArgs(1), RunE: configGet, @@ -46,12 +43,9 @@ Examples: var configSetCmd = &cobra.Command{ Use: "set ", - Short: "Updates configuration with the value of a given key", - Long: `Update the configuration by setting a key to a value. - -Examples: - - $ gh config set editor vim + Short: "Update configuration with a value for the given key", + Example: ` + $ gh config set editor vim `, Args: cobra.ExactArgs(2), RunE: configSet, From e7c934b05c89875de28024a0ab8a2d74c35d0ca1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 11 Jun 2020 16:44:27 +0200 Subject: [PATCH 5/5] Tweak `gh help config` output --- command/config.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/command/config.go b/command/config.go index a4511061e..e27580bd9 100644 --- a/command/config.go +++ b/command/config.go @@ -2,6 +2,7 @@ package command import ( "fmt" + "github.com/spf13/cobra" ) @@ -21,11 +22,11 @@ func init() { var configCmd = &cobra.Command{ Use: "config", - Short: "Set and get gh settings", - Long: `Get and set key/value strings. + Short: "Manage configuration for gh", + Long: `Display or change configuration settings for gh. Current respected settings: -- git_protocol: https or ssh. Default is https. +- git_protocol: "https" or "ssh". Default is "https". - editor: if unset, defaults to environment variables. `, }