CI: change regex to accomodate new branching stategy in enterprise (#59429)

change regex to accomodate new branching stategy in enterprise
This commit is contained in:
Kevin Minehart 2022-11-28 12:09:10 -06:00 committed by GitHub
parent d6dd86d273
commit 560b595ef2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 5 deletions

View File

@ -60,7 +60,7 @@ func NewGitHubClient(ctx context.Context, token string) *github.Client {
} }
func PRCheckRegexp() *regexp.Regexp { func PRCheckRegexp() *regexp.Regexp {
reBranch, err := regexp.Compile(`^pr-check-([0-9]+)\/(.+)$`) reBranch, err := regexp.Compile(`^prc-([0-9]+)-([A-Za-z0-9]+)\/(.+)$`)
if err != nil { if err != nil {
panic(fmt.Sprintf("Failed to compile regexp: %s", err)) panic(fmt.Sprintf("Failed to compile regexp: %s", err))
} }

View File

@ -8,18 +8,49 @@ import (
) )
func TestPRCheckRegexp(t *testing.T) { func TestPRCheckRegexp(t *testing.T) {
type match struct {
String string
Commit string
Branch string
PR string
}
var ( var (
shouldMatch = []string{"pr-check-1/branch-name", "pr-check-111/branch/name", "pr-check-102930122/branch-name"} shouldMatch = []match{
shouldNotMatch = []string{"pr-check-a/branch", "km/test", "test", "pr-check", "pr-check/test", "price"} {
String: "prc-1-a1b2c3d4/branch-name",
Branch: "branch-name",
Commit: "a1b2c3d4",
PR: "1",
},
{
String: "prc-111-a1b2c3d4/branch/name",
Branch: "branch/name",
Commit: "a1b2c3d4",
PR: "111",
},
{
String: "prc-102930122-a1b2c3d4/branch-name",
Branch: "branch-name",
Commit: "a1b2c3d4",
PR: "102930122",
},
}
shouldNotMatch = []string{"prc-a/branch", "km/test", "test", "prc", "prc/test", "price"}
) )
regex := git.PRCheckRegexp() regex := git.PRCheckRegexp()
for _, v := range shouldMatch { for _, v := range shouldMatch {
assert.Truef(t, regex.MatchString(v), "regex should match %s", v) assert.Truef(t, regex.MatchString(v.String), "regex '%s' should match %s", regex.String(), v)
m := regex.FindStringSubmatch(v.String)
assert.Equal(t, m[1], v.PR)
assert.Equal(t, m[2], v.Commit)
assert.Equal(t, m[3], v.Branch)
} }
for _, v := range shouldNotMatch { for _, v := range shouldNotMatch {
assert.False(t, regex.MatchString(v), "regex should not match %s", v) assert.False(t, regex.MatchString(v), "regex '%s' should not match %s", regex.String(), v)
} }
} }