Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions command/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions command/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 6 additions & 3 deletions command/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions command/pr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down