Skip to content

Commit 6ef51dd

Browse files
authored
JFMIG-13 - Add ability to provide include files pattern to migrate only a part of repository (#3266)
1 parent d784314 commit 6ef51dd

File tree

6 files changed

+65
-5
lines changed

6 files changed

+65
-5
lines changed

artifactory/cli.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,7 @@ func transferFilesCmd(c *cli.Context) error {
11731173
includeReposPatterns, excludeReposPatterns := getTransferIncludeExcludeRepos(c)
11741174
newTransferFilesCmd.SetIncludeReposPatterns(includeReposPatterns)
11751175
newTransferFilesCmd.SetExcludeReposPatterns(excludeReposPatterns)
1176+
newTransferFilesCmd.SetIncludeFilesPatterns(getIncludeFilesPatterns(c))
11761177
newTransferFilesCmd.SetIgnoreState(c.Bool(cliutils.IgnoreState))
11771178
newTransferFilesCmd.SetProxyKey(c.String(cliutils.ProxyKey))
11781179
return newTransferFilesCmd.Run()
@@ -1189,6 +1190,14 @@ func getTransferIncludeExcludeRepos(c *cli.Context) (includeReposPatterns, exclu
11891190
return
11901191
}
11911192

1193+
func getIncludeFilesPatterns(c *cli.Context) []string {
1194+
const patternSeparator = ";"
1195+
if c.IsSet(cliutils.IncludeFiles) {
1196+
return strings.Split(c.String(cliutils.IncludeFiles), patternSeparator)
1197+
}
1198+
return nil
1199+
}
1200+
11921201
func getTransferIncludeExcludeProjects(c *cli.Context) (includeProjectsPatterns, excludeProjectsPatterns []string) {
11931202
const patternSeparator = ";"
11941203
if c.IsSet(cliutils.IncludeProjects) {

artifactory/cli_test.go

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package artifactory
22

33
import (
44
"bytes"
5-
"github.com/jfrog/jfrog-cli-artifactory/cliutils/flagkit"
65
"path/filepath"
76
"testing"
87

8+
"github.com/jfrog/jfrog-cli-artifactory/cliutils/flagkit"
9+
910
commonCliUtils "github.com/jfrog/jfrog-cli-core/v2/common/cliutils"
1011
"github.com/jfrog/jfrog-cli-core/v2/common/spec"
1112
"github.com/jfrog/jfrog-cli/utils/cliutils"
@@ -154,3 +155,46 @@ func TestCreateUploadConfiguration(t *testing.T) {
154155
})
155156
}
156157
}
158+
159+
// Test cases for getIncludeFilesPatterns
160+
var getIncludeFilesPatternsTestCases = []struct {
161+
name string
162+
flags []string
163+
expectedPatterns []string
164+
}{
165+
{
166+
name: "no flag set",
167+
flags: []string{},
168+
expectedPatterns: nil,
169+
},
170+
{
171+
name: "single pattern",
172+
flags: []string{cliutils.IncludeFiles + "=org/company/*"},
173+
expectedPatterns: []string{"org/company/*"},
174+
},
175+
{
176+
name: "multiple patterns",
177+
flags: []string{cliutils.IncludeFiles + "=org/company/*;com/example/*"},
178+
expectedPatterns: []string{"org/company/*", "com/example/*"},
179+
},
180+
{
181+
name: "three patterns",
182+
flags: []string{cliutils.IncludeFiles + "=path1/*;path2/*;path3/*"},
183+
expectedPatterns: []string{"path1/*", "path2/*", "path3/*"},
184+
},
185+
{
186+
name: "pattern with deep nesting",
187+
flags: []string{cliutils.IncludeFiles + "=a/b/c/d/e/*"},
188+
expectedPatterns: []string{"a/b/c/d/e/*"},
189+
},
190+
}
191+
192+
func TestGetIncludeFilesPatterns(t *testing.T) {
193+
for _, testCase := range getIncludeFilesPatternsTestCases {
194+
t.Run(testCase.name, func(t *testing.T) {
195+
context, _ := tests.CreateContext(t, testCase.flags, []string{})
196+
patterns := getIncludeFilesPatterns(context)
197+
assert.Equal(t, testCase.expectedPatterns, patterns)
198+
})
199+
}
200+
}

artifactory_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,13 @@ func TestReleaseBundleImportOnPrem(t *testing.T) {
276276

277277
func TestReleaseBundleV2Download(t *testing.T) {
278278
buildNumber := "5"
279+
initArtifactoryTest(t, "")
280+
initLifecycleTest(t, signingKeyOptionalArtifactoryMinVersion)
279281
defer func() {
280282
deleteReceivedReleaseBundle(t, deleteReleaseBundleV2ApiUrl, tests.LcRbName1, buildNumber)
281283
inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails)
282284
cleanArtifactoryTest()
283285
}()
284-
initArtifactoryTest(t, "")
285-
initLifecycleTest(t, signingKeyOptionalArtifactoryMinVersion)
286286

287287
runRt(t, "upload", "testdata/a/a1.in", tests.RtRepo1, "--build-name="+tests.RtBuildName1, "--build-number="+buildNumber)
288288
runRt(t, "build-publish", tests.RtBuildName1, buildNumber)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ require (
2020
github.com/jfrog/gofrog v1.7.6
2121
github.com/jfrog/jfrog-cli-application v1.0.2-0.20251210075951-519050602a7f
2222
github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20251218044417-5113b260e416
23-
github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20251210085744-f8481d179ac5
23+
github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20251219102726-2cbe70d57403
2424
github.com/jfrog/jfrog-cli-evidence v0.8.3-0.20251204144808-73fa744851c0
2525
github.com/jfrog/jfrog-cli-platform-services v1.10.1-0.20251205121610-171eb9b0000e
2626
github.com/jfrog/jfrog-cli-security v1.24.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,8 @@ github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20251218044417-5113b260e416 h1:b
12201220
github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20251218044417-5113b260e416/go.mod h1:7cCaRhXorlbyXZgiW5bplCExFxlnROaG21K12d8inpQ=
12211221
github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20251210085744-f8481d179ac5 h1:GYE67ubwl+ZRw3CcXFUi49EwwQp6k+qS8sX0QuHDHO8=
12221222
github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20251210085744-f8481d179ac5/go.mod h1:BMoGi2rG0udCCeaghqlNgiW3fTmT+TNnfTnBoWFYgcg=
1223+
github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20251219102726-2cbe70d57403 h1:Hnw9eOCdybMBAh1pUt9FCs74CTDOUh0M79ZCQ3VKPc4=
1224+
github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20251219102726-2cbe70d57403/go.mod h1:BMoGi2rG0udCCeaghqlNgiW3fTmT+TNnfTnBoWFYgcg=
12231225
github.com/jfrog/jfrog-cli-evidence v0.8.3-0.20251204144808-73fa744851c0 h1:8S1vE1PeVtrzWkKL0N39cX6XLLNV0It+f6xjRKjw7Ug=
12241226
github.com/jfrog/jfrog-cli-evidence v0.8.3-0.20251204144808-73fa744851c0/go.mod h1:Ijx7tkTp6uDxgmQW+zQKLNztMrz6dcQAoVNXHL7spsU=
12251227
github.com/jfrog/jfrog-cli-platform-services v1.10.1-0.20251205121610-171eb9b0000e h1:0BDeb5lD8qgQMOZJ08E35jUMTlt2Hb0K7Wu0SqO6MrI=

utils/cliutils/commandsflags.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ const (
564564
ExcludeRepos = "exclude-repos"
565565
IncludeProjects = "include-projects"
566566
ExcludeProjects = "exclude-projects"
567+
IncludeFiles = "include-files"
567568

568569
// *** JFrog Pipelines Commands' flags ***
569570
// Base flags
@@ -1607,6 +1608,10 @@ var flagsMap = map[string]cli.Flag{
16071608
Name: ExcludeProjects,
16081609
Usage: "[Optional] List of semicolon-separated(;) JFrog Projects to exclude from the transfer. You can use wildcards to specify patterns for the project keys.` `",
16091610
},
1611+
IncludeFiles: cli.StringFlag{
1612+
Name: IncludeFiles,
1613+
Usage: "[Optional] List of semicolon-separated(;) path patterns to include in the transfer. Files will be filtered based on their directory path. Pattern examples: 'folder/subfolder/*', 'org/company/*'.` `",
1614+
},
16101615
IgnoreState: cli.BoolFlag{
16111616
Name: IgnoreState,
16121617
Usage: "[Default: false] Set to true to ignore the saved state from previous transfer-files operations.` `",
@@ -2035,7 +2040,7 @@ var commandFlags = map[string][]string{
20352040
url, user, password, accessToken, sshPassphrase, sshKeyPath, serverId, deleteQuiet,
20362041
},
20372042
TransferFiles: {
2038-
Filestore, IncludeRepos, ExcludeRepos, IgnoreState, ProxyKey, transferFilesStatus, Stop, PreChecks,
2043+
Filestore, IncludeRepos, ExcludeRepos, IncludeFiles, IgnoreState, ProxyKey, transferFilesStatus, Stop, PreChecks,
20392044
},
20402045
TransferInstall: {
20412046
installPluginVersion, InstallPluginSrcDir, InstallPluginHomeDir,

0 commit comments

Comments
 (0)