mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-08-16 18:01:34 +00:00
Merge pull request 'fix(git): add support for parsing weirder remote URLs' (#115) from 0x5f/act:fix-weird-remote-urls into main
Reviewed-on: https://code.forgejo.org/forgejo/act/pulls/115 Reviewed-by: earl-warren <earl-warren@noreply.code.forgejo.org>
This commit is contained in:
commit
d56e6c6683
2 changed files with 18 additions and 2 deletions
|
@ -209,7 +209,12 @@ func findGitSlug(url string, githubInstance string) (string, string, error) {
|
||||||
return "GitHub", fmt.Sprintf("%s/%s", matches[1], matches[2]), nil
|
return "GitHub", fmt.Sprintf("%s/%s", matches[1], matches[2]), nil
|
||||||
} else if githubInstance != "github.com" {
|
} else if githubInstance != "github.com" {
|
||||||
gheHTTPRegex := regexp.MustCompile(fmt.Sprintf(`^https?://%s/(.+)/(.+?)(?:.git)?$`, githubInstance))
|
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 {
|
if matches := gheHTTPRegex.FindStringSubmatch(url); matches != nil {
|
||||||
return "GitHubEnterprise", fmt.Sprintf("%s/%s", matches[1], matches[2]), nil
|
return "GitHubEnterprise", fmt.Sprintf("%s/%s", matches[1], matches[2]), nil
|
||||||
} else if matches := gheSSHRegex.FindStringSubmatch(url); matches != nil {
|
} else if matches := gheSSHRegex.FindStringSubmatch(url); matches != nil {
|
||||||
|
|
|
@ -32,10 +32,19 @@ func TestFindGitSlug(t *testing.T) {
|
||||||
{"http://github.com/nektos/act", "GitHub", "nektos/act"},
|
{"http://github.com/nektos/act", "GitHub", "nektos/act"},
|
||||||
{"git+ssh://git@github.com/owner/repo.git", "GitHub", "owner/repo"},
|
{"git+ssh://git@github.com/owner/repo.git", "GitHub", "owner/repo"},
|
||||||
{"http://myotherrepo.com/act.git", "", "http://myotherrepo.com/act.git"},
|
{"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 {
|
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.NoError(err)
|
||||||
assert.Equal(tt.provider, provider)
|
assert.Equal(tt.provider, provider)
|
||||||
|
@ -169,6 +178,8 @@ func TestGitFindRef(t *testing.T) {
|
||||||
dir := filepath.Join(basedir, name)
|
dir := filepath.Join(basedir, name)
|
||||||
require.NoError(t, os.MkdirAll(dir, 0o755))
|
require.NoError(t, os.MkdirAll(dir, 0o755))
|
||||||
require.NoError(t, gitCmd("-C", dir, "init", "--initial-branch=master"))
|
require.NoError(t, gitCmd("-C", dir, "init", "--initial-branch=master"))
|
||||||
|
require.NoError(t, gitCmd("-C", dir, "config", "user.name", "user@example.com"))
|
||||||
|
require.NoError(t, gitCmd("-C", dir, "config", "user.email", "user@example.com"))
|
||||||
require.NoError(t, cleanGitHooks(dir))
|
require.NoError(t, cleanGitHooks(dir))
|
||||||
tt.Prepare(t, dir)
|
tt.Prepare(t, dir)
|
||||||
ref, err := FindGitRef(context.Background(), dir)
|
ref, err := FindGitRef(context.Background(), dir)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue