Enable gh pr create --repo <repo> from outside of a local git repository
When failing to read information from the local git repository, silence that failure if `--repo` was given.
This commit is contained in:
parent
5d3a8e380a
commit
8c32ca925c
2 changed files with 32 additions and 1 deletions
|
|
@ -480,9 +480,14 @@ func NewCreateContext(opts *CreateOptions) (*CreateContext, error) {
|
|||
}
|
||||
client := api.NewClientFromHTTP(httpClient)
|
||||
|
||||
// TODO: consider obtaining remotes from GitClient instead
|
||||
remotes, err := opts.Remotes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
// When a repo override value is given, ignore errors when fetching git remotes
|
||||
// to support using this command outside of git repos.
|
||||
if opts.RepoOverride == "" {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
repoContext, err := ghContext.ResolveRemotesToRepos(remotes, client, opts.RepoOverride)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package create
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
|
|
@ -810,6 +811,31 @@ func Test_createRun(t *testing.T) {
|
|||
},
|
||||
wantErr: "cannot open in browser: maximum URL length exceeded",
|
||||
},
|
||||
{
|
||||
name: "no local git repo",
|
||||
setup: func(opts *CreateOptions, t *testing.T) func() {
|
||||
opts.Title = "My PR"
|
||||
opts.TitleProvided = true
|
||||
opts.Body = ""
|
||||
opts.BodyProvided = true
|
||||
opts.HeadBranch = "feature"
|
||||
opts.RepoOverride = "OWNER/REPO"
|
||||
opts.Remotes = func() (context.Remotes, error) {
|
||||
return nil, errors.New("not a git repository")
|
||||
}
|
||||
return func() {}
|
||||
},
|
||||
httpStubs: func(reg *httpmock.Registry, t *testing.T) {
|
||||
reg.Register(
|
||||
httpmock.GraphQL(`mutation PullRequestCreate\b`),
|
||||
httpmock.StringResponse(`
|
||||
{ "data": { "createPullRequest": { "pullRequest": {
|
||||
"URL": "https://github.com/OWNER/REPO/pull/12"
|
||||
} } } }
|
||||
`))
|
||||
},
|
||||
expectedOut: "https://github.com/OWNER/REPO/pull/12\n",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue