| 37 | } |
| 38 | |
| 39 | func 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 | |
| 68 | func RepositoryURL(repoType model.RepositoryType, owner, name string) string { |
| 69 | switch repoType { |