MCPcopy Create free account
hub / github.com/encoder-run/operator / SplitRepositoryURL

Function SplitRepositoryURL

pkg/graph/converters/repositories.go:39–66  ·  view source on GitHub ↗
(url string)

Source from the content-addressed store, hash-verified

37}
38
39func SplitRepositoryURL(url string) (v1alpha1.RepositoryType, string, string, error) {
40 // Regular expression to match the URL patterns
41 regex := regexp.MustCompile(`(?:https?://)?(?:www\.)?(?P<type>github|gitlab|bitbucket)\.com/(?P<owner>[^/]+)/(?P<name>[^/.]+)(?:\.git)?`)
42
43 matches := regex.FindStringSubmatch(url)
44 if matches == nil {
45 return "", "", "", errors.New("invalid repository URL")
46 }
47
48 // Extracting matches
49 repositoryType := matches[regex.SubexpIndex("type")]
50 var repoType v1alpha1.RepositoryType
51 switch repositoryType {
52 case "github":
53 repoType = v1alpha1.RepositoryTypeGithub
54 case "gitlab":
55 repoType = v1alpha1.RepositoryTypeGitlab
56 case "bitbucket":
57 repoType = v1alpha1.RepositoryTypeBitbucket
58 default:
59 return "", "", "", fmt.Errorf("unsupported repository type: %s", repositoryType)
60 }
61
62 owner := matches[regex.SubexpIndex("owner")]
63 name := matches[regex.SubexpIndex("name")]
64
65 return repoType, owner, name, nil
66}
67
68func RepositoryURL(repoType model.RepositoryType, owner, name string) string {
69 switch repoType {

Callers 1

addURLFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected