From 6d09500936b12631ecfdf3151fb02b71abd5be10 Mon Sep 17 00:00:00 2001 From: Tommy Petty Date: Wed, 15 Mar 2023 16:52:14 -0400 Subject: [PATCH] Fixes #455 - Hide "current branch" for pr status --repo --- pkg/cmd/pr/status/status.go | 26 ++++++++++++++------------ pkg/cmd/pr/status/status_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/pkg/cmd/pr/status/status.go b/pkg/cmd/pr/status/status.go index e4434978b..c2d4271d0 100644 --- a/pkg/cmd/pr/status/status.go +++ b/pkg/cmd/pr/status/status.go @@ -135,19 +135,21 @@ func statusRun(opts *StatusOptions) error { fmt.Fprintf(out, "Relevant pull requests in %s\n", ghrepo.FullName(baseRepo)) fmt.Fprintln(out, "") - shared.PrintHeader(opts.IO, "Current branch") - currentPR := prPayload.CurrentPR - if currentPR != nil && currentPR.State != "OPEN" && prPayload.DefaultBranch == currentBranch { - currentPR = nil + if !opts.HasRepoOverride { + shared.PrintHeader(opts.IO, "Current branch") + currentPR := prPayload.CurrentPR + if currentPR != nil && currentPR.State != "OPEN" && prPayload.DefaultBranch == currentBranch { + currentPR = nil + } + if currentPR != nil { + printPrs(opts.IO, 1, *currentPR) + } else if currentPRHeadRef == "" { + shared.PrintMessage(opts.IO, " There is no current branch") + } else { + shared.PrintMessage(opts.IO, fmt.Sprintf(" There is no pull request associated with %s", cs.Cyan("["+currentPRHeadRef+"]"))) + } + fmt.Fprintln(out) } - if currentPR != nil { - printPrs(opts.IO, 1, *currentPR) - } else if currentPRHeadRef == "" { - shared.PrintMessage(opts.IO, " There is no current branch") - } else { - shared.PrintMessage(opts.IO, fmt.Sprintf(" There is no pull request associated with %s", cs.Cyan("["+currentPRHeadRef+"]"))) - } - fmt.Fprintln(out) shared.PrintHeader(opts.IO, "Created by you") if prPayload.ViewerCreated.TotalCount > 0 { diff --git a/pkg/cmd/pr/status/status_test.go b/pkg/cmd/pr/status/status_test.go index c3187739d..f94822e47 100644 --- a/pkg/cmd/pr/status/status_test.go +++ b/pkg/cmd/pr/status/status_test.go @@ -285,6 +285,31 @@ Requesting a code review from you } } +func TestPRStatus_blankSlateRepoOverride(t *testing.T) { + http := initFakeHTTP() + defer http.Verify(t) + http.Register(httpmock.GraphQL(`query PullRequestStatus\b`), httpmock.StringResponse(`{"data": {}}`)) + + output, err := runCommand(http, "blueberries", true, "--repo OWNER/REPO") + if err != nil { + t.Errorf("error running command `pr status`: %v", err) + } + + expected := ` +Relevant pull requests in OWNER/REPO + +Created by you + You have no open pull requests + +Requesting a code review from you + You have no pull requests to review + +` + if output.String() != expected { + t.Errorf("expected %q, got %q", expected, output.String()) + } +} + func TestPRStatus_detachedHead(t *testing.T) { http := initFakeHTTP() defer http.Verify(t)