Violation Comments to GitHub Lib
This is a library that adds violation comments from static code analysis to GitHub.
It uses Violation Comments Lib and supports the same formats as Violations Lib:
- Checkstyle
- CPPLint
- CPPCheck
- CSSLint
- Findbugs
- Flake8 (PyLint, Pep8)
- JSHint
- Lint A common XML format, used by different linters.
- PerlCritic
- PMD
- ReSharper
- XMLLint
Very easy to use with a nice builder pattern
violationsToGitHubApi() //
.withViolations(".*/findbugs/.*\\.xml$", FINDBUGS, rootFolder) //
.withViolations(".*/checkstyle/.*\\.xml$", CHECKSTYLE, rootFolder) //
.limitNumberOfCommentsTo(20) // Optional
.usingCredentials("username","password") // This is Optional!
.usingOAuth2Token("token") // This is Optional!
.toPullRequest("organization","repository",repositoryId);
Authentication can be done by supplying username/password or OAuth2Token in the builder.
Usage
This software can be used:
- With a Gradle plugin.
- With a Maven plugin.
- With a Jenkins plugin.
You may also checkout this blog post that explains how to set it up with Travis.
Travis
To set this up in Travis, you will need to create a GitHub OAuth2 token.
curl -u 'yourgithubuser' -d '{"note":"Violation comments"}' https://api.github.com/authorizations
The token needs to be encrypted before added to your .travis.yml
.
sudo apt-get install ruby-dev
gem install travis
travis encrypt export GITHUB_OAUTH2TOKEN=YOUR TOKEN HERE
Now add it to .travis.yml
like this.
sudo: false
language: java
env:
- secure: "YOUR ENCRYPTED TOKEN HERE"
jdk:
- oraclejdk7
script:
- ./gradlew build violationCommentsToGitHub -DGITHUB_PULLREQUESTID=$TRAVIS_PULL_REQUEST -DGITHUB_OAUTH2TOKEN=$GITHUB_OAUTH2TOKEN -i --stacktrace
notifications:
email: false
Here I used Gradle plugin but you can do the same thing with Maven plugin.
Developer instructions
To build the code, have a look at .travis.yml
.
To do a release you need to do ./gradlew release
and release the artifact from staging. More information here.