Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making showing committers for fixed build configurable. #309

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,13 @@ public String currentbuildFailureAnalyzerDisplayedField() {
}

@SuppressWarnings("unused") // used in the configure-entries.jelly form
public boolean isDisplayCommitters() {
return currentConfig().shouldDisplayCommitters();
public boolean isDisplayCommittersOnBuildFailure() {
return currentConfig().shouldDisplayCommittersOnBuildFailure();
}

@SuppressWarnings("unused") // used in the configure-entries.jelly form
public boolean isDisplayCommittersOnFixedBuild() {
return currentConfig().shouldDisplayCommittersOnFixedBuild();
}

private static final BuildMonitorInstallation installation = new BuildMonitorInstallation();
Expand All @@ -119,9 +124,10 @@ protected void submit(StaplerRequest req) throws ServletException, IOException,
String requestedOrdering = req.getParameter("order");
title = req.getParameter("title");

currentConfig().setDisplayCommitters(json.optBoolean("displayCommitters", true));
currentConfig().setDisplayCommittersOnBuildFailure(json.optBoolean("displayCommittersOnBuildFailure", true));
currentConfig().setDisplayCommittersOnFixedBuild(json.optBoolean("displayCommittersOnFixedBuild", true));
currentConfig().setBuildFailureAnalyzerDisplayedField(req.getParameter("buildFailureAnalyzerDisplayedField"));

try {
currentConfig().setOrder(orderIn(requestedOrdering));
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@

public class Config {

private boolean displayCommitters;
private boolean displayCommittersOnBuildFailure;
private boolean displayCommittersOnFixedBuild;
private BuildFailureAnalyzerDisplayedField buildFailureAnalyzerDisplayedField;

public static Config defaultConfig() {
return new Config();
}
Expand Down Expand Up @@ -40,13 +41,21 @@ public BuildFailureAnalyzerDisplayedField getBuildFailureAnalyzerDisplayedField(
public void setBuildFailureAnalyzerDisplayedField(String buildFailureAnalyzerDisplayedField) {
this.buildFailureAnalyzerDisplayedField = BuildFailureAnalyzerDisplayedField.valueOf(buildFailureAnalyzerDisplayedField);
}

public boolean shouldDisplayCommitters() {
return getOrElse(displayCommitters, true);

public boolean shouldDisplayCommittersOnBuildFailure() {
return getOrElse(displayCommittersOnBuildFailure, true);
}

public void setDisplayCommittersOnBuildFailure(boolean flag) {
this.displayCommittersOnBuildFailure = flag;
}

public boolean shouldDisplayCommittersOnFixedBuild() {
return getOrElse(displayCommittersOnFixedBuild, false);
}

public void setDisplayCommitters(boolean flag) {
this.displayCommitters = flag;
public void setDisplayCommittersOnFixedBuild(boolean flag) {
this.displayCommittersOnFixedBuild = flag;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public JobView viewOf(Job<?, ?> job) {
List<Feature> viewFeatures = newArrayList();

// todo: a more elegant way of assembling the features would be nice
viewFeatures.add(new HasHeadline(new HeadlineConfig(config.shouldDisplayCommitters())));
viewFeatures.add(new HasHeadline(new HeadlineConfig(config.shouldDisplayCommittersOnBuildFailure(), config.shouldDisplayCommittersOnFixedBuild())));
viewFeatures.add(new KnowsLastCompletedBuildDetails());
viewFeatures.add(new KnowsCurrentBuildsDetails());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
* @author Jan Molak
*/
public class HeadlineConfig {
public final boolean displayCommitters;
public final boolean displayCommittersOnBuildFailure;
public final boolean displayCommittersOnFixedBuild;

public HeadlineConfig(boolean displayCommitters) {
this.displayCommitters = displayCommitters;
public HeadlineConfig(boolean displayCommittersOnBuildFailure, boolean displayCommittersOnFixedBuild) {

this.displayCommittersOnBuildFailure = displayCommittersOnBuildFailure;
this.displayCommittersOnFixedBuild = displayCommittersOnFixedBuild;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Headline asJson() {
private String text(BuildViewModel build) {
Optional<InterruptedBuildAction> interruption = build.detailsOf(InterruptedBuildAction.class);

if (config.displayCommitters && interruption.isPresent()) {
if (config.displayCommittersOnBuildFailure && interruption.isPresent()) {

Optional<String> username = userResponsibleFor(interruption.get());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private String text(BuildViewModel build) {
}

private Set<String> committersOf(BuildViewModel build) {
return config.displayCommitters
return config.displayCommittersOnBuildFailure
? build.committers()
: Sets.<String>newHashSet();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private List<BuildViewModel> failedBuildsSince(BuildViewModel build) {
}

private Set<String> responsibleFor(BuildViewModel build) {
return config.displayCommitters
return config.displayCommittersOnBuildFailure
? build.culprits()
: Sets.<String>newHashSet();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public HeadlineOfFixed(JobView job, HeadlineConfig config) {

@Override
public boolean isApplicableTo(JobView job) {
return didTheJobJustGetFixedWith(job.lastCompletedBuild());
return didTheJobJustGetFixedWith(job.lastCompletedBuild()) && config.displayCommittersOnFixedBuild;
}

@Override
Expand All @@ -35,7 +35,7 @@ public Headline asJson() {
private String textFor(BuildViewModel lastBuild) {

return Lister.describe(
"Back in the green!",
"",
"Fixed after %s committed their changes :-)",
newLinkedList(committersOf(lastBuild))
);
Expand All @@ -51,7 +51,7 @@ private boolean previousFailed(BuildViewModel build) {
}

private Set<String> committersOf(BuildViewModel build) {
return config.displayCommitters
return config.displayCommittersOnFixedBuild
? build.committers()
: Sets.<String>newHashSet();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@

<f:section title="${%Build Monitor - Widget Settings}">

<f:entry title="${%Display committers}" help="${descriptor.getHelpFile('displayCommitters')}">
<f:checkbox id="displayCommitters" field="displayCommitters" />
<f:entry title="${%Display committers on build failure}" help="${descriptor.getHelpFile('displayCommitters')}">
<f:checkbox id="displayCommittersOnBuildFailure" field="displayCommittersOnBuildFailure" />
</f:entry>

<f:entry title="${%Display committers on build fix}"}">
<f:checkbox id="displayCommittersOnFixedBuild" field="displayCommittersOnFixedBuild" />
</f:entry>

<f:entry title="${%Failure Analyzer Plugin: Field to display}" help="${descriptor.getHelpFile('buildFailureAnalyzerDisplayedField')}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
You can use it to quickly find out who might know the most about the problem
and need help fixing it.
</p>
<p>
This feature works the other way around too! If someone fixes a broken build,
it's their identifier that gets to appear on the screen.
</p>
<p>
<strong>Did you know</strong> that when a broken build is
<a href="https://wiki.jenkins-ci.org/display/JENKINS/Claim+plugin" target="_blank">claimed</a>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import java.net.MalformedURLException;
import java.net.URL;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static junit.framework.TestCase.assertTrue;

public class PathToAssetTest {

Expand All @@ -17,17 +16,21 @@ public void combines_base_resource_url_given_by_jenkins_and_a_path_to_the_asset(
URL base = baseResourceUrlGivenByJenkins("file:///opt/jenkins/plugins/build-monitor-plugin/");

PathToAsset path = new PathToAsset(base, "less/index.less");

assertThat(absolute(path), is("/opt/jenkins/plugins/build-monitor-plugin/less/index.less"));
//Tweaking it to be able to run on Windows
String actualValue = absolute(path).replace("\\", "/");
String expectedValue = "/opt/jenkins/plugins/build-monitor-plugin/less/index.less";
assertTrue("\nActual: " + actualValue + " \n does not contain expected value : " + expectedValue, actualValue.contains(expectedValue));
}

@Test
public void works_with_unc_paths_on_windows() throws Exception {
URL base = baseResourceUrlGivenByJenkins("file://server/jenkins/plugins/build-monitor-plugin/");

PathToAsset path = new PathToAsset(base, "less/index.less");

assertThat(absolute(path), is("/server/jenkins/plugins/build-monitor-plugin/less/index.less"));
//Tweaking it to be able to run on Windows
String actualValue = absolute(path).replace("\\", "/");
String expectedValue = "/server/jenkins/plugins/build-monitor-plugin/less/index.less";
assertTrue("\nActual: " + actualValue + " \n does not contain expected value : " + expectedValue, actualValue.contains(expectedValue));
}

@Rule public ExpectedException thrown = ExpectedException.none();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public void should_tell_if_a_build_was_aborted() throws Exception {
// --

private Feature hasHeadlineThatShowsCommitters() {
return new HasHeadline(new HeadlineConfig(true));
return new HasHeadline(new HeadlineConfig(true, false));
}

private Feature hasHeadlineThatDoesNotShowCommitters() {
return new HasHeadline(new HeadlineConfig(false));
return new HasHeadline(new HeadlineConfig(false, false));
}

private String headlineOf(JobView job) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ public void should_tell_the_number_of_broken_builds_since_the_last_build_broken_
// --

private Feature hasHeadlineThatShowsCommitters() {
return new HasHeadline(new HeadlineConfig(true));
return new HasHeadline(new HeadlineConfig(true, false));
}

private Feature hasHeadlineThatDoesNotShowCommitters() {
return new HasHeadline(new HeadlineConfig(false));
return new HasHeadline(new HeadlineConfig(false, false));
}

private String headlineOf(JobView job) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void should_congratulate_anonymously_if_broken_build_was_fixed_without_kn
a(job().whereTheLast(build().succeededThanksTo()).
andThePrevious(build().wasBrokenBy("Daniel", "Ben")))));

assertThat(headlineOf(view), is("Back in the green!"));
assertThat(headlineOf(view), is(""));
}

@Test
Expand All @@ -46,7 +46,7 @@ public void should_congratulate_anonymously_when_the_build_is_fixed_but_the_comm
a(job().whereTheLast(build().succeededThanksTo("Adam")).
andThePrevious(build().wasBrokenBy("Daniel", "Ben")))));

assertThat(headlineOf(view), is("Back in the green!"));
assertThat(headlineOf(view), is(""));
}

@Test
Expand All @@ -69,11 +69,11 @@ public void should_not_congratulate_if_no_failure_before() throws Exception {
// --

private Feature hasHeadlineThatShowsCommitters() {
return new HasHeadline(new HeadlineConfig(true));
return new HasHeadline(new HeadlineConfig(true, true));
}

private Feature hasHeadlineThatDoesNotShowCommitters() {
return new HasHeadline(new HeadlineConfig(false));
return new HasHeadline(new HeadlineConfig(false, false));
}

private String headlineOf(JobView job) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ public void should_not_tell_whose_changes_are_being_built_if_commiters_are_not_t
// --

private Feature hasHeadlineThatShowsCommitters() {
return new HasHeadline(new HeadlineConfig(true));
return new HasHeadline(new HeadlineConfig(true, false));
}

private Feature hasHeadlineThatDoesNotShowCommitters() {
return new HasHeadline(new HeadlineConfig(false));
return new HasHeadline(new HeadlineConfig(false, false));
}

private String headlineOf(JobView job) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void should_say_nothing_if_no_builds_were_executed() throws Exception {
// --

private Feature hasHeadlineThatShowsCommitters() {
return new HasHeadline(new HeadlineConfig(true));
return new HasHeadline(new HeadlineConfig(true, false));
}

private String headlineOf(JobView job) {
Expand Down