diff --git a/plugin/src/main/java/io/jenkins/plugins/coverage/metrics/steps/CoverageChecksPublisher.java b/plugin/src/main/java/io/jenkins/plugins/coverage/metrics/steps/CoverageChecksPublisher.java index 0cbb6ca34..1d0556b29 100644 --- a/plugin/src/main/java/io/jenkins/plugins/coverage/metrics/steps/CoverageChecksPublisher.java +++ b/plugin/src/main/java/io/jenkins/plugins/coverage/metrics/steps/CoverageChecksPublisher.java @@ -52,6 +52,7 @@ class CoverageChecksPublisher { private static final int TITLE_HEADER_LEVEL = 4; private static final char NEW_LINE = '\n'; private static final String COLUMN = "|"; + private static final String GAP = " "; private final CoverageBuildAction action; private final Node rootNode; @@ -434,21 +435,15 @@ private String formatText(final TextFormat format, final String text) { } private String getTrendIcon(final String trend) { - if (trend.startsWith("+")) { - return " " + Icon.ARROW_UP.markdown; - } - else if (trend.startsWith("-")) { - return " " + Icon.ARROW_DOWN.markdown; - } - else if (trend.startsWith("n/a")) { + if (!StringUtils.containsAny(trend, "123456789") || trend.startsWith("n/a")) { return StringUtils.EMPTY; } - return " " + Icon.ARROW_RIGHT.markdown; + return GAP + (trend.startsWith("+") ? Icon.ARROW_UP.markdown : Icon.ARROW_DOWN.markdown); } private String getBulletListItem(final int level, final String text) { int whitespaces = (level - 1) * TITLE_HEADER_LEVEL; - return String.join("", Collections.nCopies(whitespaces, " ")) + "* " + text + "\n"; + return String.join("", Collections.nCopies(whitespaces, GAP)) + "* " + text + "\n"; } private String getUrlText(final String text, final String url) { @@ -456,7 +451,7 @@ private String getUrlText(final String text, final String url) { } private String getSectionHeader(final int level, final String text) { - return String.join("", Collections.nCopies(level, "#")) + " " + text + "\n\n"; + return String.join("", Collections.nCopies(level, "#")) + GAP + text + "\n\n"; } private ChecksConclusion getCheckConclusion(final QualityGateStatus status) { diff --git a/plugin/src/main/java/io/jenkins/plugins/coverage/metrics/steps/PathResolver.java b/plugin/src/main/java/io/jenkins/plugins/coverage/metrics/steps/PathResolver.java index 7103b1365..44fe887f6 100644 --- a/plugin/src/main/java/io/jenkins/plugins/coverage/metrics/steps/PathResolver.java +++ b/plugin/src/main/java/io/jenkins/plugins/coverage/metrics/steps/PathResolver.java @@ -28,13 +28,13 @@ /** * Resolves source code files on the agent using the stored paths of the coverage reports. Since these paths are - * relative this resolver tries to find the absolute paths by guessing the prefix to the relative path. It also + * relative, this resolver tries to find the absolute paths by guessing the prefix to the relative path. It also * evaluates the defined source paths as prefixes when resolving the absolute paths. */ public class PathResolver { /** * Resolves source code files on the agent using the stored paths of the coverage reports. Since these paths are - * relative this resolver tries to find the absolute paths by guessing the prefix to the relative path. It also + * relative, this resolver tries to find the absolute paths by guessing the prefix to the relative path. It also * evaluates the defined source paths as prefixes when resolving the absolute paths. * * @param relativePaths @@ -71,7 +71,7 @@ public Map resolvePaths(final Set relativePaths, /** * Resolves source code files on the agent using the stored paths of the coverage reports. Since these paths are - * relative this resolver tries to find the absolute paths by guessing the prefix to the relative path. It also + * relative, this resolver tries to find the absolute paths by guessing the prefix to the relative path. It also * evaluates the defined source paths as prefixes when resolving the absolute paths. */ static class AgentPathResolver extends MasterToSlaveFileCallable>> { diff --git a/plugin/src/test/java/io/jenkins/plugins/coverage/metrics/steps/CoverageChecksPublisherTest.java b/plugin/src/test/java/io/jenkins/plugins/coverage/metrics/steps/CoverageChecksPublisherTest.java index c61940243..1f50358a1 100644 --- a/plugin/src/test/java/io/jenkins/plugins/coverage/metrics/steps/CoverageChecksPublisherTest.java +++ b/plugin/src/test/java/io/jenkins/plugins/coverage/metrics/steps/CoverageChecksPublisherTest.java @@ -216,7 +216,10 @@ private CoverageBuildAction createCoverageBuildAction(final Node result) { return new CoverageBuildAction(run, COVERAGE_ID, REPORT_NAME, StringUtils.EMPTY, result, new QualityGateResult(), null, "refId", - new TreeMap<>(Map.of(Metric.LINE, Fraction.ONE_HALF, Metric.MODULE, Fraction.ONE_FIFTH)), + new TreeMap<>(Map.of( + Metric.LINE, Fraction.ONE_HALF, + Metric.MODULE, Fraction.ZERO, + Metric.PACKAGE, Fraction.ONE_HALF.negate())), List.of(testCoverage), new TreeMap<>(Map.of(Metric.LINE, Fraction.ONE_HALF)), List.of(testCoverage), new TreeMap<>(Map.of(Metric.LINE, Fraction.ONE_HALF)), List.of(testCoverage), false); } diff --git a/plugin/src/test/resources/io/jenkins/plugins/coverage/metrics/steps/coverage-publisher-details.checks-expected-result b/plugin/src/test/resources/io/jenkins/plugins/coverage/metrics/steps/coverage-publisher-details.checks-expected-result index b8352bee7..56941c726 100644 --- a/plugin/src/test/resources/io/jenkins/plugins/coverage/metrics/steps/coverage-publisher-details.checks-expected-result +++ b/plugin/src/test/resources/io/jenkins/plugins/coverage/metrics/steps/coverage-publisher-details.checks-expected-result @@ -3,7 +3,7 @@ ||Module Coverage|Package Coverage|File Coverage|Class Coverage|Method Coverage|Line Coverage|Branch Coverage|Instruction Coverage |:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---: :feet: **Overall project**|100.00% (1/1)|100.00% (4/4)|70.00% (7/10)|83.33% (15/18)|95.10% (97/102)|91.02% (294/323)|93.97% (109/116)|93.33% (1260/1350) -:chart_with_upwards_trend: **Overall project (difference to reference job)**|+20.00% :arrow_up:|n/a|n/a|n/a|n/a|+50.00% :arrow_up:|n/a|n/a +:chart_with_upwards_trend: **Overall project (difference to reference job)**|+0.00%|-50.00% :arrow_down:|n/a|n/a|n/a|+50.00% :arrow_up:|n/a|n/a :feet: **Modified files**|n/a|n/a|n/a|n/a|n/a|50.00% (1/2)|n/a|n/a :chart_with_upwards_trend: **Modified files (difference to overall project)**|n/a|n/a|n/a|n/a|n/a|+50.00% :arrow_up:|n/a|n/a :feet: **Modified code lines**|n/a|n/a|n/a|n/a|n/a|50.00% (1/2)|n/a|n/a