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

Function GetRegionFromGitRemote

detect/region.go:18–44  ·  view source on GitHub ↗

GetRegionFromGitRemote returns the region name extracted from remotes URL of the current Git repository If not found it returns an empty string

(ctx context.Context, c *cli.Command, rc *config.RegionsCache)

Source from the content-addressed store, hash-verified

16// GetRegionFromGitRemote returns the region name extracted from remotes URL of the current Git repository
17// If not found it returns an empty string
18func GetRegionFromGitRemote(ctx context.Context, c *cli.Command, rc *config.RegionsCache) string {
19 remoteName := RemoteNameFromFlags(c)
20
21 if dir, ok := utils.DetectGit(); ok {
22 remotes, err := utils.ScalingoGitRemotes(ctx, dir)
23 if err != nil {
24 debug.Println(err)
25 return ""
26 }
27
28 altRemoteName := "scalingo-" + remoteName
29 for _, remote := range remotes {
30 if remote.Config().Name == remoteName || remote.Config().Name == altRemoteName {
31 region, err := extractRegionFromGitRemote(ctx, remote.Config().URLs[0], rc)
32 if err != nil {
33 debug.Println(err)
34 }
35 debug.Println("[detect] region name is", region)
36 return region
37 }
38 }
39 debug.Println("[detect] fail to find a Scalingo Git remote")
40 return ""
41 }
42 debug.Println("[detect] git repository cannot be found")
43 return ""
44}
45
46// extractRegionFromGitRemote returns region name from a Git remote URL
47// only if the region is a valid Scalingo region, returns an empty string othervise

Callers 1

regionalCommandActionFunction · 0.92

Calls 4

DetectGitFunction · 0.92
ScalingoGitRemotesFunction · 0.92
RemoteNameFromFlagsFunction · 0.85

Tested by

no test coverage detected