From 861b2313446b4cb33243bdf00b79cd378e628d07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 20 Feb 2020 13:53:44 +0100 Subject: [PATCH 1/2] Have `--state=closed` include merged PRs Since we currently offer no way of querying PRs by combining multiple states with an OR, the best way to handle the `closed` state is to match what the web UI is doing; that is to include merged PRs. --- command/pr.go | 2 +- command/pr_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/command/pr.go b/command/pr.go index cd2bf91e9..642067598 100644 --- a/command/pr.go +++ b/command/pr.go @@ -163,7 +163,7 @@ func prList(cmd *cobra.Command, args []string) error { case "open": graphqlState = []string{"OPEN"} case "closed": - graphqlState = []string{"CLOSED"} + graphqlState = []string{"CLOSED", "MERGED"} case "merged": graphqlState = []string{"MERGED"} case "all": diff --git a/command/pr_test.go b/command/pr_test.go index d621d447b..25fc8b34d 100644 --- a/command/pr_test.go +++ b/command/pr_test.go @@ -210,6 +210,30 @@ No pull requests match your search eq(t, reqBody.Variables.Labels, []string{"one", "two", "three"}) } +func TestPRList_filteringClosed(t *testing.T) { + initBlankContext("OWNER/REPO", "master") + http := initFakeHTTP() + http.StubRepoResponse("OWNER", "REPO") + + respBody := bytes.NewBufferString(`{ "data": {} }`) + http.StubResponse(200, respBody) + + _, err := RunCommand(prListCmd, `pr list -s closed`) + if err != nil { + t.Fatal(err) + } + + bodyBytes, _ := ioutil.ReadAll(http.Requests[1].Body) + reqBody := struct { + Variables struct { + State []string + } + }{} + json.Unmarshal(bodyBytes, &reqBody) + + eq(t, reqBody.Variables.State, []string{"CLOSED", "MERGED"}) +} + func TestPRList_filteringAssignee(t *testing.T) { initBlankContext("OWNER/REPO", "master") http := initFakeHTTP() From 13dbfa44c2c712cd4c9a2342b4ec02315c458021 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 20 Feb 2020 13:55:55 +0100 Subject: [PATCH 2/2] go fmt --- command/issue.go | 14 +++++++------- command/pr.go | 12 ++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/command/issue.go b/command/issue.go index 1c66bee99..d25912176 100644 --- a/command/issue.go +++ b/command/issue.go @@ -256,13 +256,13 @@ func printIssuePreview(out io.Writer, issue *api.Issue) error { ))) if issue.Body != "" { - fmt.Fprintln(out) - md, err := utils.RenderMarkdown(issue.Body) - if err != nil { - return err - } - fmt.Fprintln(out, md) - fmt.Fprintln(out) + fmt.Fprintln(out) + md, err := utils.RenderMarkdown(issue.Body) + if err != nil { + return err + } + fmt.Fprintln(out, md) + fmt.Fprintln(out) } fmt.Fprintf(out, utils.Gray("View this issue on GitHub: %s\n"), issue.URL) diff --git a/command/pr.go b/command/pr.go index 642067598..25e27a0ad 100644 --- a/command/pr.go +++ b/command/pr.go @@ -309,12 +309,12 @@ func printPrPreview(out io.Writer, pr *api.PullRequest) error { ))) if pr.Body != "" { fmt.Fprintln(out) - md, err := utils.RenderMarkdown(pr.Body) - if err != nil { - return err - } - fmt.Fprintln(out, md) - fmt.Fprintln(out) + md, err := utils.RenderMarkdown(pr.Body) + if err != nil { + return err + } + fmt.Fprintln(out, md) + fmt.Fprintln(out) } fmt.Fprintf(out, utils.Gray("View this pull request on GitHub: %s\n"), pr.URL)