Skip to content

Commit 5e2a089

Browse files
committed
add JfExcludeFoldersOnlyEnv and fix tests
1 parent 85a859a commit 5e2a089

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

jas/common.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,10 @@ func filterUniqueAndConvertToFilesExcludePatterns(excludePatterns []string) []st
426426
uniqueExcludePatterns := datastructures.MakeSet[string]()
427427
for _, excludePattern := range excludePatterns {
428428

429-
// Add ignore for the pattern as-is, not only the pattern as a directory
430-
uniqueExcludePatterns.Add(excludePattern)
431-
429+
if strings.ToLower(os.Getenv(utils.JfExcludeFoldersOnlyEnv)) == "false" {
430+
// Add ignore for the pattern as-is, not only the pattern as a directory
431+
uniqueExcludePatterns.Add(excludePattern)
432+
}
432433
// Avoid adding the pattern as a directory twice
433434
if !strings.HasPrefix(excludePattern, "**/") {
434435
excludePattern = "**/" + excludePattern

jas/common_test.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,19 +285,52 @@ func TestFilterUniqueAndConvertToFilesExcludePatterns(t *testing.T) {
285285
name string
286286
excludePatterns []string
287287
expectedOutput []string
288+
extraEnvVars map[string]string
288289
}{
289290
{
291+
name: "excludePatterns_emptyPatterns",
290292
excludePatterns: []string{},
291293
expectedOutput: []string(nil),
292294
},
293295
{
296+
name: "excludePatterns_defaultBehaviour",
297+
excludePatterns: []string{"*.git*", "*node_modules*", "*target*", "*venv*", "*test*"},
298+
expectedOutput: []string{"**/*.git*/**", "**/*node_modules*/**", "**/*target*/**", "**/*test*/**", "**/*venv*/**"},
299+
},
300+
{
301+
name: "excludePatterns_FolderEnvVarIsFalse",
302+
extraEnvVars: map[string]string{
303+
"JF_EXCLUDE_FOLDERS_ONLY": "false",
304+
},
294305
excludePatterns: []string{"*.git*", "*node_modules*", "*target*", "*venv*", "*test*"},
295306
expectedOutput: []string{"**/*.git*/**", "**/*node_modules*/**", "**/*target*/**", "**/*test*/**", "**/*venv*/**", "*.git*", "*node_modules*", "*target*", "*test*", "*venv*"},
296307
},
308+
{
309+
name: "excludePatterns_FolderEnvVarExistsAndEmpty",
310+
extraEnvVars: map[string]string{
311+
"JF_EXCLUDE_FOLDERS_ONLY": "",
312+
},
313+
excludePatterns: []string{"*.git*", "*node_modules*", "*target*", "*venv*", "*test*"},
314+
expectedOutput: []string{"**/*.git*/**", "**/*node_modules*/**", "**/*target*/**", "**/*test*/**", "**/*venv*/**"},
315+
},
297316
}
298317

318+
var filteredExcludePatterns []string
299319
for _, test := range tests {
300-
filteredExcludePatterns := filterUniqueAndConvertToFilesExcludePatterns(test.excludePatterns)
320+
if len(test.extraEnvVars) > 0 {
321+
for env, envValue := range test.extraEnvVars {
322+
err := os.Setenv(env, envValue)
323+
assert.NoError(t, err)
324+
325+
filteredExcludePatterns = filterUniqueAndConvertToFilesExcludePatterns(test.excludePatterns)
326+
327+
err = os.Unsetenv("JF_EXCLUDE_FOLDERS_ONLY")
328+
assert.NoError(t, err)
329+
}
330+
} else {
331+
filteredExcludePatterns = filterUniqueAndConvertToFilesExcludePatterns(test.excludePatterns)
332+
}
333+
301334
// Sort is needed since we create the response slice from a Set (unordered)
302335
slices.Sort(filteredExcludePatterns)
303336
assert.EqualValues(t, test.expectedOutput, filteredExcludePatterns)

utils/utils.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ const (
3535
JfrogExternalRunIdEnv = "JFROG_CLI_USAGE_RUN_ID"
3636
JfrogExternalJobIdEnv = "JFROG_CLI_USAGE_JOB_ID"
3737
JfrogExternalGitRepoEnv = "JFROG_CLI_USAGE_GIT_REPO"
38+
39+
JfExcludeFoldersOnlyEnv = "JF_EXCLUDE_FOLDERS_ONLY"
3840
)
3941

4042
var (

0 commit comments

Comments
 (0)