MCPcopy
hub / github.com/cli/cli / TryDetermineDefaultPRHead

Function TryDetermineDefaultPRHead

pkg/cmd/pr/shared/find_refs_resolution.go:185–208  ·  view source on GitHub ↗

TryDetermineDefaultPRHead is a thin wrapper around determineDefaultPushTarget, which attempts to convert a present remote into a resolved repository. If the remote is not present, we indicate that to the caller by returning a None value for the repo.

(gitClient GitConfigClient, remoteToRepo remoteToRepoResolver, branch string)

Source from the content-addressed store, hash-verified

183// a present remote into a resolved repository. If the remote is not present, we indicate that to the caller
184// by returning a None value for the repo.
185func TryDetermineDefaultPRHead(gitClient GitConfigClient, remoteToRepo remoteToRepoResolver, branch string) (DefaultPRHead, error) {
186 pushTarget, err := tryDetermineDefaultPushTarget(gitClient, branch)
187 if err != nil {
188 return DefaultPRHead{}, err
189 }
190
191 // If we have no remote, let the caller decide what to do by indicating that with a None.
192 if pushTarget.remote.IsNone() {
193 return DefaultPRHead{
194 Repo: o.None[ghrepo.Interface](),
195 BranchName: pushTarget.branchName,
196 }, nil
197 }
198
199 repo, err := remoteToRepo.resolve(pushTarget.remote.Unwrap())
200 if err != nil {
201 return DefaultPRHead{}, err
202 }
203
204 return DefaultPRHead{
205 Repo: o.Some(repo),
206 BranchName: pushTarget.branchName,
207 }, nil
208}
209
210// remote represents the value of the remote key in a branch's git configuration.
211// This value may be a name or a URL, both of which are strings, but are unfortunately

Callers 3

NewCreateContextFunction · 0.92

Calls 4

IsNoneMethod · 0.80
resolveMethod · 0.80
UnwrapMethod · 0.45

Tested by 1