Skip to content

Commit 7a9d020

Browse files
authored
[sc-169181] filepattern alias supports doublestar in globs (launchdarkly#281)
1 parent a5f2bf8 commit 7a9d020

File tree

18 files changed

+2082
-4
lines changed

18 files changed

+2082
-4
lines changed

aliases/alias.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import (
1212
"strings"
1313
"time"
1414

15+
"github.com/bmatcuk/doublestar/v4"
1516
"github.com/iancoleman/strcase"
17+
1618
"github.com/launchdarkly/ld-find-code-refs/internal/helpers"
1719
"github.com/launchdarkly/ld-find-code-refs/internal/log"
1820
"github.com/launchdarkly/ld-find-code-refs/internal/validation"
@@ -66,7 +68,7 @@ func generateAlias(a options.Alias, flag, dir string, allFileContents map[string
6668
fileContents := []byte{}
6769
for _, path := range a.Paths {
6870
absGlob := filepath.Join(dir, path)
69-
matches, err := filepath.Glob(absGlob)
71+
matches, err := doublestar.FilepathGlob(absGlob)
7072
if err != nil {
7173
return nil, fmt.Errorf("filepattern '%s': could not process path glob '%s'", aliasId, absGlob)
7274
}
@@ -133,7 +135,7 @@ func processFileContent(aliases []options.Alias, dir string) (map[string][]byte,
133135
paths := []string{}
134136
for _, glob := range a.Paths {
135137
absGlob := filepath.Join(dir, glob)
136-
matches, err := filepath.Glob(absGlob)
138+
matches, err := doublestar.FilepathGlob(absGlob)
137139
if err != nil {
138140
return nil, fmt.Errorf("filepattern '%s': could not process path glob '%s'", aliasId, absGlob)
139141
}

aliases/alias_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var allNamingConventions = []o.Alias{
2323
var allSomeFlagNamingConventionAliases = slice("anyKindOfKey", "AnyKindOfKey", "any_kind_of_key", "ANY_KIND_OF_KEY", "any-kind-of-key", "any.kind.of.key")
2424

2525
const (
26+
testFlagAlias = "test-flag"
2627
testFlagKey = "someFlag"
2728
testFlagKey2 = "anotherFlag"
2829
testFlagAliasKey = "AnyKind.of_key"
@@ -87,7 +88,7 @@ func Test_GenerateAliases(t *testing.T) {
8788
aliases: []o.Alias{
8889
fileWildPattern(testFlagKey),
8990
},
90-
want: map[string][]string{testWildFlagKey: slice("WILD_FLAG"), testFlagKey: slice("SOME_FLAG")},
91+
want: map[string][]string{testWildFlagKey: slice("WILD_FLAG", "WILD_FLAG_SECOND_ALIAS"), testFlagKey: slice("SOME_FLAG")},
9192
},
9293
// TODO
9394
// {
@@ -207,7 +208,7 @@ func fileExactPattern(flag string) o.Alias {
207208
func fileWildPattern(flag string) o.Alias {
208209
a := alias(o.FilePattern)
209210
pattern := "(\\w+)\\s= 'FLAG_KEY'"
210-
a.Paths = []string{"testdata/*/*.txt", "testdata/*.txt"}
211+
a.Paths = []string{"testdata/**/*.txt"}
211212
a.Patterns = []string{pattern}
212213
return a
213214
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
WILD_FLAG_SECOND_ALIAS = 'wildFlag'

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/launchdarkly/ld-find-code-refs
33
go 1.18
44

55
require (
6+
github.com/bmatcuk/doublestar/v4 v4.4.0
67
github.com/go-git/go-git/v5 v5.4.2
78
github.com/hashicorp/go-retryablehttp v0.7.1
89
github.com/iancoleman/strcase v0.2.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo
4949
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
5050
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
5151
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
52+
github.com/bmatcuk/doublestar/v4 v4.4.0 h1:LmAwNwhjEbYtyVLzjcP/XeVw4nhuScHGkF/XWXnvIic=
53+
github.com/bmatcuk/doublestar/v4 v4.4.0/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
5254
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
5355
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
5456
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=

vendor/github.com/bmatcuk/doublestar/v4/.codecov.yml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/bmatcuk/doublestar/v4/.gitignore

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/bmatcuk/doublestar/v4/LICENSE

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)