Skip to content

Commit a66bd33

Browse files
authored
Fix excluded chart when chart-dirs is multi-level (#312)
Signed-off-by: nekottyo <[email protected]>
1 parent 9b80b21 commit a66bd33

File tree

6 files changed

+26
-0
lines changed

6 files changed

+26
-0
lines changed

pkg/chart/chart.go

+7
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,14 @@ func (t *Testing) ComputeChangedChartDirectories() ([]string, error) {
724724
dir := filepath.Dir(file)
725725
// Make sure directory is really a chart directory
726726
chartDir, err := t.chartUtils.LookupChartDir(cfg.ChartDirs, dir)
727+
chartDirElement := strings.Split(chartDir, "/")
727728
if err == nil {
729+
if len(chartDirElement) > 1 {
730+
chartDirName := chartDirElement[len(chartDirElement)-1]
731+
if util.StringSliceContains(cfg.ExcludedCharts, chartDirName) {
732+
continue
733+
}
734+
}
728735
// Only add it if not already in the list
729736
if !util.StringSliceContains(changedChartDirs, chartDir) {
730737
changedChartDirs = append(changedChartDirs, chartDir)

pkg/chart/chart_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ func (g fakeGit) ListChangedFilesInDirs(commit string, dirs ...string) ([]string
4545
"test_charts/foo/Chart.yaml",
4646
"test_charts/bar/Chart.yaml",
4747
"test_charts/bar/bar_sub/templates/bar_sub.yaml",
48+
"test_charts/excluded/Chart.yaml",
4849
"test_chart_at_root/templates/foo.yaml",
50+
"test_chart_at_multi_level/foo/bar/Chart.yaml",
51+
"test_chart_at_multi_level/foo/baz/Chart.yaml",
52+
"test_chart_at_multi_level/foo/excluded/Chart.yaml",
4953
"some_non_chart_dir/some_non_chart_file",
5054
"some_non_chart_file",
5155
}, nil
@@ -152,6 +156,21 @@ func TestComputeChangedChartDirectories(t *testing.T) {
152156
assert.Nil(t, err)
153157
}
154158

159+
func TestComputeChangedChartDirectoriesWithMultiLevelChart(t *testing.T) {
160+
cfg := config.Configuration{
161+
ExcludedCharts: []string{"excluded"},
162+
ChartDirs: []string{"test_chart_at_multi_level/foo"},
163+
}
164+
ct := newTestingMock(cfg)
165+
actual, err := ct.ComputeChangedChartDirectories()
166+
expected := []string{"test_chart_at_multi_level/foo/bar", "test_chart_at_multi_level/foo/baz"}
167+
for _, chart := range actual {
168+
assert.Contains(t, expected, chart)
169+
}
170+
assert.Len(t, actual, 2)
171+
assert.Nil(t, err)
172+
}
173+
155174
func TestReadAllChartDirectories(t *testing.T) {
156175
actual, err := ct.ReadAllChartDirectories()
157176
expected := []string{

pkg/chart/test_chart_at_multi_level/foo/bar/Chart.yaml

Whitespace-only changes.

pkg/chart/test_chart_at_multi_level/foo/baz/Chart.yaml

Whitespace-only changes.

pkg/chart/test_chart_at_multi_level/foo/excluded/Chart.yaml

Whitespace-only changes.

pkg/chart/test_charts/excluded/Chart.yaml

Whitespace-only changes.

0 commit comments

Comments
 (0)