Don't need extra determineBaseRepo call
This commit is contained in:
parent
4c75c8bccc
commit
f490a4914f
4 changed files with 22 additions and 23 deletions
|
|
@ -76,8 +76,6 @@ func TestPRCheckout_urlArg(t *testing.T) {
|
|||
return ctx
|
||||
}
|
||||
http := initFakeHTTP()
|
||||
http.StubRepoResponse("hubot", "REPO")
|
||||
|
||||
http.StubResponse(200, bytes.NewBufferString(`
|
||||
{ "data": { "repository": { "pullRequest": {
|
||||
"number": 123,
|
||||
|
|
@ -126,7 +124,6 @@ func TestPRCheckout_urlArg_differentBase(t *testing.T) {
|
|||
return ctx
|
||||
}
|
||||
http := initFakeHTTP()
|
||||
http.StubRepoResponse("OWNER", "REPO")
|
||||
http.StubResponse(200, bytes.NewBufferString(`
|
||||
{ "data": { "repository": { "pullRequest": {
|
||||
"number": 123,
|
||||
|
|
@ -161,7 +158,7 @@ func TestPRCheckout_urlArg_differentBase(t *testing.T) {
|
|||
eq(t, err, nil)
|
||||
eq(t, output.String(), "")
|
||||
|
||||
bodyBytes, _ := ioutil.ReadAll(http.Requests[1].Body)
|
||||
bodyBytes, _ := ioutil.ReadAll(http.Requests[0].Body)
|
||||
reqBody := struct {
|
||||
Variables struct {
|
||||
Owner string
|
||||
|
|
|
|||
|
|
@ -14,32 +14,37 @@ import (
|
|||
)
|
||||
|
||||
func prFromArgs(ctx context.Context, apiClient *api.Client, cmd *cobra.Command, args []string) (*api.PullRequest, ghrepo.Interface, error) {
|
||||
if len(args) == 1 {
|
||||
// First check to see if the prString is a url, return repo from url if found. This
|
||||
// is run first because we don't need to run determineBaseRepo for this path
|
||||
prString := args[0]
|
||||
pr, r, err := prFromURL(ctx, apiClient, prString)
|
||||
if pr != nil || err != nil {
|
||||
return pr, r, err
|
||||
}
|
||||
}
|
||||
|
||||
repo, err := determineBaseRepo(apiClient, cmd, ctx)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("could not determine base repo: %w", err)
|
||||
}
|
||||
|
||||
// If there are no args see if we can guess the PR from the current branch
|
||||
if len(args) == 0 {
|
||||
pr, err := prForCurrentBranch(ctx, apiClient, repo)
|
||||
return pr, repo, err
|
||||
}
|
||||
} else {
|
||||
prString := args[0]
|
||||
// Next see if the prString is a number and use that to look up the url
|
||||
pr, err := prFromNumberString(ctx, apiClient, repo, prString)
|
||||
if pr != nil || err != nil {
|
||||
return pr, repo, err
|
||||
}
|
||||
|
||||
// First check to see if the prString is a url, return repo from url if found
|
||||
prString := args[0]
|
||||
pr, r, err := prFromURL(ctx, apiClient, prString)
|
||||
if pr != nil || err != nil {
|
||||
return pr, r, err
|
||||
}
|
||||
|
||||
// Next see if the prString is a number and use that to look up the url
|
||||
pr, err = prFromNumberString(ctx, apiClient, repo, prString)
|
||||
if pr != nil || err != nil {
|
||||
// Last see if it is a branch name
|
||||
pr, err = api.PullRequestForBranch(apiClient, repo, "", prString)
|
||||
return pr, repo, err
|
||||
}
|
||||
|
||||
// Last see if it is a branch name
|
||||
pr, err = api.PullRequestForBranch(apiClient, repo, "", prString)
|
||||
return pr, repo, err
|
||||
}
|
||||
|
||||
func prFromNumberString(ctx context.Context, apiClient *api.Client, repo ghrepo.Interface, s string) (*api.PullRequest, error) {
|
||||
|
|
|
|||
|
|
@ -50,7 +50,6 @@ func TestPRReview_bad_body(t *testing.T) {
|
|||
func TestPRReview_url_arg(t *testing.T) {
|
||||
initBlankContext("", "OWNER/REPO", "master")
|
||||
http := initFakeHTTP()
|
||||
http.StubRepoResponse("OWNER", "REPO")
|
||||
http.StubResponse(200, bytes.NewBufferString(`
|
||||
{ "data": { "repository": { "pullRequest": {
|
||||
"id": "foobar123",
|
||||
|
|
@ -77,7 +76,7 @@ func TestPRReview_url_arg(t *testing.T) {
|
|||
|
||||
test.ExpectLines(t, output.String(), "Approved pull request #123")
|
||||
|
||||
bodyBytes, _ := ioutil.ReadAll(http.Requests[2].Body)
|
||||
bodyBytes, _ := ioutil.ReadAll(http.Requests[1].Body)
|
||||
reqBody := struct {
|
||||
Variables struct {
|
||||
Input struct {
|
||||
|
|
|
|||
|
|
@ -722,8 +722,6 @@ func TestPRView_web_numberArgWithHash(t *testing.T) {
|
|||
func TestPRView_web_urlArg(t *testing.T) {
|
||||
initBlankContext("", "OWNER/REPO", "master")
|
||||
http := initFakeHTTP()
|
||||
|
||||
http.StubRepoResponse("OWNER", "REPO")
|
||||
http.StubResponse(200, bytes.NewBufferString(`
|
||||
{ "data": { "repository": { "pullRequest": {
|
||||
"url": "https://github.com/OWNER/REPO/pull/23"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue