GetAppNameFromGitRemote searches into the current directory and its parent for a remote named remoteName or scalingo- . It returns the application name and an error.
(ctx context.Context, directory string, remoteName string)
| 203 | // |
| 204 | // It returns the application name and an error. |
| 205 | func GetAppNameFromGitRemote(ctx context.Context, directory string, remoteName string) (string, error) { |
| 206 | remotes, err := utils.ScalingoGitRemotes(ctx, directory) |
| 207 | if err != nil { |
| 208 | return "", errors.Wrapf(ctx, err, "list git remotes from %s", directory) |
| 209 | } |
| 210 | |
| 211 | altRemoteName := "scalingo-" + remoteName |
| 212 | for _, remote := range remotes { |
| 213 | if remote.Config().Name == remoteName || |
| 214 | remote.Config().Name == altRemoteName { |
| 215 | return extractAppNameFromGitRemote(remote.Config().URLs[0]), nil |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | return "", errors.Newf(ctx, "[detect] Scalingo Git remote hasn't been found") |
| 220 | } |
| 221 | |
| 222 | // RemoteNameFromFlags returns the remote name specified in command flags |
| 223 | func RemoteNameFromFlags(c *cli.Command) string { |
no test coverage detected