diff --git a/act/common/git/git.go b/act/common/git/git.go index 10506479..3d29b038 100644 --- a/act/common/git/git.go +++ b/act/common/git/git.go @@ -209,7 +209,12 @@ func findGitSlug(url string, githubInstance string) (string, string, error) { return "GitHub", fmt.Sprintf("%s/%s", matches[1], matches[2]), nil } else if githubInstance != "github.com" { gheHTTPRegex := regexp.MustCompile(fmt.Sprintf(`^https?://%s/(.+)/(.+?)(?:.git)?$`, githubInstance)) - gheSSHRegex := regexp.MustCompile(fmt.Sprintf(`%s[:/](.+)/(.+?)(?:.git)?$`, githubInstance)) + // Examples: + // - `code.forgejo.org/forgejo/act` + // - `code.forgejo.org:22/forgejo/act` + // - `code.forgejo.org:forgejo/act` + // - `code.forgejo.org:/forgejo/act` + gheSSHRegex := regexp.MustCompile(fmt.Sprintf(`%s(?::\d+/|:|/|:/)([^/].+)/(.+?)(?:.git)?$`, githubInstance)) if matches := gheHTTPRegex.FindStringSubmatch(url); matches != nil { return "GitHubEnterprise", fmt.Sprintf("%s/%s", matches[1], matches[2]), nil } else if matches := gheSSHRegex.FindStringSubmatch(url); matches != nil { diff --git a/act/common/git/git_test.go b/act/common/git/git_test.go index 78324eb8..5d37c32b 100644 --- a/act/common/git/git_test.go +++ b/act/common/git/git_test.go @@ -32,10 +32,19 @@ func TestFindGitSlug(t *testing.T) { {"http://github.com/nektos/act", "GitHub", "nektos/act"}, {"git+ssh://git@github.com/owner/repo.git", "GitHub", "owner/repo"}, {"http://myotherrepo.com/act.git", "", "http://myotherrepo.com/act.git"}, + {"ssh://git@example.com/forgejo/act.git", "GitHubEnterprise", "forgejo/act"}, + {"ssh://git@example.com:2222/forgejo/act.git", "GitHubEnterprise", "forgejo/act"}, + {"ssh://git@example.com:forgejo/act.git", "GitHubEnterprise", "forgejo/act"}, + {"ssh://git@example.com:/forgejo/act.git", "GitHubEnterprise", "forgejo/act"}, } for _, tt := range slugTests { - provider, slug, err := findGitSlug(tt.url, "github.com") + instance := "example.com" + if tt.provider == "GitHub" { + instance = "github.com" + } + + provider, slug, err := findGitSlug(tt.url, instance) assert.NoError(err) assert.Equal(tt.provider, provider)