Skip to content

Commit

Permalink
fix(cli): update git branch and commit regex to support non / links
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalbreuninger committed Nov 27, 2023
1 parent c9a081a commit 4f03d13
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package git

import (
"context"
"fmt"
"os"
"os/exec"
"regexp"
Expand All @@ -17,7 +18,7 @@ const (
)

var (
branchRegEx = regexp.MustCompile(`^([^@]*(?:git@)?[^@/]+/[^@/]+/[^@/]+)@([a-zA-Z0-9\./\-\_]+)$`)
branchRegEx = regexp.MustCompile(`^([^@]*(?:git@)?[^@/]+/[^@/]+/?[^@/]+)@([a-zA-Z0-9\./\-\_]+)$`)
commitRegEx = regexp.MustCompile(`^([^@]*(?:git@)?[^@/]+/[^@]+)` + regexp.QuoteMeta(CommitDelimiter) + `([a-zA-Z0-9]+)$`)
prReferenceRegEx = regexp.MustCompile(`^([^@]*(?:git@)?[^@/]+/[^@]+)@(` + PullRequestReference + `)$`)
)
Expand All @@ -40,6 +41,7 @@ func NormalizeRepository(str string) (string, string, string, string) {
if match := prReferenceRegEx.FindStringSubmatch(str); match != nil {
str = match[1]
prReference = match[2]
fmt.Println("PR:", str, prReference)

return str, prReference, "", ""
}
Expand All @@ -50,13 +52,15 @@ func NormalizeRepository(str string) (string, string, string, string) {
str = match[1]
branch = match[2]
}
fmt.Println("Branch:", str, branch)

// resolve commit hash
commit := ""
if match := commitRegEx.FindStringSubmatch(str); match != nil {
str = match[1]
commit = match[2]
}
fmt.Println("Commit:", str, commit)

return str, prReference, branch, commit
}
Expand Down

0 comments on commit 4f03d13

Please sign in to comment.