X Tutup
Skip to content

Commit fb7b01b

Browse files
committed
resolve PR review
1 parent 3bb6983 commit fb7b01b

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

command/pr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func prStatus(cmd *cobra.Command, args []string) error {
116116
repoOverride, _ := cmd.Flags().GetString("repo")
117117
currentPRNumber, currentPRHeadRef, err := prSelectorForCurrentBranch(ctx, baseRepo)
118118

119-
if err != nil && repoOverride == "" && err != git.ErrNotOnAnyBranch {
119+
if err != nil && repoOverride == "" && !errors.Is(err, git.ErrNotOnAnyBranch) {
120120
return fmt.Errorf("could not query for pull request for current branch: %w", err)
121121
}
122122

command/pr_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,38 @@ Requesting a code review from you
299299
}
300300
}
301301

302+
func TestPRStatus_detachedHead(t *testing.T) {
303+
initBlankContext("", "OWNER/REPO", "")
304+
http := initFakeHTTP()
305+
http.StubRepoResponse("OWNER", "REPO")
306+
307+
http.StubResponse(200, bytes.NewBufferString(`
308+
{ "data": {} }
309+
`))
310+
311+
output, err := RunCommand("pr status")
312+
if err != nil {
313+
t.Errorf("error running command `pr status`: %v", err)
314+
}
315+
316+
expected := `
317+
Relevant pull requests in OWNER/REPO
318+
319+
Current branch
320+
There is no current branch
321+
322+
Created by you
323+
You have no open pull requests
324+
325+
Requesting a code review from you
326+
You have no pull requests to review
327+
328+
`
329+
if output.String() != expected {
330+
t.Errorf("expected %q, got %q", expected, output.String())
331+
}
332+
}
333+
302334
func TestPRList(t *testing.T) {
303335
initBlankContext("", "OWNER/REPO", "master")
304336
http := initFakeHTTP()

context/blank_context.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func NewBlank() *blankContext {
1818
type blankContext struct {
1919
authToken string
2020
branch string
21+
branchErr error
2122
baseRepo ghrepo.Interface
2223
remotes Remotes
2324
}
@@ -40,7 +41,7 @@ func (c *blankContext) SetAuthToken(t string) {
4041

4142
func (c *blankContext) Branch() (string, error) {
4243
if c.branch == "" {
43-
return "", fmt.Errorf("branch was not initialized")
44+
return "", fmt.Errorf("branch was not initialized: %w", git.ErrNotOnAnyBranch)
4445
}
4546
return c.branch, nil
4647
}

context/context.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,7 @@ func (c *fsContext) Branch() (string, error) {
207207
}
208208

209209
currentBranch, err := git.CurrentBranch()
210-
switch err {
211-
case nil:
212-
case git.ErrNotOnAnyBranch:
213-
return "", err
214-
default:
210+
if err != nil {
215211
return "", fmt.Errorf("could not determine current branch: %w", err)
216212
}
217213

0 commit comments

Comments
 (0)
X Tutup