Skip to content
Permalink
Browse files

Add a link to pipeline settings in the pipeline history page. (#2939)

  • Loading branch information...
varshavaradarajan authored and zabil committed Dec 13, 2016
1 parent f47d054 commit c749c47a12df283c2e333b9cc918e161aa6c1803
@@ -23,12 +23,10 @@
import com.thoughtworks.go.domain.*;
import com.thoughtworks.go.domain.Properties;
import com.thoughtworks.go.i18n.Localizer;
import com.thoughtworks.go.server.domain.Username;
import com.thoughtworks.go.server.presentation.models.JobDetailPresentationModel;
import com.thoughtworks.go.server.presentation.models.JobStatusJsonPresentationModel;
import com.thoughtworks.go.server.service.*;
import com.thoughtworks.go.server.util.ErrorHandler;
import com.thoughtworks.go.server.util.UserHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -45,7 +43,6 @@
import static com.thoughtworks.go.server.controller.actions.JsonAction.jsonFound;
import static com.thoughtworks.go.util.ExceptionUtils.bomb;
import static com.thoughtworks.go.util.GoConstants.ERROR_FOR_PAGE;
import static com.thoughtworks.go.util.StringUtil.isBlank;
import static com.thoughtworks.go.util.json.JsonHelper.addDeveloperErrorMessage;

/*
@@ -55,24 +52,32 @@
public class JobController {

private static final Log LOGGER = LogFactory.getLog(JobController.class);
@Autowired private JobInstanceService jobInstanceService;
@Autowired private JobDetailService jobDetailService;
@Autowired private GoConfigService goConfigService;
@Autowired private PipelineService pipelineService;
@Autowired private RestfulService restfulService;
@Autowired private ArtifactsService artifactService;
@Autowired private PropertiesService propertiesService;
@Autowired private StageService stageService;
@Autowired private Localizer localizer;
@Autowired private SecurityService securityService;
@Autowired
private JobInstanceService jobInstanceService;
@Autowired
private JobDetailService jobDetailService;
@Autowired
private GoConfigService goConfigService;
@Autowired
private PipelineService pipelineService;
@Autowired
private RestfulService restfulService;
@Autowired
private ArtifactsService artifactService;
@Autowired
private PropertiesService propertiesService;
@Autowired
private StageService stageService;
@Autowired
private Localizer localizer;

public JobController() {
}

JobController(
JobInstanceService jobInstanceService, JobDetailService jobDetailService,
GoConfigService goConfigService, PipelineService pipelineService, RestfulService restfulService,
ArtifactsService artifactService, PropertiesService propertiesService, StageService stageService, Localizer localizer, SecurityService securityService) {
ArtifactsService artifactService, PropertiesService propertiesService, StageService stageService, Localizer localizer) {
this.jobInstanceService = jobInstanceService;
this.jobDetailService = jobDetailService;
this.goConfigService = goConfigService;
@@ -82,7 +87,6 @@ public JobController() {
this.propertiesService = propertiesService;
this.stageService = stageService;
this.localizer = localizer;
this.securityService = securityService;
}

@RequestMapping(value = "/tab/build/recent", method = RequestMethod.GET)
@@ -132,22 +136,13 @@ private JobDetailPresentationModel presenter(JobInstance current) {
new CaseInsensitiveString(pipelineWithOneBuild.getName())).trackingTool();
Properties properties = propertiesService.getPropertiesForJob(current.getId());
Stage stage = stageService.getStageByBuild(current);
return new JobDetailPresentationModel(current, recent25, agentConfig, pipelineWithOneBuild, customizedTabs, trackingTool, artifactService, properties, stage, getJobDetailLink(pipelineName));
return new JobDetailPresentationModel(current, recent25, agentConfig, pipelineWithOneBuild, customizedTabs, trackingTool, artifactService, properties, stage);
}

private String getJobDetailLink(String pipelineName) {
Username userName = UserHelper.getUserName();
String jobDetailLink = null;
String groupName = goConfigService.findGroupNameByPipeline(new CaseInsensitiveString(pipelineName));
if (!isBlank(groupName) && securityService.isUserAdminOfGroup(userName.getUsername(), groupName)) {
jobDetailLink = "admin/pipelines/" + pipelineName + "/general";
}
return jobDetailLink;
}
@RequestMapping(value = "/**/jobStatus.json", method = RequestMethod.GET)
public ModelAndView handleRequest(@RequestParam(value = "pipelineName")String pipelineName,
@RequestParam(value = "stageName")String stageName,
@RequestParam(value = "jobId")long jobId,
public ModelAndView handleRequest(@RequestParam(value = "pipelineName") String pipelineName,
@RequestParam(value = "stageName") String stageName,
@RequestParam(value = "jobId") long jobId,
HttpServletResponse response) {
Object json;
try {
@@ -1,5 +1,5 @@
/*
* Copyright 2015 ThoughtWorks, Inc.
* Copyright 2016 ThoughtWorks, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -90,9 +90,9 @@ public ModelAndView list(@RequestParam("pipelineName") String pipelineName) thro
}

@RequestMapping(value = "/**/pipelineHistory.json", method = RequestMethod.GET)
public ModelAndView list(@RequestParam("pipelineName")String pipelineName,
@RequestParam(value = "perPage", required = false)Integer perPageParam,
@RequestParam(value = "start", required = false)Integer startParam,
public ModelAndView list(@RequestParam("pipelineName") String pipelineName,
@RequestParam(value = "perPage", required = false) Integer perPageParam,
@RequestParam(value = "start", required = false) Integer startParam,
@RequestParam(value = "labelFilter", required = false) String labelFilter,
HttpServletResponse response, HttpServletRequest request) throws NamingException {
PipelineConfig pipelineConfig = goConfigService.pipelineConfigNamed(new CaseInsensitiveString(pipelineName));
@@ -54,12 +54,11 @@
private final Tabs customizedTabs;
private StageIdentifier stageIdentifier;
private Stage stage;
private String jobDetailLink;

public JobDetailPresentationModel(JobInstance job, JobInstances recent25,
AgentConfig buildingAgentConfig, Pipeline pipeline, Tabs customizedTabs,
TrackingTool trackingTool, ArtifactsService artifactsService,
Properties properties, Stage stage, String jobDetailLink) {
Properties properties, Stage stage) {
this.pipeline = pipeline;
this.customizedTabs = customizedTabs;
this.job = job;
@@ -72,7 +71,6 @@ public JobDetailPresentationModel(JobInstance job, JobInstances recent25,
this.buildingAgentConfig = buildingAgentConfig;
jobIdentifier = this.job.getIdentifier();
stageIdentifier = jobIdentifier.getStageIdentifier();
this.jobDetailLink = jobDetailLink;
}

public String getConsoleoutLocator() {
@@ -247,8 +245,4 @@ public Tabs getCustomizedTabs() {
public Stage getStage() {
return stage;
}

public String getJobEditLink() {
return jobDetailLink;
}
}
@@ -37,6 +37,7 @@

import java.util.*;


/**
* @understands providing services around a pipeline configuration
*/
@@ -57,20 +57,34 @@
private JobController controller;
private MockHttpServletResponse response;
private MockHttpServletRequest request;
@Autowired private JobInstanceService jobInstanceService;
@Autowired private JobDetailService jobDetailService;
@Autowired private GoConfigService goConfigService;
@Autowired private PipelineService pipelineService;
@Autowired private RestfulService restfulService;
@Autowired private ArtifactsService artifactService;
@Autowired private PropertiesService propertiesService;
@Autowired private DatabaseAccessHelper dbHelper;
@Autowired private GoConfigDao goConfigDao;
@Autowired private MaterialRepository materialRepository;
@Autowired private StageService stageService;
@Autowired private Localizer localizer;
@Autowired private TransactionTemplate transactionTemplate;
@Autowired private SecurityService securityService;
@Autowired
private JobInstanceService jobInstanceService;
@Autowired
private JobDetailService jobDetailService;
@Autowired
private GoConfigService goConfigService;
@Autowired
private PipelineService pipelineService;
@Autowired
private RestfulService restfulService;
@Autowired
private ArtifactsService artifactService;
@Autowired
private PropertiesService propertiesService;
@Autowired
private DatabaseAccessHelper dbHelper;
@Autowired
private GoConfigDao goConfigDao;
@Autowired
private MaterialRepository materialRepository;
@Autowired
private StageService stageService;
@Autowired
private Localizer localizer;
@Autowired
private TransactionTemplate transactionTemplate;
@Autowired
private PipelineConfigService pipelineConfigService;

private GoConfigFileHelper configHelper;
private PipelineWithTwoStages fixture;
@@ -84,7 +98,7 @@ public void setUp() throws Exception {
fixture = new PipelineWithTwoStages(materialRepository, transactionTemplate);
fixture.usingConfigHelper(configHelper).usingDbHelper(dbHelper).onSetUp();
controller = new JobController(jobInstanceService, jobDetailService, goConfigService,
pipelineService, restfulService, artifactService, propertiesService, stageService, localizer, securityService);
pipelineService, restfulService, artifactService, propertiesService, stageService, localizer);
}

@After
@@ -139,7 +153,7 @@ public void shouldFindJobByPipelineCounterEvenMultiplePipelinesHaveSameLabel() t
@Test
public void shouldCreateJobPresentationModelWithRightStage() throws Exception {
controller = new JobController(jobInstanceService, jobDetailService, goConfigService,
pipelineService, restfulService, artifactService, propertiesService, stageService, localizer, securityService);
pipelineService, restfulService, artifactService, propertiesService, stageService, localizer);
fixture.configLabelTemplateUsingMaterialRevision();
Pipeline pipeline = fixture.createdPipelineWithAllStagesPassed();
Stage devStage = pipeline.getStages().byName("dev");
@@ -44,16 +44,15 @@
private GoConfigService jobConfigService;
private StageService stageService;
private MockHttpServletResponse response;
private SecurityService securityService;

@Before
public void setUp() throws Exception {
jobInstanceService = mock(JobInstanceService.class);
jobDetailService = mock(JobDetailService.class);
jobConfigService = mock(GoConfigService.class);
securityService = mock(SecurityService.class);
stageService = mock(StageService.class);
response = new MockHttpServletResponse();
jobController = new JobController(jobInstanceService, jobDetailService,jobConfigService,null,null,null,null,stageService,null, securityService);
jobController = new JobController(jobInstanceService, jobDetailService, jobConfigService, null, null, null, null, stageService, null);
}

@Test
@@ -69,16 +69,18 @@ public void setUp() {

trackingTool = new TrackingTool();
jobDetailPresenter = new JobDetailPresentationModel(stubJobInstance,
null, null, pipeline, new Tabs(), trackingTool, artifactService, new Properties(), null, null);
null, null, pipeline, new Tabs(), trackingTool, artifactService, new Properties(), null);

testFolder = TestFileUtil.createTempFolder("testFiles");
}

@After public void tearDown() throws Exception {
@After
public void tearDown() throws Exception {
FileUtil.deleteFolder(testFolder);
}

@Test public void hasBuildErrorShouldBeFalseWhenEmptyContent() throws Exception {
@Test
public void hasBuildErrorShouldBeFalseWhenEmptyContent() throws Exception {
context.checking(new Expectations() {
{
allowing(stubJobInstance).getBuildError();
@@ -89,7 +91,8 @@ public void setUp() {

}

@Test public void hasFailedTestsShouldBeFalseWhenIndexPageURLIsNull() throws Exception {
@Test
public void hasFailedTestsShouldBeFalseWhenIndexPageURLIsNull() throws Exception {
context.checking(new Expectations() {
{
allowing(stubJobInstance).getTestIndexPage();
@@ -100,7 +103,8 @@ public void setUp() {

}

@Test public void hasBuildErrorShouldBeTrueWhenNonEmptyContent() throws Exception {
@Test
public void hasBuildErrorShouldBeTrueWhenNonEmptyContent() throws Exception {

context.checking(new Expectations() {
{
@@ -111,7 +115,8 @@ public void setUp() {
assertThat(jobDetailPresenter.hasBuildError(), is(true));
}

@Test public void hasStackTraceShouldBeFalseWhenEmptyContent() throws Exception {
@Test
public void hasStackTraceShouldBeFalseWhenEmptyContent() throws Exception {
context.checking(new Expectations() {
{
allowing(stubJobInstance).getStacktrace();
@@ -122,7 +127,8 @@ public void setUp() {
assertThat(jobDetailPresenter.hasStacktrace(), is(false));
}

@Test public void hasStackTraceShouldBeTrueWhenNonEmptyContent() throws Exception {
@Test
public void hasStackTraceShouldBeTrueWhenNonEmptyContent() throws Exception {
context.checking(new Expectations() {
{
allowing(stubJobInstance).getStacktrace();
@@ -133,7 +139,8 @@ public void setUp() {
assertThat(jobDetailPresenter.hasStacktrace(), is(true));
}

@Test public void shouldIndexPage() throws Exception {
@Test
public void shouldIndexPage() throws Exception {
context.checking(new Expectations() {
{
allowing(stubJobInstance).getTestIndexPage();
@@ -144,7 +151,8 @@ public void setUp() {
assertThat(path, is("files/pipeline/1/stageName/0/build/testoutput/result/index.html"));
}

@Test public void shouldReturnEmptyStringForIndexPage() throws Exception {
@Test
public void shouldReturnEmptyStringForIndexPage() throws Exception {
context.checking(new Expectations() {
{
allowing(stubJobInstance).getTestIndexPage();
@@ -156,7 +164,8 @@ public void setUp() {
}


@Test public void shouldGetServerFailurePage() throws Exception {
@Test
public void shouldGetServerFailurePage() throws Exception {
final File file = new File(
"home" + File.separator + "user" + File.separator + ArtifactLogUtil.CRUISE_OUTPUT_FOLDER
+ File.separator + ArtifactLogUtil.SERVER_FAILURE_PAGE);
@@ -171,7 +180,8 @@ public void setUp() {
}


@Test public void shouldReturnEmptyStringForServerFailurePage() throws Exception {
@Test
public void shouldReturnEmptyStringForServerFailurePage() throws Exception {
context.checking(new Expectations() {
{
allowing(stubJobInstance).getServerFailurePage();
@@ -182,7 +192,8 @@ public void setUp() {
assertThat(path, is(""));
}

@Test public void shouldReturnBuildMessageFromPipeline() throws Exception {
@Test
public void shouldReturnBuildMessageFromPipeline() throws Exception {
String message = jobDetailPresenter.getBuildCauseMessage();
assertThat(message, is("Unknown"));
}
@@ -59,7 +59,7 @@ public void shouldShowMessage() throws IllegalArtifactLocationException {
when(directoryReader.listEntries(any(File.class), any(String.class))).thenReturn(directoryEntries);

JobDetailPresentationModel jobDetailPresentationModel = new JobDetailPresentationModel(jobInstance, null, null
, null, null, null, artifactsService, null, stage, null);
, null, null, null, artifactsService, null, stage);
DirectoryEntries artifactFiles = jobDetailPresentationModel.getArtifactFiles(directoryReader);

assertThat(artifactFiles.isArtifactsDeleted(), is(true));
@@ -69,7 +69,7 @@ public void shouldShowMessage() throws IllegalArtifactLocationException {
public void shouldAddFakeConsoleOutputEntryIfJobIsNotCompleted() throws Exception {
JobInstance job = building("job");
JobDetailPresentationModel model = new JobDetailPresentationModel(job, null, null,
null, null, null, artifactsService, null, custom("stage"), null);
null, null, null, artifactsService, null, custom("stage"));

when(artifactsService.findArtifact(job.getIdentifier(), "")).thenReturn(mock(File.class));
when(artifactsService.findArtifactUrl(job.getIdentifier(), getConsoleOutputFolderAndFileName())).thenReturn("path/to/console");
@@ -76,7 +76,7 @@ public void shouldEscapeBuildCauseInTrimpathTemplate() throws Exception {
Pipeline pipeline = schedule(pipelineConfig("pipeline", new MaterialConfigs(gitMaterialConfig)), createWithModifications(materialRevisions, ""));
JobDetailPresentationModel model = new JobDetailPresentationModel(building("job"), new JobInstances(), null,
pipeline, null, createTrackingTool(new HashMap()),
mock(ArtifactsService.class), null, StageMother.custom("stage"), null);
mock(ArtifactsService.class), null, StageMother.custom("stage"));

HashMap<String, Object> data = new HashMap<>();
data.put("presenter", model);

0 comments on commit c749c47

Please sign in to comment.
You can’t perform that action at this time.