Skip to content

Commit f490a49

Browse files
committed
Don't need extra determineBaseRepo call
1 parent 4c75c8b commit f490a49

File tree

4 files changed

+22
-23
lines changed

4 files changed

+22
-23
lines changed

command/pr_checkout_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ func TestPRCheckout_urlArg(t *testing.T) {
7676
return ctx
7777
}
7878
http := initFakeHTTP()
79-
http.StubRepoResponse("hubot", "REPO")
80-
8179
http.StubResponse(200, bytes.NewBufferString(`
8280
{ "data": { "repository": { "pullRequest": {
8381
"number": 123,
@@ -126,7 +124,6 @@ func TestPRCheckout_urlArg_differentBase(t *testing.T) {
126124
return ctx
127125
}
128126
http := initFakeHTTP()
129-
http.StubRepoResponse("OWNER", "REPO")
130127
http.StubResponse(200, bytes.NewBufferString(`
131128
{ "data": { "repository": { "pullRequest": {
132129
"number": 123,
@@ -161,7 +158,7 @@ func TestPRCheckout_urlArg_differentBase(t *testing.T) {
161158
eq(t, err, nil)
162159
eq(t, output.String(), "")
163160

164-
bodyBytes, _ := ioutil.ReadAll(http.Requests[1].Body)
161+
bodyBytes, _ := ioutil.ReadAll(http.Requests[0].Body)
165162
reqBody := struct {
166163
Variables struct {
167164
Owner string

command/pr_lookup.go

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,37 @@ import (
1414
)
1515

1616
func prFromArgs(ctx context.Context, apiClient *api.Client, cmd *cobra.Command, args []string) (*api.PullRequest, ghrepo.Interface, error) {
17+
if len(args) == 1 {
18+
// First check to see if the prString is a url, return repo from url if found. This
19+
// is run first because we don't need to run determineBaseRepo for this path
20+
prString := args[0]
21+
pr, r, err := prFromURL(ctx, apiClient, prString)
22+
if pr != nil || err != nil {
23+
return pr, r, err
24+
}
25+
}
26+
1727
repo, err := determineBaseRepo(apiClient, cmd, ctx)
1828
if err != nil {
1929
return nil, nil, fmt.Errorf("could not determine base repo: %w", err)
2030
}
2131

32+
// If there are no args see if we can guess the PR from the current branch
2233
if len(args) == 0 {
2334
pr, err := prForCurrentBranch(ctx, apiClient, repo)
2435
return pr, repo, err
25-
}
26-
27-
// First check to see if the prString is a url, return repo from url if found
28-
prString := args[0]
29-
pr, r, err := prFromURL(ctx, apiClient, prString)
30-
if pr != nil || err != nil {
31-
return pr, r, err
32-
}
36+
} else {
37+
prString := args[0]
38+
// Next see if the prString is a number and use that to look up the url
39+
pr, err := prFromNumberString(ctx, apiClient, repo, prString)
40+
if pr != nil || err != nil {
41+
return pr, repo, err
42+
}
3343

34-
// Next see if the prString is a number and use that to look up the url
35-
pr, err = prFromNumberString(ctx, apiClient, repo, prString)
36-
if pr != nil || err != nil {
44+
// Last see if it is a branch name
45+
pr, err = api.PullRequestForBranch(apiClient, repo, "", prString)
3746
return pr, repo, err
3847
}
39-
40-
// Last see if it is a branch name
41-
pr, err = api.PullRequestForBranch(apiClient, repo, "", prString)
42-
return pr, repo, err
4348
}
4449

4550
func prFromNumberString(ctx context.Context, apiClient *api.Client, repo ghrepo.Interface, s string) (*api.PullRequest, error) {

command/pr_review_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ func TestPRReview_bad_body(t *testing.T) {
5050
func TestPRReview_url_arg(t *testing.T) {
5151
initBlankContext("", "OWNER/REPO", "master")
5252
http := initFakeHTTP()
53-
http.StubRepoResponse("OWNER", "REPO")
5453
http.StubResponse(200, bytes.NewBufferString(`
5554
{ "data": { "repository": { "pullRequest": {
5655
"id": "foobar123",
@@ -77,7 +76,7 @@ func TestPRReview_url_arg(t *testing.T) {
7776

7877
test.ExpectLines(t, output.String(), "Approved pull request #123")
7978

80-
bodyBytes, _ := ioutil.ReadAll(http.Requests[2].Body)
79+
bodyBytes, _ := ioutil.ReadAll(http.Requests[1].Body)
8180
reqBody := struct {
8281
Variables struct {
8382
Input struct {

command/pr_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,8 +722,6 @@ func TestPRView_web_numberArgWithHash(t *testing.T) {
722722
func TestPRView_web_urlArg(t *testing.T) {
723723
initBlankContext("", "OWNER/REPO", "master")
724724
http := initFakeHTTP()
725-
726-
http.StubRepoResponse("OWNER", "REPO")
727725
http.StubResponse(200, bytes.NewBufferString(`
728726
{ "data": { "repository": { "pullRequest": {
729727
"url": "https://github.com/OWNER/REPO/pull/23"

0 commit comments

Comments
 (0)