-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: regex support for http credentials embedded in remote url
Introduce a modification to the regular expression for repository remote url parsing. Remove parser failure with credentials embedded into http remote urls.
- Loading branch information
Showing
2 changed files
with
29 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,7 @@ func NewGitData(remote string, g GitManager) (GitData, error) { | |
https://[email protected]/namespace/subnamespace/dummy-test-repo.git | ||
git@[email protected]:namespace/subnamespace/dummy-test-repo.git | ||
*/ | ||
re := regexp.MustCompile(`(?:^https?:\/\/|^ssh:\/\/|^git@)(?:[^\/:]+)(?::\d+)?[\/:](.*)\/([^\/]+?)(?:\.git)?$`) | ||
re := regexp.MustCompile(`^(?:git@[^\/:]*|https?:\/\/[^\/]+|ssh:\/\/[^\/:]+)(?::\d+)?[\/:](.*)\/([^\/]+?)(?:\.git)?\/?$`) | ||
matches := re.FindStringSubmatch(url) | ||
if len(matches) != 3 { | ||
return GitData{}, fmt.Errorf("Invalid Git URL format: %s", url) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,27 +101,55 @@ func TestExtractGitInfo_Success(t *testing.T) { | |
projectName: "project-name", | ||
namespace: "namespace-1", | ||
}, | ||
{ | ||
desc: "Project configured in HTTP and under a single folder without .git extension (with embedded credentials)", | ||
remote: "http://username:[email protected]/namespace-1/project-name", | ||
branch: "feature/abc", | ||
projectName: "project-name", | ||
namespace: "namespace-1", | ||
}, | ||
{ | ||
desc: "Project configured in HTTPS and under a single folder", | ||
remote: "https://custom-gitlab.com/namespace-1/project-name.git", | ||
branch: "feature/abc", | ||
projectName: "project-name", | ||
namespace: "namespace-1", | ||
}, | ||
{ | ||
desc: "Project configured in HTTPS and under a single folder (with embedded credentials)", | ||
remote: "https://username:[email protected]/namespace-1/project-name.git", | ||
branch: "feature/abc", | ||
projectName: "project-name", | ||
namespace: "namespace-1", | ||
}, | ||
{ | ||
desc: "Project configured in HTTPS and under a nested folder", | ||
remote: "https://custom-gitlab.com/namespace-1/namespace-2/project-name.git", | ||
branch: "feature/abc", | ||
projectName: "project-name", | ||
namespace: "namespace-1/namespace-2", | ||
}, | ||
{ | ||
desc: "Project configured in HTTPS and under a nested folder (with embedded credentials)", | ||
remote: "https://username:[email protected]/namespace-1/namespace-2/project-name.git", | ||
branch: "feature/abc", | ||
projectName: "project-name", | ||
namespace: "namespace-1/namespace-2", | ||
}, | ||
{ | ||
desc: "Project configured in HTTPS and under two nested folders", | ||
remote: "https://custom-gitlab.com/namespace-1/namespace-2/namespace-3/project-name.git", | ||
branch: "feature/abc", | ||
projectName: "project-name", | ||
namespace: "namespace-1/namespace-2/namespace-3", | ||
}, | ||
{ | ||
desc: "Project configured in HTTPS and under two nested folders (with embedded credentials)", | ||
remote: "https://username:[email protected]/namespace-1/namespace-2/namespace-3/project-name.git", | ||
branch: "feature/abc", | ||
projectName: "project-name", | ||
namespace: "namespace-1/namespace-2/namespace-3", | ||
}, | ||
} | ||
for _, tC := range testCases { | ||
t.Run(tC.desc, func(t *testing.T) { | ||
|