Skip to content

Commit

Permalink
Adding pipeline count information to the about page
Browse files Browse the repository at this point in the history
  • Loading branch information
jyotisingh committed Oct 27, 2017
1 parent 9f6909e commit 979fa50
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 4 deletions.
Expand Up @@ -527,7 +527,7 @@ public CommentRenderer getCommentRendererFor(String pipelineName) {
}

public List<PipelineConfig> getAllPipelineConfigs() {
return getCurrentConfig().getAllPipelineConfigs();
return cruiseConfig().getAllPipelineConfigs();
}

/* NOTE: this is called from rails environments controller to build a list of pipelines which user can assign in environment.
Expand Down
Expand Up @@ -190,4 +190,8 @@ private List<PluggableTask> pluggableTask(PipelineConfig config) {
}
return tasks;
}

public int totalPipelinesCount() {
return goConfigService.getAllPipelineConfigs().size();
}
}
Expand Up @@ -16,13 +16,14 @@

package com.thoughtworks.go.server.service;

import com.rits.cloning.Cloner;
import com.thoughtworks.go.config.*;
import com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig;
import com.thoughtworks.go.config.pluggabletask.PluggableTask;
import com.thoughtworks.go.domain.PipelineGroups;
import com.thoughtworks.go.config.materials.git.GitMaterialConfig;
import com.thoughtworks.go.config.pluggabletask.PluggableTask;
import com.thoughtworks.go.config.remote.ConfigRepoConfig;
import com.thoughtworks.go.config.remote.RepoConfigOrigin;
import com.thoughtworks.go.domain.PipelineGroups;
import com.thoughtworks.go.helper.JobConfigMother;
import com.thoughtworks.go.helper.PipelineConfigMother;
import com.thoughtworks.go.i18n.LocalizedMessage;
Expand All @@ -34,6 +35,7 @@

import java.util.List;
import java.util.Map;
import java.util.UUID;

import static com.thoughtworks.go.helper.EnvironmentConfigMother.environment;
import static com.thoughtworks.go.helper.PipelineConfigMother.createGroup;
Expand Down Expand Up @@ -63,6 +65,7 @@ public void setUp() throws Exception {
securityService = mock(SecurityService.class);
pluggableTaskService = mock(PluggableTaskService.class);
when(goConfigService.getCurrentConfig()).thenReturn(cruiseConfig);
when(goConfigService.cruiseConfig()).thenReturn(cruiseConfig);
when(goConfigService.getConfigForEditing()).thenReturn(cruiseConfig);
when(goConfigService.getMergedConfigForEditing()).thenReturn(cruiseConfig);
pipelineConfigService = new PipelineConfigService(goConfigService, securityService, pluggableTaskService, null);
Expand Down Expand Up @@ -180,4 +183,19 @@ public void createPipelineConfigShouldValidateAllPluggableTasks() {
verify(pluggableTaskService).isValid(xUnit);
verify(pluggableTaskService).isValid(docker);
}

@Test
public void shouldGetPipelinesCount() {
assertThat(pipelineConfigService.totalPipelinesCount(), is(this.cruiseConfig.allPipelines().size()));
}

@Test
public void pipelineCountShouldIncludeConfigRepoPipelinesAsWell() {
CruiseConfig mergedCruiseConfig = new Cloner().deepClone(cruiseConfig);
mergedCruiseConfig.addPipeline("default", PipelineConfigMother.pipelineConfig(UUID.randomUUID().toString()));
when(goConfigService.cruiseConfig()).thenReturn(mergedCruiseConfig);
when(goConfigService.getConfigForEditing()).thenReturn(cruiseConfig);

assertThat(pipelineConfigService.totalPipelinesCount(), is(mergedCruiseConfig.allPipelines().size()));
}
}
6 changes: 5 additions & 1 deletion server/webapp/WEB-INF/rails.new/app/helpers/about_helper.rb
@@ -1,5 +1,5 @@
##########################################################################
# Copyright 2015 ThoughtWorks, Inc.
# Copyright 2017 ThoughtWorks, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,4 +35,8 @@ def available_space
def schema_version
system_service.getSchemaVersion()
end

def total_pipelines_count
pipeline_config_service.totalPipelinesCount()
end
end
4 changes: 4 additions & 0 deletions server/webapp/WEB-INF/rails.new/app/views/about/show.html.erb
Expand Up @@ -24,6 +24,10 @@
<td>Database schema version:</td>
<td><%= schema_version %></td>
</tr>
<tr>
<td>Pipelines Count:</td>
<td><%= total_pipelines_count %></td>
</tr>
</tbody>
</table>
</div>
Expand Down
28 changes: 28 additions & 0 deletions server/webapp/WEB-INF/rails.new/spec/helpers/about_helper_spec.rb
@@ -0,0 +1,28 @@
##########################################################################
# Copyright 2017 ThoughtWorks, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##########################################################################

require 'spec_helper'

describe AboutHelper do
include AboutHelper

it "should get the pipelines count" do
should_receive(:pipeline_config_service).and_return(pipeline_config_service = double('pipeline_config_service'))
expect(pipeline_config_service).to receive(:totalPipelinesCount).and_return(10)

expect(total_pipelines_count).to eq(10)
end
end

0 comments on commit 979fa50

Please sign in to comment.