From 62d2167f3b3fa956f8c5aaff3c660f386092db63 Mon Sep 17 00:00:00 2001 From: Mike Beaumont Date: Sat, 13 Nov 2021 15:56:31 +0100 Subject: [PATCH] Fix github SSH regex for missing .git extension (#871) * tests(pkg/common) add failing test case for SSH git URL * fix(pkg/common) github SSH regex for missing .git extension Co-authored-by: Ryan --- pkg/common/git.go | 4 ++-- pkg/common/git_test.go | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/common/git.go b/pkg/common/git.go index b1e1f54..b5e288f 100644 --- a/pkg/common/git.go +++ b/pkg/common/git.go @@ -26,7 +26,7 @@ var ( codeCommitHTTPRegex = regexp.MustCompile(`^https?://git-codecommit\.(.+)\.amazonaws.com/v1/repos/(.+)$`) codeCommitSSHRegex = regexp.MustCompile(`ssh://git-codecommit\.(.+)\.amazonaws.com/v1/repos/(.+)$`) githubHTTPRegex = regexp.MustCompile(`^https?://.*github.com.*/(.+)/(.+?)(?:.git)?$`) - githubSSHRegex = regexp.MustCompile(`github.com[:/](.+)/(.+).git$`) + githubSSHRegex = regexp.MustCompile(`github.com[:/](.+)/(.+?)(?:.git)?$`) cloneLock sync.Mutex ) @@ -185,7 +185,7 @@ 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)) + gheSSHRegex := regexp.MustCompile(fmt.Sprintf(`%s[:/](.+)/(.+?)(?:.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/pkg/common/git_test.go b/pkg/common/git_test.go index 7abb9ed..97829db 100644 --- a/pkg/common/git_test.go +++ b/pkg/common/git_test.go @@ -26,6 +26,7 @@ func TestFindGitSlug(t *testing.T) { {"https://git-codecommit.us-east-1.amazonaws.com/v1/repos/my-repo-name", "CodeCommit", "my-repo-name"}, {"ssh://git-codecommit.us-west-2.amazonaws.com/v1/repos/my-repo", "CodeCommit", "my-repo"}, {"git@github.com:nektos/act.git", "GitHub", "nektos/act"}, + {"git@github.com:nektos/act", "GitHub", "nektos/act"}, {"https://github.com/nektos/act.git", "GitHub", "nektos/act"}, {"http://github.com/nektos/act.git", "GitHub", "nektos/act"}, {"https://github.com/nektos/act", "GitHub", "nektos/act"},