Skip to content

Commit

Permalink
Update regex
Browse files Browse the repository at this point in the history
  • Loading branch information
bkneis committed Jan 7, 2025
1 parent c670c27 commit 4e19c86
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const (
// WARN: Make sure this matches the regex in /desktop/src/views/Workspaces/CreateWorkspace/CreateWorkspaceInput.tsx!
var (
// Updated regex pattern to support SSH-style Git URLs
repoBaseRegEx = `((?:(?:https?|git|ssh|file):\/\/)?\/?(?:[^@\/\n]+@)?(?:[^:\/\n]+)(?:[:\/][^\/\n]+)+(?:\.git)?)`
branchRegEx = regexp.MustCompile(`^` + repoBaseRegEx + `@([a-zA-Z0-9\./\-\_]+)$`)
repoBaseRegEx = `((?:(?:https?|git|ssh|file):\/\/)?(?:[^:@\/\n]+(?::[^@\/\n]+)?@)?(?:[^:\/\n]+|(?:\/[^\/\n]+)+)(?:[:\/][^\/\n]+)+(?:\.git))`
branchRegEx = regexp.MustCompile(`^` + repoBaseRegEx + `(?:@([a-zA-Z0-9\./\-\_]+))?$`)
commitRegEx = regexp.MustCompile(`^` + repoBaseRegEx + regexp.QuoteMeta(CommitDelimiter) + `([a-zA-Z0-9]+)$`)
prReferenceRegEx = regexp.MustCompile(`^` + repoBaseRegEx + `@(` + PullRequestReference + `)$`)
subPathRegEx = regexp.MustCompile(`^` + repoBaseRegEx + regexp.QuoteMeta(SubPathDelimiter) + `([a-zA-Z0-9\./\-\_]+)$`)
Expand Down Expand Up @@ -58,17 +58,8 @@ func NormalizeRepository(str string) (string, string, string, string, string) {
// resolve branch
branch := ""
if match := branchRegEx.FindStringSubmatch(str); match != nil {
// Check if basic auth is used, if so concat the user info and URL
if strings.Contains(match[1], ":") {
str = match[1] + "@" + match[2]
if innerMatch := branchRegEx.FindStringSubmatch(str); innerMatch != nil {
str = innerMatch[1]
branch = innerMatch[2]
}
} else {
str = match[1]
branch = match[2]
}
str = match[1]
branch = match[2]
}

// resolve commit hash
Expand Down

0 comments on commit 4e19c86

Please sign in to comment.