MCPcopy Create free account
hub / github.com/Scalingo/cli / ScalingoGitRemotes

Function ScalingoGitRemotes

utils/git.go:55–83  ·  view source on GitHub ↗

ScalingoGitRemotes returns an array of remote URLs (*.scalingo.com) from a git repository

(ctx context.Context, directory string)

Source from the content-addressed store, hash-verified

53
54// ScalingoGitRemotes returns an array of remote URLs (*.scalingo.com) from a git repository <directory>
55func ScalingoGitRemotes(ctx context.Context, directory string) ([]*git.Remote, error) {
56 repo, err := git.PlainOpen(directory)
57 if err != nil {
58 return nil, errors.Wrapf(ctx, err, "fail to initialize the Git repository")
59 }
60
61 remotes, err := repo.Remotes()
62 if err != nil {
63 return nil, errors.Wrapf(ctx, err, "fail to list the remotes")
64 }
65
66 matchedRemotes := []*git.Remote{}
67 for _, remote := range remotes {
68 if len(remote.Config().URLs) == 0 {
69 continue
70 }
71
72 remoteURL := remote.Config().URLs[0]
73 matched, err := regexp.Match(".*scalingo.com:.*.git", []byte(remoteURL))
74 if err != nil || !matched {
75 continue
76 }
77
78 debug.Println("git remote found:", remoteURL)
79 matchedRemotes = append(matchedRemotes, remote)
80 }
81
82 return matchedRemotes, nil
83}
84
85// AddGitRemote add a remote URL to the current git repository
86func AddGitRemote(ctx context.Context, url string, name string) error {

Callers 3

GetAppNameFromGitRemoteFunction · 0.92
GetRegionFromGitRemoteFunction · 0.92
ScalingoRepoAutoCompleteFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected