Rename PRRefs to PullRequestRefs and PR comment cleanup
This commit is contained in:
parent
e31bfd0092
commit
e0f624ba24
6 changed files with 35 additions and 35 deletions
|
|
@ -474,7 +474,7 @@ func (c *Client) RemotePushDefault(ctx context.Context) (string, error) {
|
|||
}
|
||||
|
||||
// ParsePushRevision gets the value of the @{push} revision syntax
|
||||
// An error here doesn't necessarily mean something are broke, but may mean that the @{push}
|
||||
// An error here doesn't necessarily mean something is broken, but may mean that the @{push}
|
||||
// revision syntax couldn't be resolved, such as in non-centralized workflows with
|
||||
// push.default = simple. Downstream consumers should consider how to handle this error.
|
||||
func (c *Client) ParsePushRevision(ctx context.Context, branch string) (string, error) {
|
||||
|
|
|
|||
|
|
@ -769,7 +769,7 @@ func TestClientReadBranchConfig(t *testing.T) {
|
|||
branch.trunk.merge refs/heads/trunk
|
||||
branch.trunk.pushremote origin
|
||||
branch.trunk.gh-merge-base gh-merge-base
|
||||
`),
|
||||
`),
|
||||
},
|
||||
},
|
||||
branch: "trunk",
|
||||
|
|
|
|||
|
|
@ -518,7 +518,7 @@ func initDefaultTitleBody(ctx CreateContext, state *shared.IssueMetadataState, u
|
|||
return nil
|
||||
}
|
||||
|
||||
// TODO: Replace with the finder's PRRefs struct
|
||||
// TODO: Replace with the finder's PullRequestRefs struct
|
||||
// trackingRef represents a ref for a remote tracking branch.
|
||||
type trackingRef struct {
|
||||
remoteName string
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ type FindOptions struct {
|
|||
//
|
||||
// A ref is described as "remoteName/branchName", so
|
||||
// baseRepoName/baseBranchName -----PR-----> headRepoName/headBranchName
|
||||
type PRRefs struct {
|
||||
type PullRequestRefs struct {
|
||||
BranchName string
|
||||
HeadRepo ghrepo.Interface
|
||||
BaseRepo ghrepo.Interface
|
||||
|
|
@ -112,7 +112,7 @@ type PRRefs struct {
|
|||
// GetPRHeadLabel returns the string that the GitHub API uses to identify the PR. This is
|
||||
// either just the branch name or, if the PR is originating from a fork, the fork owner
|
||||
// and the branch name, like <owner>:<branch>.
|
||||
func (s *PRRefs) GetPRHeadLabel() string {
|
||||
func (s *PullRequestRefs) GetPRHeadLabel() string {
|
||||
if ghrepo.IsSame(s.HeadRepo, s.BaseRepo) {
|
||||
return s.BranchName
|
||||
}
|
||||
|
|
@ -227,7 +227,7 @@ func (f *finder) Find(opts FindOptions) (*api.PullRequest, ghrepo.Interface, err
|
|||
return nil, nil, err
|
||||
}
|
||||
|
||||
// Suppressing these errors as we have other means of computing the PRRefs when these fail.
|
||||
// Suppressing these errors as we have other means of computing the PullRequestRefs when these fail.
|
||||
parsedPushRevision, _ := f.parsePushRevision(f.branchName)
|
||||
|
||||
remotePushDefault, err := f.remotePushDefault()
|
||||
|
|
@ -302,8 +302,8 @@ func (f *finder) parseURL(prURL string) (ghrepo.Interface, int, error) {
|
|||
return repo, prNumber, nil
|
||||
}
|
||||
|
||||
func ParsePRRefs(currentBranchName string, branchConfig git.BranchConfig, parsedPushRevision string, pushDefault string, remotePushDefault string, baseRefRepo ghrepo.Interface, rems remotes.Remotes) (PRRefs, error) {
|
||||
prRefs := PRRefs{
|
||||
func ParsePRRefs(currentBranchName string, branchConfig git.BranchConfig, parsedPushRevision string, pushDefault string, remotePushDefault string, baseRefRepo ghrepo.Interface, rems remotes.Remotes) (PullRequestRefs, error) {
|
||||
prRefs := PullRequestRefs{
|
||||
BaseRepo: baseRefRepo,
|
||||
}
|
||||
|
||||
|
|
@ -323,7 +323,7 @@ func ParsePRRefs(currentBranchName string, branchConfig git.BranchConfig, parsed
|
|||
for i, r := range rems {
|
||||
remoteNames[i] = r.Name
|
||||
}
|
||||
return PRRefs{}, fmt.Errorf("no remote for %q found in %q", parsedPushRevision, strings.Join(remoteNames, ", "))
|
||||
return PullRequestRefs{}, fmt.Errorf("no remote for %q found in %q", parsedPushRevision, strings.Join(remoteNames, ", "))
|
||||
}
|
||||
|
||||
// We assume the PR's branch name is the same as whatever f.BranchFn() returned earlier
|
||||
|
|
|
|||
|
|
@ -676,15 +676,15 @@ func TestParsePRRefs(t *testing.T) {
|
|||
currentBranchName string
|
||||
baseRefRepo ghrepo.Interface
|
||||
rems context.Remotes
|
||||
wantPRRefs PRRefs
|
||||
wantPRRefs PullRequestRefs
|
||||
wantErr error
|
||||
}{
|
||||
{
|
||||
name: "When the branch is called 'blueberries' with an empty branch config, it returns the correct PRRefs",
|
||||
name: "When the branch is called 'blueberries' with an empty branch config, it returns the correct PullRequestRefs",
|
||||
branchConfig: git.BranchConfig{},
|
||||
currentBranchName: "blueberries",
|
||||
baseRefRepo: remoteOrigin.Repo,
|
||||
wantPRRefs: PRRefs{
|
||||
wantPRRefs: PullRequestRefs{
|
||||
BranchName: "blueberries",
|
||||
HeadRepo: remoteOrigin.Repo,
|
||||
BaseRepo: remoteOrigin.Repo,
|
||||
|
|
@ -692,11 +692,11 @@ func TestParsePRRefs(t *testing.T) {
|
|||
wantErr: nil,
|
||||
},
|
||||
{
|
||||
name: "When the branch is called 'otherBranch' with an empty branch config, it returns the correct PRRefs",
|
||||
name: "When the branch is called 'otherBranch' with an empty branch config, it returns the correct PullRequestRefs",
|
||||
branchConfig: git.BranchConfig{},
|
||||
currentBranchName: "otherBranch",
|
||||
baseRefRepo: remoteOrigin.Repo,
|
||||
wantPRRefs: PRRefs{
|
||||
wantPRRefs: PullRequestRefs{
|
||||
BranchName: "otherBranch",
|
||||
HeadRepo: remoteOrigin.Repo,
|
||||
BaseRepo: remoteOrigin.Repo,
|
||||
|
|
@ -711,7 +711,7 @@ func TestParsePRRefs(t *testing.T) {
|
|||
rems: context.Remotes{
|
||||
&remoteOrigin,
|
||||
},
|
||||
wantPRRefs: PRRefs{
|
||||
wantPRRefs: PullRequestRefs{
|
||||
BranchName: "pushBranch",
|
||||
HeadRepo: remoteOrigin.Repo,
|
||||
BaseRepo: remoteOrigin.Repo,
|
||||
|
|
@ -727,7 +727,7 @@ func TestParsePRRefs(t *testing.T) {
|
|||
&remoteUpstream,
|
||||
&remoteOther,
|
||||
},
|
||||
wantPRRefs: PRRefs{},
|
||||
wantPRRefs: PullRequestRefs{},
|
||||
wantErr: fmt.Errorf("no remote for %q found in %q", "origin/differentPushBranch", "upstream, other"),
|
||||
},
|
||||
{
|
||||
|
|
@ -738,7 +738,7 @@ func TestParsePRRefs(t *testing.T) {
|
|||
rems: context.Remotes{
|
||||
&remoteOther,
|
||||
},
|
||||
wantPRRefs: PRRefs{
|
||||
wantPRRefs: PullRequestRefs{
|
||||
BranchName: "pushBranch",
|
||||
HeadRepo: remoteOther.Repo,
|
||||
BaseRepo: remoteOrigin.Repo,
|
||||
|
|
@ -746,7 +746,7 @@ func TestParsePRRefs(t *testing.T) {
|
|||
wantErr: nil,
|
||||
},
|
||||
{
|
||||
name: "When the push remote is the same as the baseRepo, it returns the baseRepo as the PRRefs HeadRepo",
|
||||
name: "When the push remote is the same as the baseRepo, it returns the baseRepo as the PullRequestRefs HeadRepo",
|
||||
branchConfig: git.BranchConfig{
|
||||
PushRemoteName: remoteOrigin.Remote.Name,
|
||||
},
|
||||
|
|
@ -756,7 +756,7 @@ func TestParsePRRefs(t *testing.T) {
|
|||
&remoteOrigin,
|
||||
&remoteUpstream,
|
||||
},
|
||||
wantPRRefs: PRRefs{
|
||||
wantPRRefs: PullRequestRefs{
|
||||
BranchName: "blueberries",
|
||||
HeadRepo: remoteOrigin.Repo,
|
||||
BaseRepo: remoteOrigin.Repo,
|
||||
|
|
@ -764,7 +764,7 @@ func TestParsePRRefs(t *testing.T) {
|
|||
wantErr: nil,
|
||||
},
|
||||
{
|
||||
name: "When the push remote is different from the baseRepo, it returns the push remote repo as the PRRefs HeadRepo",
|
||||
name: "When the push remote is different from the baseRepo, it returns the push remote repo as the PullRequestRefs HeadRepo",
|
||||
branchConfig: git.BranchConfig{
|
||||
PushRemoteName: remoteOrigin.Remote.Name,
|
||||
},
|
||||
|
|
@ -774,7 +774,7 @@ func TestParsePRRefs(t *testing.T) {
|
|||
&remoteOrigin,
|
||||
&remoteUpstream,
|
||||
},
|
||||
wantPRRefs: PRRefs{
|
||||
wantPRRefs: PullRequestRefs{
|
||||
BranchName: "blueberries",
|
||||
HeadRepo: remoteOrigin.Repo,
|
||||
BaseRepo: remoteUpstream.Repo,
|
||||
|
|
@ -782,7 +782,7 @@ func TestParsePRRefs(t *testing.T) {
|
|||
wantErr: nil,
|
||||
},
|
||||
{
|
||||
name: "When the push remote defined by a URL and the baseRepo is different from the push remote, it returns the push remote repo as the PRRefs HeadRepo",
|
||||
name: "When the push remote defined by a URL and the baseRepo is different from the push remote, it returns the push remote repo as the PullRequestRefs HeadRepo",
|
||||
branchConfig: git.BranchConfig{
|
||||
PushRemoteURL: remoteOrigin.Remote.FetchURL,
|
||||
},
|
||||
|
|
@ -792,7 +792,7 @@ func TestParsePRRefs(t *testing.T) {
|
|||
&remoteOrigin,
|
||||
&remoteUpstream,
|
||||
},
|
||||
wantPRRefs: PRRefs{
|
||||
wantPRRefs: PullRequestRefs{
|
||||
BranchName: "blueberries",
|
||||
HeadRepo: remoteOrigin.Repo,
|
||||
BaseRepo: remoteUpstream.Repo,
|
||||
|
|
@ -812,7 +812,7 @@ func TestParsePRRefs(t *testing.T) {
|
|||
&remoteOrigin,
|
||||
&remoteUpstream,
|
||||
},
|
||||
wantPRRefs: PRRefs{
|
||||
wantPRRefs: PullRequestRefs{
|
||||
BranchName: "blue-upstream-berries",
|
||||
HeadRepo: remoteUpstream.Repo,
|
||||
BaseRepo: remoteOrigin.Repo,
|
||||
|
|
@ -832,7 +832,7 @@ func TestParsePRRefs(t *testing.T) {
|
|||
&remoteOrigin,
|
||||
&remoteUpstream,
|
||||
},
|
||||
wantPRRefs: PRRefs{
|
||||
wantPRRefs: PullRequestRefs{
|
||||
BranchName: "blue-upstream-berries",
|
||||
HeadRepo: remoteUpstream.Repo,
|
||||
BaseRepo: remoteOrigin.Repo,
|
||||
|
|
@ -840,7 +840,7 @@ func TestParsePRRefs(t *testing.T) {
|
|||
wantErr: nil,
|
||||
},
|
||||
{
|
||||
name: "When remote.pushDefault is set, it returns the correct PRRefs",
|
||||
name: "When remote.pushDefault is set, it returns the correct PullRequestRefs",
|
||||
branchConfig: git.BranchConfig{},
|
||||
remotePushDefault: remoteUpstream.Remote.Name,
|
||||
currentBranchName: "blueberries",
|
||||
|
|
@ -849,7 +849,7 @@ func TestParsePRRefs(t *testing.T) {
|
|||
&remoteOrigin,
|
||||
&remoteUpstream,
|
||||
},
|
||||
wantPRRefs: PRRefs{
|
||||
wantPRRefs: PullRequestRefs{
|
||||
BranchName: "blueberries",
|
||||
HeadRepo: remoteUpstream.Repo,
|
||||
BaseRepo: remoteOrigin.Repo,
|
||||
|
|
@ -857,7 +857,7 @@ func TestParsePRRefs(t *testing.T) {
|
|||
wantErr: nil,
|
||||
},
|
||||
{
|
||||
name: "When the remote name is set on the branch, it returns the correct PRRefs",
|
||||
name: "When the remote name is set on the branch, it returns the correct PullRequestRefs",
|
||||
branchConfig: git.BranchConfig{
|
||||
RemoteName: remoteUpstream.Remote.Name,
|
||||
},
|
||||
|
|
@ -867,7 +867,7 @@ func TestParsePRRefs(t *testing.T) {
|
|||
&remoteOrigin,
|
||||
&remoteUpstream,
|
||||
},
|
||||
wantPRRefs: PRRefs{
|
||||
wantPRRefs: PullRequestRefs{
|
||||
BranchName: "blueberries",
|
||||
HeadRepo: remoteUpstream.Repo,
|
||||
BaseRepo: remoteOrigin.Repo,
|
||||
|
|
@ -875,7 +875,7 @@ func TestParsePRRefs(t *testing.T) {
|
|||
wantErr: nil,
|
||||
},
|
||||
{
|
||||
name: "When the remote URL is set on the branch, it returns the correct PRRefs",
|
||||
name: "When the remote URL is set on the branch, it returns the correct PullRequestRefs",
|
||||
branchConfig: git.BranchConfig{
|
||||
RemoteURL: remoteUpstream.Remote.FetchURL,
|
||||
},
|
||||
|
|
@ -885,7 +885,7 @@ func TestParsePRRefs(t *testing.T) {
|
|||
&remoteOrigin,
|
||||
&remoteUpstream,
|
||||
},
|
||||
wantPRRefs: PRRefs{
|
||||
wantPRRefs: PullRequestRefs{
|
||||
BranchName: "blueberries",
|
||||
HeadRepo: remoteUpstream.Repo,
|
||||
BaseRepo: remoteOrigin.Repo,
|
||||
|
|
@ -911,12 +911,12 @@ func TestPRRefs_GetPRHeadLabel(t *testing.T) {
|
|||
upstreamRepo := ghrepo.New("UPSTREAMOWNER", "REPO")
|
||||
tests := []struct {
|
||||
name string
|
||||
prRefs PRRefs
|
||||
prRefs PullRequestRefs
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "When the HeadRepo and BaseRepo match, it returns the branch name",
|
||||
prRefs: PRRefs{
|
||||
prRefs: PullRequestRefs{
|
||||
BranchName: "blueberries",
|
||||
HeadRepo: originRepo,
|
||||
BaseRepo: originRepo,
|
||||
|
|
@ -925,7 +925,7 @@ func TestPRRefs_GetPRHeadLabel(t *testing.T) {
|
|||
},
|
||||
{
|
||||
name: "When the HeadRepo and BaseRepo do not match, it returns the prepended HeadRepo owner to the branch name",
|
||||
prRefs: PRRefs{
|
||||
prRefs: PullRequestRefs{
|
||||
BranchName: "blueberries",
|
||||
HeadRepo: originRepo,
|
||||
BaseRepo: upstreamRepo,
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ func statusRun(opts *StatusOptions) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Suppressing these errors as we have other means of computing the PRRefs when these fail.
|
||||
// Suppressing these errors as we have other means of computing the PullRequestRefs when these fail.
|
||||
parsedPushRevision, _ := opts.GitClient.ParsePushRevision(ctx, currentBranchName)
|
||||
|
||||
remotePushDefault, err := opts.GitClient.RemotePushDefault(ctx)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue