ScalingoGitRemotes returns an array of remote URLs (*.scalingo.com) from a git repository
(ctx context.Context, directory string)
| 53 | |
| 54 | // ScalingoGitRemotes returns an array of remote URLs (*.scalingo.com) from a git repository <directory> |
| 55 | func 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 |
| 86 | func AddGitRemote(ctx context.Context, url string, name string) error { |
no outgoing calls
no test coverage detected