Home

Awesome

There are very few users of this tool, so I am archiving it and referring to:


Violation Comments to GitLab Gradle Plugin

Build Status Maven Central

This is a Gradle plugin for Violation Comments to GitLab Lib.

It can parse results from static code analysis and comment merge requests in GitLab with them.

An alternative is also to have violations-command-line convert the violations to CodeClimate format and upload that to GitLab. It is explained in readme of violations-command-line.

The merge must be performed first in order for the commented lines in the MR to match the lines reported by the analysis tools!

Example of supported reports are available here.

A number of parsers have been implemented. Some parsers can parse output from several reporters.

ReporterParserNotes
ARM-GCCCLANG
AndroidLintANDROIDLINT
AnsibleLintFLAKE8With -p
BanditCLANGWith bandit -r examples/ -f custom -o bandit.out --msg-template "{abspath}:{line}: {severity}: {test_id}: {msg}"
CLangCLANG
CPDCPD
CPPCheckCPPCHECKWith cppcheck test.cpp --output-file=cppcheck.xml --xml
CPPLintCPPLINT
CSSLintCSSLINT
CheckstyleCHECKSTYLE
CodeClimateCODECLIMATE
CodeNarcCODENARC
DetektCHECKSTYLEWith --output-format xml.
DocFXDOCFX
DoxygenCLANG
ERBCLANGWith erb -P -x -T '-' "${it}" | ruby -c 2>&1 >/dev/null | grep '^-' | sed -E 's/^-([a-zA-Z0-9:]+)/${filename}\1 ERROR:/p' > erbfiles.out.
ESLintCHECKSTYLEWith format: 'checkstyle'.
FindbugsFINDBUGS
Flake8FLAKE8
FxCopFXCOP
GCCCLANG
GendarmeGENDARME
Generic reporterGENERICWill create one single violation with all the content as message.
GoLintGOLINT
GoVetGOLINTSame format as GoLint.
GolangCI-LintCHECKSTYLEWith --out-format=checkstyle.
GoogleErrorProneGOOGLEERRORPRONE
HadoLintCHECKSTYLEWith -f checkstyle
IARIARWith --no_wrap_diagnostics
InferPMDFacebook Infer. With --pmd-xml.
JCReportJCREPORT
JSHintJSLINTWith --reporter=jslint or the CHECKSTYLE parser with --reporter=checkstyle
JUnitJUNITIt only contains the failures.
KTLintCHECKSTYLE
KlocworkKLOCWORK
KotlinGradleKOTLINGRADLEOutput from Kotlin Gradle Plugin.
KotlinMavenKOTLINMAVENOutput from Kotlin Maven Plugin.
LintLINTA common XML format, used by different linters.
MSBuildLogMSBULDLOGWith -fileLogger use .*msbuild\\.log$ as pattern or -fl -flp:logfile=MyProjectOutput.log;verbosity=diagnostic for a custom output filename
MSCppMSCPP
MccabeFLAKE8
MyPyMYPY
NullAwayGOOGLEERRORPRONESame format as Google Error Prone.
PCLintPCLINTPC-Lint using the same output format as the Jenkins warnings plugin, details here
PHPCSCHECKSTYLEWith phpcs api.php --report=checkstyle.
PHPPMDPMDWith phpmd api.php xml ruleset.xml.
PMDPMD
Pep8FLAKE8
PerlCriticPERLCRITIC
PiTestPITEST
ProtoLintPROTOLINT
Puppet-LintCLANGWith -log-format %{fullpath}:%{line}:%{column}: %{kind}: %{message}
PyDocStylePYDOCSTYLE
PyFlakesFLAKE8
PyLintPYLINTWith pylint --output-format=parseable.
ReSharperRESHARPER
RubyCopCLANGWith rubycop -f clang file.rb
SbtScalacSBTSCALAC
ScalastyleCHECKSTYLE
SimianSIMIAN
SonarSONARWith mvn sonar:sonar -Dsonar.analysis.mode=preview -Dsonar.report.export.path=sonar-report.json. Removed in 7.7, see SONAR-11670 but can be retrieved with: curl --silent 'http://sonar-server/api/issues/search?componentKeys=unique-key&resolved=false' | jq -f sonar-report-builder.jq > sonar-report.json.
SpotbugsFINDBUGS
StyleCopSTYLECOP
SwiftLintCHECKSTYLEWith --reporter checkstyle.
TSLintCHECKSTYLEWith -t checkstyle
XMLLintXMLLINT
XUnitXUNITIt only contains the failures.
YAMLLintYAMLLINTWith -f parsable
ZPTLintZPTLINT

Missing a format? Open an issue here!

Usage

There is a running example here and it is invoked here.

Here is and example:

buildscript {
 repositories {
  maven { url 'https://plugins.gradle.org/m2/' }
 }
 dependencies {
  classpath "se.bjurr.violations:violation-comments-to-gitlab-gradle-plugin:X"
 }
}

apply plugin: "se.bjurr.violations.violation-comments-to-gitlab-gradle-plugin"

task violationCommentsToGitLab(type: se.bjurr.violations.comments.gitlab.plugin.gradle.ViolationCommentsToGitLabTask) {
 gitLabUrl = System.properties['GITLAB_URL'];
 mergeRequestIid = System.properties['GITLAB_MERGEREQUESTIID'];
 projectId = System.properties['GITLAB_PROJECTID'];

 commentOnlyChangedContent = true;
 commentOnlyChangedContentContext = 0;
 createCommentWithAllSingleFileComments = true;
 createSingleFileComments = true;
 keepOldComments = false;
 minSeverity = "INFO";
 maxNumberOfComments = 99999;
 //commentTemplate = """
 // See https://github.com/tomasbjerre/violation-comments-lib
 //""" 

 apiTokenPrivate = true;
 apiToken = System.properties['GITLAB_APITOKEN'];
 ignoreCertificateErrors = true;

 shouldSetWip = false;
 
 //proxyServer = ""
 //proxyUser = ""
 //proxyPassword = ""
 
 violations = [
  ["FINDBUGS",   ".", ".*/findbugs/.*\\.xml\$",   "Findbugs"],
  ["PMD",        ".", ".*/pmd/.*\\.xml\$",        "PMD"],
  ["CHECKSTYLE", ".", ".*/checkstyle/.*\\.xml\$", "Checkstyle"],
  ["JSHINT",     ".", ".*/jshint/.*\\.xml\$",     "JSHint"],
  ["CSSLINT",    ".", ".*/csslint/.*\\.xml\$",     "CssLint"]
 ]
}

You may also have a look at Violations Lib.

Developer instructions

To build the code you need to run build.sh in root of repo. You may also have a look at .travis.yml.

To do a release you need to do ./gradlew release -Dgradle.publish.key=... -Dgradle.publish.secret=... and release the artifact from staging. More information here.