Repository: cli/cli
File: pkg/cmd/pr/shared/finder_test.go (Go)

Code before:
					}}}`))
			},
			wantPR:   13,
			wantRepo: "https://example.org/OWNER/REPO",
		},
		{
			name: "PR URL argument and not in a local git repo",
			args: args{
				selector:   "https://example.org/OWNER/REPO/pull/13/files",
				fields:     []string{"id", "number"},
				baseRepoFn: nil,
				branchFn: func() (string, error) {
					return "", &git.GitError{
						Stderr:   "fatal: not a git repository (or any of the parent directories): .git",
						ExitCode: 128,
					}
				},
				branchConfig: stubBranchConfig(git.BranchConfig{}, &git.GitError{
					Stderr:   "fatal: not a git repository (or any of the parent directories): .git",
					ExitCode: 128,
				}),
				pushDefault: stubPushDefault("simple", nil),
				remotePushDefault: stubRemotePushDefault("", &git.GitError{
					Stderr:   "fatal: not a git repository (or any of the parent directories): .git",
					ExitCode: 128,
				}),
			},
			httpStub: func(r *httpmock.Registry) {
				r.Register(
					httpmock.GraphQL(`query PullRequestByNumber\b`),
					httpmock.StringResponse(`{"data":{"repository":{
						"pullRequest":{"number":13}
					}}}`))
			},
			wantPR:   13,
			wantRepo: "https://example.org/OWNER/REPO",
		},
		{
			name: "when provided branch argument with an open and closed PR for that branch name, it returns the open PR",
			args: args{
				selector:   "blueberries",
				fields:     []string{"id", "number"},
				baseRepoFn: stubBaseRepoFn(ghrepo.New("ORIGINOWNER", "REPO"), nil),
				branchFn: func() (string, error) {
					return "blueberries", nil
				},
				branchConfig:      stubBranchConfig(git.BranchConfig{}, nil),
				pushDefault:       stubPushDefault("simple", nil),
				parsePushRevision: stubParsedPushRevision("", nil),
				remotePushDefault: stubRemotePushDefault("", nil),
			},

Review comment (refactor):
maybe eventually this is DRYed up a little but having a single `git.GitError`

Code after:
					}}}`))
			},
			wantPR:   13,
			wantRepo: "https://example.org/OWNER/REPO",
		},
		{
			name: "PR URL argument and not in a local git repo",
			args: args{
				selector:   "https://example.org/OWNER/REPO/pull/13/files",
				fields:     []string{"id", "number"},
				baseRepoFn: nil,
				branchFn: func() (string, error) {
					return "", &git.GitError{
						Stderr:   "fatal: branchFn error",
						ExitCode: 128,
					}
				},
				branchConfig: stubBranchConfig(git.BranchConfig{}, &git.GitError{
					Stderr:   "fatal: branchConfig error",
					ExitCode: 128,
				}),
				pushDefault: stubPushDefault("simple", nil),
				remotePushDefault: stubRemotePushDefault("", &git.GitError{
					Stderr:   "fatal: remotePushDefault error",
					ExitCode: 128,
				}),
			},
			httpStub: func(r *httpmock.Registry) {
				r.Register(
					httpmock.GraphQL(`query PullRequestByNumber\b`),
					httpmock.StringResponse(`{"data":{"repository":{
						"pullRequest":{"number":13}
					}}}`))
			},
			wantPR:   13,
			wantRepo: "https://example.org/OWNER/REPO",
		},
		{
			name: "when provided branch argument with an open and closed PR for that branch name, it returns the open PR",
			args: args{
				selector:   "blueberries",
				fields:     []string{"id", "number"},
				baseRepoFn: stubBaseRepoFn(ghrepo.New("ORIGINOWNER", "REPO"), nil),
				branchFn: func() (string, error) {
					return "blueberries", nil
				},
				branchConfig:      stubBranchConfig(git.BranchConfig{}, nil),
				pushDefault:       stubPushDefault("simple", nil),
				parsePushRevision: stubParsedPushRevision("", nil),
				remotePushDefault: stubRemotePushDefault("", nil),
			},