resolve PR review

This commit is contained in:
naman 2020-06-11 17:05:25 -07:00
parent 3bb6983b35
commit fb7b01b40c
4 changed files with 36 additions and 7 deletions

View file

@ -116,7 +116,7 @@ func prStatus(cmd *cobra.Command, args []string) error {
repoOverride, _ := cmd.Flags().GetString("repo")
currentPRNumber, currentPRHeadRef, err := prSelectorForCurrentBranch(ctx, baseRepo)
if err != nil && repoOverride == "" && err != git.ErrNotOnAnyBranch {
if err != nil && repoOverride == "" && !errors.Is(err, git.ErrNotOnAnyBranch) {
return fmt.Errorf("could not query for pull request for current branch: %w", err)
}

View file

@ -299,6 +299,38 @@ Requesting a code review from you
}
}
func TestPRStatus_detachedHead(t *testing.T) {
initBlankContext("", "OWNER/REPO", "")
http := initFakeHTTP()
http.StubRepoResponse("OWNER", "REPO")
http.StubResponse(200, bytes.NewBufferString(`
{ "data": {} }
`))
output, err := RunCommand("pr status")
if err != nil {
t.Errorf("error running command `pr status`: %v", err)
}
expected := `
Relevant pull requests in OWNER/REPO
Current branch
There is no current branch
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 TestPRList(t *testing.T) {
initBlankContext("", "OWNER/REPO", "master")
http := initFakeHTTP()

View file

@ -18,6 +18,7 @@ func NewBlank() *blankContext {
type blankContext struct {
authToken string
branch string
branchErr error
baseRepo ghrepo.Interface
remotes Remotes
}
@ -40,7 +41,7 @@ func (c *blankContext) SetAuthToken(t string) {
func (c *blankContext) Branch() (string, error) {
if c.branch == "" {
return "", fmt.Errorf("branch was not initialized")
return "", fmt.Errorf("branch was not initialized: %w", git.ErrNotOnAnyBranch)
}
return c.branch, nil
}

View file

@ -207,11 +207,7 @@ func (c *fsContext) Branch() (string, error) {
}
currentBranch, err := git.CurrentBranch()
switch err {
case nil:
case git.ErrNotOnAnyBranch:
return "", err
default:
if err != nil {
return "", fmt.Errorf("could not determine current branch: %w", err)
}