Skip to content

Commit

Permalink
Merge pull request #356 from uhafner/improve-markdown-output
Browse files Browse the repository at this point in the history
Improve layout of Markdown
  • Loading branch information
uhafner committed May 8, 2024
2 parents 171d57a + a61bc24 commit a15e6bb
Show file tree
Hide file tree
Showing 15 changed files with 240 additions and 47 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name: 'GitHub CI'
on:
push:
branches:
- master
- main
pull_request:

Expand Down Expand Up @@ -34,4 +33,4 @@ jobs:
- name: Build with Maven
env:
BROWSER: chrome-container
run: mvn -V --color always -ntp clean verify --file pom.xml '-Djenkins.test.timeout=5000' '-Dgpg.skip'
run: mvn -V --color always -ntp clean verify '-Djenkins.test.timeout=5000' '-Dgpg.skip' '-Pci'
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
queries: +security-and-quality

- name: Build with Maven
run: mvn -V --color always -ntp clean verify --file pom.xml -Pskip
run: mvn -V --color always -ntp clean verify -Pskip

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name: 'CodeCov'
on:
push:
branches:
- master
- main
pull_request:

Expand All @@ -27,7 +26,7 @@ jobs:
with:
maven-version: 3.9.6
- name: Generate coverage with JaCoCo
run: mvn -V --color always -ntp clean verify '-Dgpg.skip'
run: mvn -V --color always -ntp clean verify -Dgpg.skip -Pci
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4.3.1
with:
Expand Down
81 changes: 80 additions & 1 deletion .github/workflows/quality-monitor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Build with Maven
env:
BROWSER: chrome-container
run: mvn -V --color always -ntp clean verify -Ppit | tee maven.log
run: mvn -V --color always -ntp clean verify -Ppit -Pci | tee maven.log
- name: Extract pull request number
uses: jwalton/gh-find-current-pr@v1
id: pr
Expand All @@ -34,3 +34,82 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
pr-number: ${{ steps.pr.outputs.number }}
config: >
{
"tests": {
"tools": [
{
"id": "test",
"name": "Tests",
"pattern": "**/target/*-reports/TEST*.xml"
}
],
"name": "Tests"
},
"analysis": [
{
"name": "Style",
"id": "style",
"tools": [
{
"id": "checkstyle",
"pattern": "**/target/checkstyle-*/checkstyle-result.xml"
},
{
"id": "pmd",
"pattern": "**/target/pmd-*/pmd.xml"
}
]
},
{
"name": "Bugs",
"id": "bugs",
"icon": "bug",
"tools": [
{
"id": "spotbugs",
"sourcePath": "src/main/java",
"pattern": "**/target/spotbugsXml.xml"
},
{
"id": "error-prone",
"icon": "bug",
"pattern": "**/maven.log"
}
]
}
],
"coverage": [
{
"name": "Code Coverage",
"tools": [
{
"id": "jacoco",
"name": "Line Coverage",
"metric": "line",
"sourcePath": "src/main/java",
"pattern": "**/target/site/jacoco/jacoco.xml"
},
{
"id": "jacoco",
"name": "Branch Coverage",
"metric": "branch",
"sourcePath": "src/main/java",
"pattern": "**/target/site/jacoco/jacoco.xml"
}
]
},
{
"name": "Mutation Coverage",
"tools": [
{
"id": "pit",
"name": "Mutation Coverage",
"metric": "mutation",
"sourcePath": "src/main/java",
"pattern": "**/target/pit-reports/mutations.xml"
}
]
}
]
}
78 changes: 78 additions & 0 deletions .github/workflows/update-badges.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,84 @@ jobs:
uses: uhafner/quality-monitor@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
config: >
{
"tests": {
"tools": [
{
"id": "test",
"name": "Tests",
"pattern": "**/target/*-reports/TEST*.xml"
}
],
"name": "Tests"
},
"analysis": [
{
"name": "Style",
"id": "style",
"tools": [
{
"id": "checkstyle",
"pattern": "**/target/checkstyle-*/checkstyle-result.xml"
},
{
"id": "pmd",
"pattern": "**/target/pmd-*/pmd.xml"
}
]
},
{
"name": "Bugs",
"id": "bugs",
"icon": "bug",
"tools": [
{
"id": "spotbugs",
"sourcePath": "src/main/java",
"pattern": "**/target/spotbugsXml.xml"
},
{
"id": "error-prone",
"pattern": "**/maven.log"
}
]
}
],
"coverage": [
{
"name": "Code Coverage",
"tools": [
{
"id": "jacoco",
"name": "Line Coverage",
"metric": "line",
"sourcePath": "src/main/java",
"pattern": "**/target/site/jacoco/jacoco.xml"
},
{
"id": "jacoco",
"name": "Branch Coverage",
"metric": "branch",
"sourcePath": "src/main/java",
"pattern": "**/target/site/jacoco/jacoco.xml"
}
]
},
{
"name": "Mutation Coverage",
"tools": [
{
"id": "pit",
"name": "Mutation Coverage",
"metric": "mutation",
"sourcePath": "src/main/java",
"pattern": "**/target/pit-reports/mutations.xml"
}
]
}
]
}
- name: Write metrics to GitHub output
id: metrics
run: |
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>edu.hm.hafner</groupId>
<artifactId>codingstyle-pom</artifactId>
<version>4.5.0</version>
<version>4.9.0</version>
<relativePath />
</parent>

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/edu/hm/hafner/grading/AnalysisMarkdown.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ private int sum(final AnalysisScore score, final Function<AnalysisScore, Integer

protected String extractSeverities(final AnalysisScore score) {
if (score.getReport().isEmpty()) {
return "No warnings found";
return "No warnings";
}
else {
return String.format("%d warning%s found (%d error%s, %d high, %d normal, %d low)",
return String.format("%d warning%s (%d error%s, %d high, %d normal, %d low)",
score.getTotalSize(), AnalysisScore.plural(score.getTotalSize()),
score.getErrorSize(), AnalysisScore.plural(score.getErrorSize()),
score.getHighSeveritySize(),
Expand Down Expand Up @@ -121,7 +121,7 @@ private String getIconAndName(final AnalysisScore analysisScore) {
private String extractParserIcon(final AnalysisScore analysisScore) {
var descriptor = REGISTRY.get(analysisScore.getId());
if (descriptor.getIconUrl().isEmpty()) {
return ":exclamation:";
return getIcon(analysisScore);
}
else {
return "<img src=\"%s\" alt=\"%s\" height=\"%d\" width=\"%d\">"
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/edu/hm/hafner/grading/AnalysisScore.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ public int getTotalSize() {
@Override
protected String createSummary() {
if (getReport().isEmpty()) {
return "No warnings found";
return "No warnings";
}
else {
return String.format("%d warning%s found (%d error%s, %d high, %d normal, %d low)",
return String.format("%d warning%s (%d error%s, %d high, %d normal, %d low)",
getTotalSize(), plural(getTotalSize()),
getErrorSize(), plural(getErrorSize()),
getHighSeveritySize(), getNormalSeveritySize(), getLowSeveritySize());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.nio.file.Path;

import org.apache.commons.lang3.StringUtils;

import edu.hm.hafner.analysis.FileReaderFactory;
import edu.hm.hafner.analysis.Report;
import edu.hm.hafner.analysis.registry.ParserDescriptor;
Expand All @@ -23,17 +25,22 @@ public final class FileSystemAnalysisReportFactory implements AnalysisReportFact
public Report create(final ToolConfiguration tool, final FilteredLog log) {
ParserDescriptor parser = new ParserRegistry().get(tool.getId());

var total = new Report(tool.getId(), tool.getDisplayName());
var displayName = getDisplayName(tool, parser.getName());
var total = new Report(tool.getId(), displayName);

var analysisParser = parser.createParser();
for (Path file : REPORT_FINDER.find(tool, log)) {
for (Path file : REPORT_FINDER.find(log, displayName, tool.getPattern())) {
Report report = analysisParser.parseFile(new FileReaderFactory(file));
report.setOrigin(tool.getId(), tool.getDisplayName());
report.setOrigin(tool.getId(), displayName);
log.logInfo("- %s: %d warnings", PATH_UTIL.getRelativePath(file), report.size());
total.addAll(report);
}

log.logInfo("-> %s Total: %d warnings", tool.getDisplayName(), total.size());
log.logInfo("-> %s Total: %d warnings", displayName, total.size());
return total;
}

private String getDisplayName(final ToolConfiguration tool, final String defaultName) {
return StringUtils.defaultIfBlank(tool.getName(), defaultName);
}
}
16 changes: 11 additions & 5 deletions src/main/java/edu/hm/hafner/grading/ReportFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,20 @@ class ReportFinder {
*
* @return the paths
*/
public List<Path> find(final ToolConfiguration tool, final FilteredLog log) {
log.logInfo("Searching for %s results matching file name pattern %s",
tool.getDisplayName(), tool.getPattern());
List<Path> files = find("glob:" + tool.getPattern(), ".", log);
List<Path> find(final ToolConfiguration tool, final FilteredLog log) {
var displayName = tool.getDisplayName();
var pattern = tool.getPattern();

return find(log, displayName, pattern);
}

List<Path> find(final FilteredLog log, final String displayName, final String pattern) {
log.logInfo("Searching for %s results matching file name pattern %s", displayName, pattern);
List<Path> files = find("glob:" + pattern, ".", log);

if (files.isEmpty()) {
log.logError("No matching report files found when using pattern '%s'! "
+ "Configuration error for '%s'?", tool.getPattern(), tool.getDisplayName());
+ "Configuration error for '%s'?", pattern, displayName);
}

Collections.sort(files);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/edu/hm/hafner/grading/TestMarkdown.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ protected String createSummary(final TestScore score) {
- :microscope: &nbsp; Mutation Coverage: 93% mutations killed
- ☑️ 99% Test strength
---
- :warning: &nbsp; Style:: No warnings found
- :bug: &nbsp; Bugs: No warnings found
- :warning: &nbsp; Style:: No warnings
- :bug: &nbsp; Bugs: No warnings
<br/>
Created by [Quality Monitor](https://github.com/uhafner/quality-monitor/releases/tag/v1.6.0) v1.6.0 (#85eae94). More details are shown in the [GitHub Checks Result](https://github.com/jenkinsci/coverage-model/runs/23474192891).
Expand Down
20 changes: 10 additions & 10 deletions src/test/java/edu/hm/hafner/grading/AnalysisMarkdownTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void shouldShowMaximumScore() {
.contains(IMPACT_CONFIGURATION);
assertThat(analysisMarkdown.createSummary(score))
.contains("CheckStyle - 100 of 100")
.contains("No warnings found");
.contains("No warnings");
}

@Test
Expand Down Expand Up @@ -87,7 +87,7 @@ void shouldShowScoreWithOneResult() {
var analysisMarkdown = new AnalysisMarkdown();

assertThat(analysisMarkdown.createSummary(score)).contains(
"CS - 70 of 100: 10 warnings found (1 error, 2 high, 3 normal, 4 low)");
"CS - 70 of 100: 10 warnings (1 error, 2 high, 3 normal, 4 low)");
assertThat(analysisMarkdown.createDetails(score))
.contains("TopLevel Warnings - 70 of 100")
.contains("|CS|1|1|2|3|4|10|-30")
Expand Down Expand Up @@ -126,8 +126,8 @@ void shouldShowScoreWithTwoSubResults() {

assertThat(analysisMarkdown.createSummary(score))
.contains(
"CheckStyle - 70 of 100: 10 warnings found (1 error, 2 high, 3 normal, 4 low)",
"SpotBugs - 80 of 100: 10 warnings found (4 errors, 3 high, 2 normal, 1 low)");
"CheckStyle - 70 of 100: 10 warnings (1 error, 2 high, 3 normal, 4 low)",
"SpotBugs - 80 of 100: 10 warnings (4 errors, 3 high, 2 normal, 1 low)");
assertThat(analysisMarkdown.createDetails(score))
.contains("CheckStyle - 50 of 100",
"|CheckStyle|1|1|2|3|4|10|-30",
Expand Down Expand Up @@ -162,8 +162,8 @@ void shouldShowNoImpactsWithTwoSubResults() {
var analysisMarkdown = new AnalysisMarkdown();

assertThat(analysisMarkdown.createSummary(score))
.contains("CheckStyle: 10 warnings found (1 error, 2 high, 3 normal, 4 low)",
"SpotBugs: 10 warnings found (4 errors, 3 high, 2 normal, 1 low)");
.contains("CheckStyle: 10 warnings (1 error, 2 high, 3 normal, 4 low)",
"SpotBugs: 10 warnings (4 errors, 3 high, 2 normal, 1 low)");
assertThat(analysisMarkdown.createDetails(score))
.contains("CheckStyle",
"|CheckStyle|1|1|2|3|4|10",
Expand Down Expand Up @@ -217,10 +217,10 @@ void shouldShowScoreWithTwoResults() {
":moneybag:|:heavy_minus_sign:|*1*|*2*|*3*|*4*|:heavy_minus_sign:|:heavy_minus_sign:",
":moneybag:|:heavy_minus_sign:|*-11*|*-12*|*-13*|*-14*|:heavy_minus_sign:|:heavy_minus_sign:");
assertThat(analysisMarkdown.createSummary(score))
.contains("CheckStyle 1 - 30 of 100: 10 warnings found (1 error, 2 high, 3 normal, 4 low)",
"CheckStyle 2 - 30 of 100: 10 warnings found (1 error, 2 high, 3 normal, 4 low)",
"SpotBugs 1 - 0 of 100: 10 warnings found (4 errors, 3 high, 2 normal, 1 low)",
"SpotBugs 2 - 0 of 100: 10 warnings found (4 errors, 3 high, 2 normal, 1 low)")
.contains("CheckStyle 1 - 30 of 100: 10 warnings (1 error, 2 high, 3 normal, 4 low)",
"CheckStyle 2 - 30 of 100: 10 warnings (1 error, 2 high, 3 normal, 4 low)",
"SpotBugs 1 - 0 of 100: 10 warnings (4 errors, 3 high, 2 normal, 1 low)",
"SpotBugs 2 - 0 of 100: 10 warnings (4 errors, 3 high, 2 normal, 1 low)")
.doesNotContain("Total");
}

Expand Down
Loading

0 comments on commit a15e6bb

Please sign in to comment.