Skip to content

Commit

Permalink
Add markdown details as additional parameter.
Browse files Browse the repository at this point in the history
For analysis issues, these details will be filled with
the documentation of the corresponding static analysis tool.

See uhafner/autograding-gitlab-action#27
  • Loading branch information
uhafner committed Mar 23, 2024
1 parent d65a1b6 commit bf493b1
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions src/main/java/edu/hm/hafner/grading/CommentBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.apache.commons.lang3.StringUtils;

import edu.hm.hafner.analysis.Issue;
import edu.hm.hafner.analysis.registry.ParserRegistry;
import edu.hm.hafner.coverage.FileNode;
import edu.hm.hafner.coverage.Metric;
import edu.hm.hafner.coverage.Mutation;
Expand Down Expand Up @@ -77,22 +78,32 @@ public void createAnnotations(final AggregatedScore score) {
* @param lineEnd
* end line of the comment
* @param message
* message of the comment
* plain text message of the comment
* @param title
* title of the comment
* plain text title of the comment
* @param columnStart
* column of the comment (-1 if not applicable)
* @param columnEnd
* column of the comment (-1 if not applicable)
* @param details
* additional details of the comment (empty if not applicable)
* additional plain text details of the comment (empty if not applicable)
* @param markDownDetails
* additional details of the comment in Markdown (empty if not applicable)
*/
@SuppressWarnings("checkstyle:ParameterNumber")
protected abstract void createComment(CommentType commentType, String relativePath,
int lineStart, int lineEnd,
String message, String title,
int columnStart, int columnEnd,
String details);
String details, String markDownDetails);

private void createComment(final CommentType commentType, final String relativePath,
final int lineStart, final int lineEnd,
final String message, final String title) {
createComment(commentType, relativePath, lineStart, lineEnd, message, title,
NO_COLUMN, NO_COLUMN,
NO_ADDITIONAL_DETAILS, NO_ADDITIONAL_DETAILS);
}

private Set<String> extractAdditionalSourcePaths(final List<? extends Score<?, ?>> scores) {
return scores.stream()
Expand All @@ -111,9 +122,19 @@ private void createAnnotationForIssue(final Issue issue,
final Set<String> sourcePaths) {
var relativePath = cleanPath(createRelativeRepositoryPath(issue.getFileName(), sourcePaths));

var text = getDescription(issue);

createComment(CommentType.WARNING, relativePath, issue.getLineStart(), issue.getLineEnd(),
issue.getMessage(), issue.getOriginName() + ": " + issue.getType(), issue.getColumnStart(),
issue.getColumnEnd(), NO_ADDITIONAL_DETAILS);
issue.getColumnEnd(), NO_ADDITIONAL_DETAILS, text);
}

private String getDescription(final Issue issue) {
var parserRegistry = new ParserRegistry();
if (parserRegistry.contains(issue.getOrigin())) {
return parserRegistry.get(issue.getOrigin()).getDescription(issue);
}
return issue.getDescription();
}

private String cleanPath(final String path) {
Expand Down Expand Up @@ -141,8 +162,7 @@ private void createAnnotationForMissedLineRange(final FileNode file, final LineR
createComment(CommentType.NO_COVERAGE,
relativePath, range.getStart(),
range.getEnd(), getMissedLinesDescription(range),
getMissedLinesMessage(range), NO_COLUMN,
NO_COLUMN, NO_ADDITIONAL_DETAILS);
getMissedLinesMessage(range));
}

private String getMissedLinesMessage(final LineRange range) {
Expand Down Expand Up @@ -177,7 +197,7 @@ private void createAnnotationForMissedBranches(final FileNode file,
createComment(CommentType.PARTIAL_COVERAGE,
createRelativeRepositoryPath(file.getRelativePath(), sourcePaths), branchCoverage.getKey(),
branchCoverage.getKey(), createBranchMessage(branchCoverage.getKey(), branchCoverage.getValue()),
"Partially covered line", NO_COLUMN, NO_COLUMN, NO_ADDITIONAL_DETAILS);
"Partially covered line");
}

private String createBranchMessage(final int line, final int missed) {
Expand Down Expand Up @@ -216,11 +236,13 @@ private void createAnnotationsForSurvivedMutations(final FileNode file,
private void createAnnotationForSurvivedMutation(final FileNode file,
final Entry<Integer, List<Mutation>> mutationsPerLine,
final Set<String> sourcePaths) {
var mutationDetails = createMutationDetails(mutationsPerLine.getValue());
createComment(CommentType.MUTATION_SURVIVED,
createRelativeRepositoryPath(file.getRelativePath(), sourcePaths), mutationsPerLine.getKey(),
mutationsPerLine.getKey(),
createMutationMessage(mutationsPerLine.getKey(), mutationsPerLine.getValue()),
"Mutation survived", NO_COLUMN, NO_COLUMN, createMutationDetails(mutationsPerLine.getValue()));
"Mutation survived", NO_COLUMN, NO_COLUMN,
mutationDetails, mutationDetails);
}

private String createMutationMessage(final int line, final List<Mutation> survived) {
Expand Down

0 comments on commit bf493b1

Please sign in to comment.