(opts *CreateOptions)
| 708 | } |
| 709 | |
| 710 | func NewCreateContext(opts *CreateOptions) (*CreateContext, error) { |
| 711 | httpClient, err := opts.HttpClient() |
| 712 | if err != nil { |
| 713 | return nil, err |
| 714 | } |
| 715 | client := api.NewClientFromHTTP(httpClient) |
| 716 | |
| 717 | remotes, err := getRemotes(opts) |
| 718 | if err != nil { |
| 719 | return nil, err |
| 720 | } |
| 721 | |
| 722 | resolvedRemotes, err := ghContext.ResolveRemotesToRepos(remotes, client, opts.RepoOverride) |
| 723 | if err != nil { |
| 724 | return nil, err |
| 725 | } |
| 726 | |
| 727 | var baseRepo *api.Repository |
| 728 | if br, err := resolvedRemotes.BaseRepo(opts.IO); err == nil { |
| 729 | if r, ok := br.(*api.Repository); ok { |
| 730 | baseRepo = r |
| 731 | } else { |
| 732 | // TODO: if RepoNetwork is going to be requested anyway in `repoContext.HeadRepos()`, |
| 733 | // consider piggybacking on that result instead of performing a separate lookup |
| 734 | baseRepo, err = api.GitHubRepo(client, br) |
| 735 | if err != nil { |
| 736 | return nil, err |
| 737 | } |
| 738 | } |
| 739 | } else { |
| 740 | return nil, err |
| 741 | } |
| 742 | |
| 743 | // This closure provides an easy way to instantiate a CreateContext with everything other than |
| 744 | // the refs. This probably indicates that CreateContext could do with some rework, but the refactor |
| 745 | // to introduce PRRefs is already large enough. |
| 746 | var newCreateContext = func(refs creationRefs) *CreateContext { |
| 747 | baseTrackingBranch := refs.BaseRef() |
| 748 | |
| 749 | // The baseTrackingBranch is used later for a command like: |
| 750 | // `git commit upstream/main feature` in order to create a PR message showing the commits |
| 751 | // between these two refs. I'm not really sure what is expected to happen if we don't have a remote, |
| 752 | // which seems like it would be possible with a command `gh pr create --repo owner/repo-that-is-not-a-remote`. |
| 753 | // In that case, we might just have a mess? In any case, this is what the old code did, so I don't want to change |
| 754 | // it as part of an already large refactor. |
| 755 | baseRemote, _ := resolvedRemotes.RemoteForRepo(baseRepo) |
| 756 | if baseRemote != nil { |
| 757 | baseTrackingBranch = fmt.Sprintf("%s/%s", baseRemote.Name, baseTrackingBranch) |
| 758 | } |
| 759 | |
| 760 | return &CreateContext{ |
| 761 | ResolvedRemotes: resolvedRemotes, |
| 762 | Client: client, |
| 763 | GitClient: opts.GitClient, |
| 764 | PRRefs: refs, |
| 765 | BaseTrackingBranch: baseTrackingBranch, |
| 766 | } |
| 767 | } |
no test coverage detected