MCPcopy
hub / github.com/cli/cli / detectGitHubRemote

Function detectGitHubRemote

pkg/cmd/skills/publish/publish.go:944–968  ·  view source on GitHub ↗

detectGitHubRemote attempts to detect the GitHub owner/repo from git remotes in the given directory. Remotes are tried in the order returned by gitClient.Remotes (upstream > github > origin > rest), so the first GitHub-pointing remote wins.

(gitClient *git.Client, dir string)

Source from the content-addressed store, hash-verified

942// gitClient.Remotes (upstream > github > origin > rest), so the first
943// GitHub-pointing remote wins.
944func detectGitHubRemote(gitClient *git.Client, dir string) (*gitHubRemote, error) {
945 if gitClient == nil {
946 return nil, nil
947 }
948
949 dirClient := gitClient.Copy()
950 dirClient.RepoDir = dir
951
952 remotes, err := dirClient.Remotes(context.Background())
953 if err != nil {
954 return nil, nil //nolint:nilerr // failing to list remotes is not an error; it just means no repo detected
955 }
956 for _, r := range remotes {
957 if url, err := dirClient.RemoteURL(context.Background(), r.Name); err == nil {
958 repo, parseErr := parseGitHubURL(url)
959 if parseErr != nil {
960 return nil, parseErr
961 }
962 if repo != nil {
963 return &gitHubRemote{Repo: repo, RemoteName: r.Name}, nil
964 }
965 }
966 }
967 return nil, nil
968}
969
970// parseGitHubURL extracts owner/repo from a GitHub remote URL.
971// Only github.com and GHEC data residency (*.ghe.com) URLs are recognized.

Callers 2

publishRunFunction · 0.85

Calls 4

parseGitHubURLFunction · 0.85
RemoteURLMethod · 0.80
RemotesMethod · 0.65
CopyMethod · 0.45

Tested by 1