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

Function extractRegionFromGitRemote

detect/region.go:48–62  ·  view source on GitHub ↗

extractRegionFromGitRemote returns region name from a Git remote URL only if the region is a valid Scalingo region, returns an empty string othervise

(ctx context.Context, url string, rc *config.RegionsCache)

Source from the content-addressed store, hash-verified

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
48func extractRegionFromGitRemote(ctx context.Context, url string, rc *config.RegionsCache) (string, error) {
49 // Extract url part from the git remote
50 // e.g.: git@ssh.osc-fr1.scalingo.com:app-name.git -> ssh.osc-fr1.scalingo.com
51 r := regexp.MustCompile(`git@(.*)\:.*`)
52 matches := r.FindStringSubmatch(url)
53 if len(matches) > 0 {
54 for _, region := range rc.Regions {
55 if matches[1] == strings.Split(region.SSH, ":")[0] {
56 return region.Name, nil
57 }
58 }
59 return "", errors.Newf(ctx, "[detect] no valid region could be found in the Git remote")
60 }
61 return "", errors.Newf(ctx, "[detect] could not extract URL from Git remote")
62}

Callers 2

GetRegionFromGitRemoteFunction · 0.85

Calls

no outgoing calls

Tested by 1