Skip to content
This repository was archived by the owner on Jun 12, 2022. It is now read-only.

Commit ffb2075

Browse files
committed
Correct format
1 parent a1d78f8 commit ffb2075

File tree

2 files changed

+48
-29
lines changed

2 files changed

+48
-29
lines changed

src/main/java/io/nthienan/phdiff/report/RemarkGlobalReportBuilder.java

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,38 +51,54 @@ private StringBuilder summarize() {
5151
sum.append(bold("SonarQube")).append(" ")
5252
.append("analysis reported ")
5353
.append(bold(String.valueOf(totalIssues)))
54+
.append(" issue")
5455
.append(totalIssues > 1 ? "s" : "")
5556
.append("\n");
5657
// Blocker
57-
sum.append(" - ")
58-
.append(String.valueOf(numberOfIssues(Severity.BLOCKER)))
59-
.append(" Blocker issue")
60-
.append(numberOfIssues(Severity.BLOCKER) > 1 ? "s" : "")
61-
.append("(").append(remarkupUtils.icon(Severity.BLOCKER)).append(")\n");
58+
int blockerIssues = numberOfIssues(Severity.BLOCKER);
59+
if (blockerIssues > 0) {
60+
sum.append(" - ")
61+
.append(String.valueOf(blockerIssues))
62+
.append(" Blocker issue")
63+
.append(blockerIssues > 1 ? "s" : "")
64+
.append(" (").append(remarkupUtils.icon(Severity.BLOCKER)).append(")\n");
65+
}
6266
// Critical
63-
sum.append(" - ")
64-
.append(String.valueOf(numberOfIssues(Severity.CRITICAL)))
65-
.append(" Critical issue")
66-
.append(numberOfIssues(Severity.CRITICAL) > 1 ? "s" : "")
67-
.append("(").append(remarkupUtils.icon(Severity.CRITICAL)).append(")\n");
67+
int criticalIssues = numberOfIssues(Severity.CRITICAL);
68+
if (criticalIssues > 0) {
69+
sum.append(" - ")
70+
.append(String.valueOf(criticalIssues))
71+
.append(" Critical issue")
72+
.append(criticalIssues > 1 ? "s" : "")
73+
.append(" (").append(remarkupUtils.icon(Severity.CRITICAL)).append(")\n");
74+
}
6875
// Major
69-
sum.append(" - ")
70-
.append(String.valueOf(numberOfIssues(Severity.MAJOR)))
71-
.append(" Major issue")
72-
.append(numberOfIssues(Severity.MAJOR) > 1 ? "s" : "")
73-
.append("(").append(remarkupUtils.icon(Severity.MAJOR)).append(")\n");
76+
int majorIssues = numberOfIssues(Severity.MAJOR);
77+
if (majorIssues > 0) {
78+
sum.append(" - ")
79+
.append(String.valueOf(majorIssues))
80+
.append(" Major issue")
81+
.append(majorIssues > 1 ? "s" : "")
82+
.append(" (").append(remarkupUtils.icon(Severity.MAJOR)).append(")\n");
83+
}
7484
// Minor
75-
sum.append(" - ")
76-
.append(String.valueOf(numberOfIssues(Severity.MINOR)))
77-
.append(" Minor issue")
78-
.append(numberOfIssues(Severity.MINOR) > 1 ? "s" : "")
79-
.append("(").append(remarkupUtils.icon(Severity.MINOR)).append(")\n");
85+
int minorIssues = numberOfIssues(Severity.MINOR);
86+
if (minorIssues > 0) {
87+
sum.append(" - ")
88+
.append(String.valueOf(minorIssues))
89+
.append(" Minor issue")
90+
.append(minorIssues > 1 ? "s" : "")
91+
.append(" (").append(remarkupUtils.icon(Severity.MINOR)).append(")\n");
92+
}
8093
// Info
81-
sum.append(" - ")
82-
.append(String.valueOf(numberOfIssues(Severity.INFO)))
83-
.append(" Info issue")
84-
.append(numberOfIssues(Severity.INFO) > 1 ? "s" : "")
85-
.append("(").append(remarkupUtils.icon(Severity.INFO)).append(")\n");
94+
int infoIssues = numberOfIssues(Severity.INFO);
95+
if (infoIssues > 0) {
96+
sum.append(" - ")
97+
.append(String.valueOf(infoIssues))
98+
.append(" Info issue")
99+
.append(infoIssues > 1 ? "s" : "")
100+
.append(" (").append(remarkupUtils.icon(Severity.INFO)).append(")\n");
101+
}
86102
} else {
87103
sum.append("You are great developer.\n")
88104
.append(bold("SonarQube"))

src/main/java/io/nthienan/phdiff/report/RemarkupUtils.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ public static String icon(String icon, String color) {
5656

5757
public static String link(String url, String title) {
5858
if (StringUtils.isNotBlank(title)) {
59-
return String.format("[[%s|%s]]", encodeForUrl(url), title);
59+
return String.format("[[%s|%s]]", url, title);
6060
}
61-
return encodeForUrl(url);
61+
return url;
6262
}
6363

6464
public static String encodeForUrl(String url) {
@@ -92,15 +92,18 @@ public String icon(Severity severity) {
9292
}
9393

9494
public String source(String componentKey, int line) {
95-
return String.format("%s - %s:", italics(String.valueOf(line)), code(componentKey.replace(projectKey, "")));
95+
return String.format("%s - %s:",
96+
italics(String.valueOf(String.format("Line %s", line))),
97+
code(componentKey.replace(projectKey, "").substring(1)));
9698
}
9799

98100
public String message(String message) {
99101
return message;
100102
}
101103

102104
public String rule(String ruleKey) {
103-
return link(String.format("%s/coding_rules#rule_key=%s", this.ruleUrlPrefix, ruleKey), "View rule");
105+
return link(String.format("%s/coding_rules#rule_key=%s",
106+
this.ruleUrlPrefix, encodeForUrl(ruleKey)), "View rule");
104107
}
105108

106109
public String issue(PostJobIssue issue) {

0 commit comments

Comments
 (0)