Skip to content

Commit

Permalink
Do not remove MaterialHealthStateScope for config repo materials (#5651)
Browse files Browse the repository at this point in the history
  • Loading branch information
GaneshSPatil committed Jan 4, 2019
1 parent b871665 commit 9a1eaf3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public boolean isRemovedFromConfig(CruiseConfig cruiseConfig, String group) {
},
MATERIAL {
public boolean isRemovedFromConfig(CruiseConfig cruiseConfig, String materialScope) {
for (MaterialConfig materialConfig : cruiseConfig.getAllUniqueMaterials()) {
for (MaterialConfig materialConfig : cruiseConfig.getAllUniqueMaterialsOfPipelinesAndConfigRepos()) {
if (HealthStateScope.forMaterialConfig(materialConfig).getScope().equals(materialScope)) {
return false;
}
Expand All @@ -242,7 +242,7 @@ public boolean isRemovedFromConfig(CruiseConfig cruiseConfig, String materialSco
},
MATERIAL_UPDATE {
public boolean isRemovedFromConfig(CruiseConfig cruiseConfig, String materialScope) {
for (MaterialConfig materialConfig : cruiseConfig.getAllUniqueMaterials()) {
for (MaterialConfig materialConfig : cruiseConfig.getAllUniqueMaterialsOfPipelinesAndConfigRepos()) {
if (HealthStateScope.forMaterialConfigUpdate(materialConfig).getScope().equals(materialScope)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.thoughtworks.go.config.CruiseConfig;
import com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig;
import com.thoughtworks.go.config.materials.svn.SvnMaterial;
import com.thoughtworks.go.config.remote.ConfigRepoConfig;
import com.thoughtworks.go.helper.GoConfigMother;
import com.thoughtworks.go.helper.MaterialConfigsMother;
import com.thoughtworks.go.helper.MaterialsMother;
Expand Down Expand Up @@ -65,6 +66,22 @@ public void shouldRemoveScopeWhenMaterialIsRemovedFromConfig() throws Exception
assertThat(HealthStateScope.forMaterial(MaterialsMother.svnMaterial("file:///bar")).isRemovedFromConfig(config),is(true));
}

@Test
public void shouldNotRemoveScopeWhenMaterialBelongsToConfigRepoMaterial() throws Exception {
HgMaterialConfig hgMaterialConfig = MaterialConfigsMother.hgMaterialConfig();
CruiseConfig config = GoConfigMother.pipelineHavingJob("blahPipeline", "blahStage", "blahJob", "fii", "baz");
config.getConfigRepos().add(new ConfigRepoConfig(hgMaterialConfig, "id1", "foo"));
assertThat(HealthStateScope.forMaterialConfig(hgMaterialConfig).isRemovedFromConfig(config),is(false));
}

@Test
public void shouldNotRemoveScopeWhenMaterialUpdateBelongsToConfigRepoMaterial() throws Exception {
HgMaterialConfig hgMaterialConfig = MaterialConfigsMother.hgMaterialConfig();
CruiseConfig config = GoConfigMother.pipelineHavingJob("blahPipeline", "blahStage", "blahJob", "fii", "baz");
config.getConfigRepos().add(new ConfigRepoConfig(hgMaterialConfig, "id1", "foo"));
assertThat(HealthStateScope.forMaterialConfigUpdate(hgMaterialConfig).isRemovedFromConfig(config),is(false));
}

@Test
public void shouldRemoveScopeWhenStageIsRemovedFromConfig() throws Exception {
CruiseConfig config = GoConfigMother.pipelineHavingJob("blahPipeline", "blahStage", "blahJob", "fii", "baz");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,10 @@ public Set<MaterialConfig> getAllUniqueMaterials() {
return getUniqueMaterials(false, true);
}

public Set<MaterialConfig> getAllUniqueMaterialsOfPipelinesAndConfigRepos() {
return getUniqueMaterials(false, false);
}

private Set<MaterialConfig> getUniqueMaterials(boolean ignoreManualPipelines, boolean ignoreConfigRepos) {
Set<MaterialConfig> materialConfigs = new HashSet<>();
Set<Map> uniqueMaterials = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ public interface CruiseConfig extends Validatable, ConfigOriginTraceable {

Set<MaterialConfig> getAllUniqueMaterials();

Set<MaterialConfig> getAllUniqueMaterialsOfPipelinesAndConfigRepos();

Set<StageConfig> getStagesUsedAsMaterials(PipelineConfig pipelineConfig);

EnvironmentConfig addEnvironment(String environmentName);
Expand Down

0 comments on commit 9a1eaf3

Please sign in to comment.