Skip to content

Commit

Permalink
Merge pull request #3 from walquis/master
Browse files Browse the repository at this point in the history
Restore "secondsElapsed" (since build finished), and rename to "secondsSinceFinished" to make its intent clearer.  Renamed "elapsed" to "buildDuration".
  • Loading branch information
cread committed Jul 24, 2014
2 parents 9e4bb98 + 8d709a3 commit 3b120f7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
15 changes: 12 additions & 3 deletions src/main/io/cread/teamcity/JSONMonitorController.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Date;

public class JSONMonitorController implements Controller {
private final SBuildServer server;
Expand Down Expand Up @@ -59,9 +60,16 @@ public ModelAndView handleRequest(HttpServletRequest request, HttpServletRespons
userName = responsibleUser.getUsername();
}

long elapsed = -1;
long duration = -1;
long secondsSinceFinished = -1;
if (!latestBuild.isFinished()) {
elapsed = latestBuild.getDuration();
duration = latestBuild.getDuration();
} else {
Date finishDate = latestBuild.getFinishDate();
if (finishDate != null) {
long now = new Date().getTime();
secondsSinceFinished = (now - finishDate.getTime()) / 1000;
}
}

state.addJob(new JobState(
Expand All @@ -70,7 +78,8 @@ public ModelAndView handleRequest(HttpServletRequest request, HttpServletRespons
latestBuild.getBuildStatus().getText(),
userName,
latestBuild.getProjectExternalId(),
elapsed
duration,
secondsSinceFinished
));
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/main/io/cread/teamcity/JSONViewState.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ public String renderJobsList() {
.append("\",\"url\":\"").append(rootURL).append("/viewType.html?buildTypeId=").append(job.id)
.append("\",\"responsible\":\"").append(job.responsible)
.append("\",\"project\":\"").append(job.project);
if (job.secondsElapsed > 0) {
data.append("\",\"secondsElapsed\":\"").append(job.secondsElapsed);
if (job.buildDuration >= 0) {
data.append("\",\"buildDuration\":\"").append(job.buildDuration);
}
if (job.secondsSinceFinished >= 0) {
data.append("\",\"secondsSinceFinished\":\"").append(job.secondsSinceFinished);
}
data.append("\",\"color\":\"").append(job.color).append("\"},");
}
Expand Down
8 changes: 5 additions & 3 deletions src/main/io/cread/teamcity/JobState.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ public class JobState {
public final String status;
public final String responsible;
public final String project;
public final long secondsElapsed;
public final long buildDuration;
public final long secondsSinceFinished;
public final String color;

public JobState(String name, String id, String status, String responsible, String project, long secondsElapsed ) {
public JobState(String name, String id, String status, String responsible, String project, long buildDuration, long secondsSinceFinished) {
this.name = name;
this.id = id;
this.status = status;
this.secondsElapsed = secondsElapsed;
this.buildDuration = buildDuration;
this.responsible = responsible;
this.project = project;
this.secondsSinceFinished = secondsSinceFinished;
this.color = ("SUCCESS".equals(status)) ? "blue" : "red";
}
}
18 changes: 8 additions & 10 deletions src/tests/io/cread/teamcity/JSONViewStateTests.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.cread.teamcity;

import io.cread.teamcity.JSONViewState;
import io.cread.teamcity.JobState;
import junit.framework.TestCase;

public class JSONViewStateTests extends TestCase {
Expand All @@ -18,26 +16,26 @@ public void testShouldRenderEmptyListIfNoJobs() {
}

public void testShouldBeAbleToRenderMultipleJobDetails() {
state.addJob(new JobState("Job1", "bt3", "ERROR", "buildadmin", "Big Project", 100L));
state.addJob(new JobState("Job2", "bt5", "SUCCESS", "jdoe", "Medium Project", 200L));
state.addJob(new JobState("Job1", "bt3", "ERROR", "buildadmin", "Big Project", 100L, 300L));
state.addJob(new JobState("Job2", "bt5", "SUCCESS", "jdoe", "Medium Project", 200L, 400L));


assertEquals("\"jobs\":[" +
"{\"name\":\"Job1\",\"url\":\"http://localhost:8111/viewType.html?buildTypeId=bt3\",\"responsible\":\"buildadmin\",\"project\":\"Big Project\",\"secondsElapsed\":\"100\",\"color\":\"red\"}," +
"{\"name\":\"Job2\",\"url\":\"http://localhost:8111/viewType.html?buildTypeId=bt5\",\"responsible\":\"jdoe\",\"project\":\"Medium Project\",\"secondsElapsed\":\"200\",\"color\":\"blue\"}" +
"{\"name\":\"Job1\",\"url\":\"http://localhost:8111/viewType.html?buildTypeId=bt3\",\"responsible\":\"buildadmin\",\"project\":\"Big Project\",\"buildDuration\":\"100\",\"secondsSinceFinished\":\"300\",\"color\":\"red\"}," +
"{\"name\":\"Job2\",\"url\":\"http://localhost:8111/viewType.html?buildTypeId=bt5\",\"responsible\":\"jdoe\",\"project\":\"Medium Project\",\"buildDuration\":\"200\",\"secondsSinceFinished\":\"400\",\"color\":\"blue\"}" +
"],", state.renderJobsList());
}

public void testShouldBeAbleToRenderSingleJobDetails() {
state.addJob(new JobState("Job1", "bt3", "ERROR", "rstevens", "Little Project", 300L));
state.addJob(new JobState("Job1", "bt3", "ERROR", "rstevens", "Little Project", 300L, 400L));

assertEquals("\"jobs\":[" +
"{\"name\":\"Job1\",\"url\":\"http://localhost:8111/viewType.html?buildTypeId=bt3\",\"responsible\":\"rstevens\",\"project\":\"Little Project\",\"secondsElapsed\":\"300\",\"color\":\"red\"}" +
"{\"name\":\"Job1\",\"url\":\"http://localhost:8111/viewType.html?buildTypeId=bt3\",\"responsible\":\"rstevens\",\"project\":\"Little Project\",\"buildDuration\":\"300\",\"secondsSinceFinished\":\"400\",\"color\":\"red\"}" +
"],", state.renderJobsList());
}

public void testShouldNotAddDuplicates() {
JobState job = new JobState("Job1", "bt3", "SUCCESS", "cread", "Stuff", -1);
JobState job = new JobState("Job1", "bt3", "SUCCESS", "cread", "Stuff", -1, -1);

state.addJob(job);

Expand All @@ -49,7 +47,7 @@ public void testShouldNotAddDuplicates() {
}

public void testShouldNotRenderNoElapsedSeconds() {
state.addJob(new JobState("Job1", "bt3", "ERROR", "rstevens", "Little Project", -1L));
state.addJob(new JobState("Job1", "bt3", "ERROR", "rstevens", "Little Project", -1L, -1));

assertEquals("\"jobs\":[" +
"{\"name\":\"Job1\",\"url\":\"http://localhost:8111/viewType.html?buildTypeId=bt3\",\"responsible\":\"rstevens\",\"project\":\"Little Project\",\"color\":\"red\"}" +
Expand Down

0 comments on commit 3b120f7

Please sign in to comment.