Skip to content

Commit

Permalink
add possibility to change status color (via #23)
Browse files Browse the repository at this point in the history
  • Loading branch information
eroshenkoam authored Mar 21, 2022
1 parent bbd2c9b commit 3510ccd
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 36 deletions.
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ repositories {

dependencies {
annotationProcessor("info.picocli:picocli-codegen:4.1.4")
annotationProcessor("org.projectlombok:lombok:1.18.12")

compileOnly("org.projectlombok:lombok:1.18.12")

implementation("com.fasterxml.jackson.core:jackson-databind:2.10.2")
implementation("org.apache.commons:commons-collections4:4.4")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import java.util.stream.Collectors;

import static io.github.eroshenkoam.allure.FontHolder.loadArialFont;
import static io.github.eroshenkoam.allure.util.ColorUtils.statusTextColor;
import static io.github.eroshenkoam.allure.util.PdfUtil.addEmptyLine;
import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.joining;
Expand All @@ -48,11 +47,13 @@ public class AllurePDFGenerator {
private final String reportName;
private final Path reportPath;
private final Map<String, String> filter;
private final StatusColors statusColors;

public AllurePDFGenerator(final String reportName, final Path reportPath) {
public AllurePDFGenerator(final String reportName, final Path reportPath, final StatusColors statusColors) {
this.filter = new HashMap<>();
this.reportName = reportName;
this.reportPath = reportPath;
this.statusColors = statusColors;
}

public void filter(final Map<String, String> tags) {
Expand Down Expand Up @@ -171,7 +172,7 @@ private void addSteps(final TestResult testResult, final FontHolder fontHolder,
private com.lowagie.text.List createStepsList(final List<StepResult> steps, final FontHolder fontHolder) {
final com.lowagie.text.List stepList = new com.lowagie.text.List(true);
steps.forEach(step -> {
final Font font = fontHolder.normal(statusTextColor(step.getStatus()));
final Font font = fontHolder.normal(statusColors.getStatusColor(step.getStatus()));
final ListItem stepItem = new ListItem(String.format("%s", step.getName()), font);
final StatusDetails statusDetails = step.getStatusDetails();
if (Objects.nonNull(statusDetails) && Objects.nonNull(statusDetails.getMessage())) {
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/io/github/eroshenkoam/allure/MainCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.eroshenkoam.allure;

import io.github.eroshenkoam.allure.option.StatusColorOptions;
import io.qameta.allure.model.Status;
import picocli.CommandLine;

import java.io.IOException;
Expand Down Expand Up @@ -32,12 +34,21 @@ public class MainCommand implements Runnable {
protected String reportName;

@CommandLine.Option(names = {"-f", "--filter"})
Map<String, String> filter;
protected Map<String, String> filter;

@CommandLine.ArgGroup
protected StatusColorOptions statusColorOptions = new StatusColorOptions();

@Override
public void run() {
try {
final AllurePDFGenerator generator = new AllurePDFGenerator(reportName, reportPath);
final StatusColors statusColors = new StatusColors();
statusColors.setStatusColors(Status.PASSED, statusColorOptions.getPassed());
statusColors.setStatusColors(Status.FAILED, statusColorOptions.getFailed());
statusColors.setStatusColors(Status.BROKEN, statusColorOptions.getBroken());
statusColors.setStatusColors(Status.SKIPPED, statusColorOptions.getSkipped());

final AllurePDFGenerator generator = new AllurePDFGenerator(reportName, reportPath, statusColors);
generator.filter(filter);
generator.generate(outputPath);
;
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/io/github/eroshenkoam/allure/StatusColors.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.github.eroshenkoam.allure;

import io.qameta.allure.model.Status;

import java.awt.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

public class StatusColors {

private final Map<Status, String> statusColors;

public StatusColors() {
statusColors = new HashMap<Status, String>() {{
put(Status.PASSED, "#97cc64");
put(Status.FAILED, "#fd5a3e");
put(Status.BROKEN, "#ffd050");
put(Status.SKIPPED, "#aaaaaa");
}};
}

public void setStatusColors(final Status status, String color) {
statusColors.put(status, color);
}

public Color getStatusColor(final Status status) {
final String hex = Optional.ofNullable(status)
.map(statusColors::get)
.orElse("#BF98A6FF");
return Color.decode(hex);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.github.eroshenkoam.allure.option;

import lombok.Data;
import lombok.experimental.Accessors;
import picocli.CommandLine;

import java.io.Serializable;

@Data
@Accessors(chain = true)
public class StatusColorOptions implements Serializable {

private static final long serialVersionUID = 1L;

@CommandLine.Option(names = "--status.color.passed", defaultValue = "#97cc64")
private String passed;
@CommandLine.Option(names = "--status.color.failed", defaultValue = "#fd5a3e")
private String failed;
@CommandLine.Option(names = "--status.color.broken", defaultValue = "#ffd050")
private String broken;
@CommandLine.Option(names = "--status.color.skipped", defaultValue = "#aaaaaa")
private String skipped;

}
31 changes: 0 additions & 31 deletions src/main/java/io/github/eroshenkoam/allure/util/ColorUtils.java

This file was deleted.

0 comments on commit 3510ccd

Please sign in to comment.