Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions src/main/java/io/jenkins/plugins/reporter/ReportAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ public ReportDetails getTarget() {
public ReportResult getResult() {
return result;
}

@Whitelisted
public io.jenkins.plugins.reporter.model.Report getReport() {
return result.getReport();
}

/**
* Returns the name of the report.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public String getItemPieChartModel() {
*/
@SuppressWarnings("unused") // Called by jelly view
public ItemTableModel getTableModel() {
return new ItemTableModel(result.getReport(), getItem());
return new ItemTableModel(result.getReport(), getItem(), owner);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ public enum DisplayType {

ABSOLUTE,
RELATIVE,
DUAL;
DUAL,
DELTA;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package io.jenkins.plugins.reporter.model;

import hudson.model.Run;
import io.jenkins.plugins.datatables.TableColumn;
import io.jenkins.plugins.reporter.ReportAction;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.CaseUtils;

import java.io.UnsupportedEncodingException;
Expand All @@ -9,6 +12,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

/**
Expand All @@ -23,6 +27,8 @@

private final Item item;

private final Run<?, ?> owner;

/**
* Creates a new instance of {@link ItemTableModel}.
*
Expand All @@ -32,11 +38,12 @@
* @param item
* the item to render
*/
public ItemTableModel(final Report report, final Item item) {
public ItemTableModel(final Report report, final Item item, final Run<?,?> owner) {
super();

this.report = report;
this.item = item;
this.owner = owner;
}

public String getId() {
Expand Down Expand Up @@ -145,15 +152,68 @@
}

public String label(String id, Integer value) {
if (item.getResult().size() == 1) {
return item.getLabel(report, value, value / (double) model.getItem().getTotal() * 100);
String label = "";
if (report.getDisplayType() == DisplayType.DELTA) {
String delta = getDelta(id);
if (StringUtils.equals(delta, "=")) {
label = String.valueOf(value);
} else if (StringUtils.isNotEmpty(delta)) {
label = String.format("%d (%s)", value, delta);
} else {
label = String.valueOf(value);
}
} else {
if (item.getResult().size() == 1) {
label = item.getLabel(report, value, value / (double) model.getItem().getTotal() * 100);
} else {
label = item.getLabel(report, value, value / (double) model.getItem().getResult().get(id) * 100);
}
}

return item.getLabel(report, value, value / (double) model.getItem().getResult().get(id) * 100);
return label;
}

public String tooltip(String id, double percentage) {
return String.format("%s: %.2f%%", id, percentage);
}

public String getDelta(String property) {
Optional<Report> referenceReport = getReferenceReport();
if (referenceReport.isPresent()) {
Optional<Item> referenceItem = referenceReport.get().findItem(item.getId());
if (referenceItem.isPresent()) {

int current = item.getResult().get(property);
int old = referenceItem.get().getResult().get(property);
int delta = current - old;

if (delta > 0) {
return String.format("+%d", delta);
} else if (delta == 0) {
return "=";
}

return String.valueOf(delta);
}
}

return "";
}

private Optional<Report> getReferenceReport() {
if (model.owner == null) {
return Optional.empty();
}

Run<?, ?> lastSuccessfulBuild = model.owner.getParent().getLastSuccessfulBuild();
if (lastSuccessfulBuild != null) {
ReportAction action = lastSuccessfulBuild.getAction(ReportAction.class);
if (action != null) {
return Optional.of(action.getReport());
}
}

return Optional.empty();
}
}
}
7 changes: 4 additions & 3 deletions src/main/resources/report/help-displayType.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<div>
This can be used to change the display of the displayed metrics within the distribution table.
'absolute' shows the absolute values from the underlying files. 'relative', shows percentage values
and 'dual' shows the absolute value and additionally the relative frequency within the category.
This can be used to change the display of the displayed metrics within the distribution table.
'absolute' shows the absolute values from the underlying files. 'relative', shows percentage values,
'dual' shows the absolute value and additionally the relative frequency within the category and 'delta'
shows the absolute value and additionally the delta to the last successful build.
</div>
2 changes: 1 addition & 1 deletion src/main/resources/report/step.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
description.name=Choose a name for the report. The name is shown in the UI.
description.displayType=Select the display type of the metrics in the table. Choose between 'absolute', \
'relative' and 'dual'. As default, if nothing is specified, 'absolute is used.
'relative', 'dual' and 'delta'. As default, if nothing is specified, 'absolute is used.
Loading