Skip to content

Commit

Permalink
Merge pull request #144 from takemikami/gh_annotations
Browse files Browse the repository at this point in the history
add github annotations
  • Loading branch information
takemikami authored May 29, 2022
2 parents beee644 + bc5e98d commit 8d91d83
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/main/java/com/github/imas/rdflint/LintProblemFormatter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.imas.rdflint;

import com.github.imas.rdflint.LintProblem.ErrorLevel;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.OutputStream;
import java.io.PrintWriter;
Expand Down Expand Up @@ -78,6 +79,42 @@ public static void out(OutputStream out, LintProblemSet problems) {
pw.flush();
}

/**
* dump formatted problems.
*/
@SuppressFBWarnings(value = "DM_DEFAULT_ENCODING")
public static void annotationGitHubAction(OutputStream out, LintProblemSet problems) {
PrintWriter pw = new PrintWriter(out);
problems.getProblemSet().forEach((f, l) -> {
l.forEach(m -> {
Object[] args = LintProblemFormatter.buildArguments(m);
String msg = LintProblemFormatter.dumpMessage(m.getKey(), null, args);
long lineNoBegin = 1;
long lineNoEnd = 1;
if (m.getLocation() != null && m.getLocation().getBeginLine() >= 0) {
lineNoBegin = m.getLocation().getBeginLine();
if (m.getLocation().getEndLine() >= 0) {
lineNoEnd = m.getLocation().getEndLine();
} else {
lineNoEnd = lineNoBegin;
}
}
pw.println(String.format(
"::%s file=%s,line=%d,endLine=%d,title=%s#L%d::%s",
m.getLevel() == ErrorLevel.INFO ? "warning" : "error",
f,
lineNoBegin,
lineNoEnd,
f,
lineNoBegin,
msg
));
});
pw.println();
});
pw.flush();
}

/**
* dump yaml-formatted problems.
*/
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/github/imas/rdflint/RdfLint.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ public static void main(String[] args) throws ParseException, IOException {
if (problems.hasProblem()) {
Path problemsPath = Paths.get(params.getOutputDir() + "/rdflint-problems.yml");
LintProblemFormatter.out(System.out, problems);
if ("true".equals(System.getenv("GITHUB_ACTIONS"))) {
LintProblemFormatter.annotationGitHubAction(System.out, problems);
}
LintProblemFormatter.yaml(Files.newOutputStream(problemsPath), problems);
final String minErrorLevel = cmd.getOptionValue("minErrorLevel", "WARN");
final LintProblem.ErrorLevel errorLevel = LintProblem.ErrorLevel.valueOf(minErrorLevel);
Expand Down

0 comments on commit 8d91d83

Please sign in to comment.