Git Product home page Git Product logo

violation-comments-to-bitbucket-server-lib's Introduction

Violation Comments to Bitbucket Server Lib

Maven Central

This is a library that adds violation comments from static code analysis to Bitbucket Server.

It uses Violation Comments Lib and supports the same formats as Violations Lib.

Very easy to use with a nice builder pattern

  violationCommentsToBitbucketServerApi() //
    .withViolations(".*/findbugs/.*\\.xml$", FINDBUGS, rootFolder) //
    .withViolations(".*/checkstyle/.*\\.xml$", CHECKSTYLE, rootFolder) //
    .withUsername("username")
    .withPassword("password")
    .withProjectKey("projectKey")
    .withRepoSlug("repoSlug")
    .withPullRequestId("pullRequestId")
    .toPullRequest();

Usage

This software can be used:

Properties

It can be configured with some Java properties:

  • VIOLATIONS_KEYSTORE_PATH - A path to a keystore.
  • VIOLATIONS_KEYSTORE_PASS - Password for the keystore.
  • VIOLATIONS_PAT - Personal access token used to authenticate.
  • VIOLATIONS_USERNAME - Username to authenticate with.
  • VIOLATIONS_PASSWORD - Password to authenticate with.

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.

violation-comments-to-bitbucket-server-lib's People

Contributors

csknns avatar thomaslorentsen avatar tomasbjerre avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

violation-comments-to-bitbucket-server-lib's Issues

Connection refused exception though credentials

Hi, execution of the violation comments to bitbucket server plug-in in a Jenkins pipeline project produces the following output:

---
--- Jenkins Violation Comments to Bitbucket Server ---
---
bitbucketServerUrl: https://SERVER_URL/
projectKey: P2T
repoSlug: code
pullRequestId: 7
credentialsId: true
createSingleFileComments: true
createCommentWithAllSingleFileComments: false
commentOnlyChangedContent: false
commentOnlyChangedContentContext: 0
minSeverity: INFO
keepOldComments: false
cpplint with pattern cpplint-result\.xml
Pull request: 7
Workspace: /srv/www/jenkins/workspace/code_PR-7-7S7CYR323YORU65XFMRGB5AFWUTKJ5IHOVX2WIB2M4IM6EQQZRXA
Found 0 violations from ViolationConfig [pattern=cpplint-result\.xml, reporter=cpplint, parser=CPPLINT].
PR: P2T/code/7 on https://SERVER_URL/
java.lang.RuntimeException: Error calling:
https://SERVER_URL/rest/api/1.0/projects/P2T/repos/code/pull-requests/7/changes?limit=999999
GET
null
	at se.bjurr.violations.comments.bitbucketserver.lib.client.BitbucketServerInvoker.doInvokeUrl(BitbucketServerInvoker.java:88)
	at se.bjurr.violations.comments.bitbucketserver.lib.client.BitbucketServerInvoker.invokeUrl(BitbucketServerInvoker.java:51)
	at se.bjurr.violations.comments.bitbucketserver.lib.client.BitbucketServerClient.doInvokeUrl(BitbucketServerClient.java:97)
	at se.bjurr.violations.comments.bitbucketserver.lib.client.BitbucketServerClient.invokeAndParse(BitbucketServerClient.java:69)
	at se.bjurr.violations.comments.bitbucketserver.lib.client.BitbucketServerClient.pullRequestChanges(BitbucketServerClient.java:80)
	at se.bjurr.violations.comments.bitbucketserver.lib.BitbucketServerCommentsProvider.getFiles(BitbucketServerCommentsProvider.java:106)
	at se.bjurr.violations.comments.lib.CommentsCreator.<init>(CommentsCreator.java:42)
	at se.bjurr.violations.comments.lib.CommentsCreator.createComments(CommentsCreator.java:25)
	at se.bjurr.violations.comments.bitbucketserver.lib.ViolationCommentsToBitbucketServerApi.toPullRequest(ViolationCommentsToBitbucketServerApi.java:133)
	at org.jenkinsci.plugins.jvctb.perform.JvctbPerformer.doPerform(JvctbPerformer.java:137)
	at org.jenkinsci.plugins.jvctb.perform.JvctbPerformer$1.invoke(JvctbPerformer.java:220)
	at org.jenkinsci.plugins.jvctb.perform.JvctbPerformer$1.invoke(JvctbPerformer.java:208)
	at hudson.FilePath.act(FilePath.java:1009)
	at hudson.FilePath.act(FilePath.java:987)
	at org.jenkinsci.plugins.jvctb.perform.JvctbPerformer.jvctsPerform(JvctbPerformer.java:207)
	at org.jenkinsci.plugins.jvctb.ViolationsToBitbucketServerRecorder.perform(ViolationsToBitbucketServerRecorder.java:66)
	at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:80)
	at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:67)
	at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1$1.call(SynchronousNonBlockingStepExecution.java:49)
	at hudson.security.ACL.impersonate(ACL.java:290)
	at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1.run(SynchronousNonBlockingStepExecution.java:46)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.ConnectException: Connection refused (Connection refused)
	at java.net.PlainSocketImpl.socketConnect(Native Method)
	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
	at java.net.Socket.connect(Socket.java:589)
	at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:673)
	at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
	at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
	at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
	at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264)
	at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)
	at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
	at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1156)
	at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1050)
	at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
	at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:162)
	at se.bjurr.violations.comments.bitbucketserver.lib.client.BitbucketServerInvoker.doInvokeUrl(BitbucketServerInvoker.java:74)
	... 25 more

I use the same credentials and URL earlier in that Jenkinsfile for checking out the git repository, so I would guess that it should work. I used the Pipeline Syntax generator for the Jenkinsfile:

ViolationsToBitbucketServer(
[
	bitbucketServerUrl: 'https://SERVER_URL/',
	createSingleFileComments: true,
	credentialsId: 'CREDENTIALS_ID',
	projectKey: 'P2T',
	pullRequestId: env.CHANGE_ID,
	repoSlug: 'code',
	violationConfigs: [
	[
		parser: 'CPPLINT', pattern: 'cpplint-result\\.xml', reporter: 'cpplint'
	]]
])

Can you help?

NullPointerException when running the Jenkins plugin

Hi,

I'm getting a NullPointerException when running the Jenkins plugin on an Pull Request that contains a deleted file. I'm using BitBucket Server v4.4.1

java.lang.NullPointerException
	at se.bjurr.violations.comments.bitbucketserver.lib.BitbucketServerCommentsProvider.shouldComment(BitbucketServerCommentsProvider.java:127)
	at se.bjurr.violations.comments.bitbucketserver.lib.BitbucketServerCommentsProvider.shouldComment(BitbucketServerCommentsProvider.java:121)
	at se.bjurr.violations.comments.lib.CommentsCreator.filterChanged(CommentsCreator.java:114)
	at se.bjurr.violations.comments.lib.CommentsCreator.<init>(CommentsCreator.java:41)
	at se.bjurr.violations.comments.lib.CommentsCreator.createComments(CommentsCreator.java:25)
	at se.bjurr.violations.comments.bitbucketserver.lib.ViolationCommentsToBitbucketServerApi.toPullRequest(ViolationCommentsToBitbucketServerApi.java:113)
	at org.jenkinsci.plugins.jvctb.perform.JvctbPerformer.doPerform(JvctbPerformer.java:95)
	at org.jenkinsci.plugins.jvctb.perform.JvctbPerformer$1.invoke(JvctbPerformer.java:162)
	at org.jenkinsci.plugins.jvctb.perform.JvctbPerformer$1.invoke(JvctbPerformer.java:149)
	at hudson.FilePath.act(FilePath.java:989)
	at hudson.FilePath.act(FilePath.java:967)
	at org.jenkinsci.plugins.jvctb.perform.JvctbPerformer.jvctsPerform(JvctbPerformer.java:149)
	at org.jenkinsci.plugins.jvctb.ViolationsToBitbucketServerRecorder.perform(ViolationsToBitbucketServerRecorder.java:61)
	at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:74)
	at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:761)
	at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:721)
	at hudson.model.Build$BuildExecution.post2(Build.java:183)
	at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:670)
	at hudson.model.Run.execute(Run.java:1743)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
	at hudson.model.ResourceController.execute(ResourceController.java:89)
	at hudson.model.Executor.run(Executor.java:240)

Escaping of violation.message

I'm not sure that this is logged in the correct place: but

According to my reading of https://github.com/tomasbjerre/violation-comments-lib/blob/master/src/main/java/se/bjurr/violations/comments/lib/model/ViolationData.java

via the README at https://github.com/tomasbjerre/violation-comments-lib the violation message is always escaped as HTML. Is it possible to override part of this to support bitbucket-server contents which write markdown in their comments:

Details

I have commentTemplate defined as follows (the default, but made explicit)

 commentTemplate: '''**Reporter**: {{violation.reporter}}{{#violation.rule}}

**Rule**: {{violation.rule}}{{/violation.rule}}
**Severity**: {{violation.severity}}
**File**: {{violation.file}} L{{violation.startLine}}{{#violation.source}}

**Source**: {{violation.source}}{{/violation.source}}

{{violation.message}}''',

However the HTML escaping shows poorly in bitbucket comments - in this case ' single quotes are being escaped into numeric escapes which are (a) ugly and (b) linked to unrelated pull-request of the same id as the escape :-/

see below

violation-escape

Have I misunderstood? can the unescaped code be inserted somehow?

If you need to "escape" for markdown you could consider simply wrapping it in ``` ``` and leaving the escaping to the markdown processor.

VIOLATIONS_KEYSTORE_PATH (No such file or directory)

java.lang.RuntimeException: Error calling:
http://.../pull-requests/17/changes?limit=999999
GET
null
	at shadow.se.bjurr.violations.comments.bitbucketserver.lib.client.BitbucketServerInvoker.doInvokeUrl(BitbucketServerInvoker.java:162)
	at shadow.se.bjurr.violations.comments.bitbucketserver.lib.client.BitbucketServerInvoker.invokeUrl(BitbucketServerInvoker.java:78)
	at shadow.se.bjurr.violations.comments.bitbucketserver.lib.client.BitbucketServerClient.doInvokeUrl(BitbucketServerClient.java:142)
	at shadow.se.bjurr.violations.comments.bitbucketserver.lib.client.BitbucketServerClient.pullRequestChanges(BitbucketServerClient.java:109)
	at shadow.se.bjurr.violations.comments.bitbucketserver.lib.BitbucketServerCommentsProvider.getFiles(BitbucketServerCommentsProvider.java:150)
	at shadow.se.bjurr.violations.comments.lib.CommentsCreator.<init>(CommentsCreator.java:51)
	at shadow.se.bjurr.violations.comments.lib.CommentsCreator.createComments(CommentsCreator.java:38)
	at shadow.se.bjurr.violations.comments.bitbucketserver.lib.ViolationCommentsToBitbucketServerApi.toPullRequest(ViolationCommentsToBitbucketServerApi.java:226)
	at se.bjurr.violations.main.Runner.main(Runner.java:297)
	at se.bjurr.violations.main.Main.main(Main.java:6)
Caused by: java.io.FileNotFoundException: VIOLATIONS_KEYSTORE_PATH (No such file or directory)
	at java.io.FileInputStream.open0(Native Method)
	at java.io.FileInputStream.open(FileInputStream.java:195)
	at java.io.FileInputStream.<init>(FileInputStream.java:138)
	at java.io.FileInputStream.<init>(FileInputStream.java:93)
	at shadow.se.bjurr.violations.comments.bitbucketserver.lib.client.CertificateConfig.addTo(CertificateConfig.java:26)
	at shadow.se.bjurr.violations.comments.bitbucketserver.lib.client.BitbucketServerInvoker.doInvokeUrl(BitbucketServerInvoker.java:125)
	... 9 more

Paths with spaces fail

Issue

I'm trying to leverage the Violation Comments to Bitbucket Server Jenkins plugin. I got a minimal setup working for one project, but on another I'm seeing this error (names changed to protect the innocent):

java.io.IOException: Server returned HTTP response code: 505 for URL: https://my-bitbucket.com/rest/api/1.0/projects/PR/repos/my-web-service/pull-requests/1/comments?path=MyWebService/Service References/SomeService/Reference.cs&limit=999999
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
	at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
	at se.bjurr.violations.comments.bitbucketserver.lib.client.BitbucketServerInvoker.invokeUrl(BitbucketServerInvoker.java:47)
Caused: java.lang.RuntimeException: Error calling:
https://my-bitbucket.com/rest/api/1.0/projects/PR/repos/my-web-service/pull-requests/1/comments?path=MyWebService/Service References/SomeService/Reference.cs&limit=999999
GET
null
	at se.bjurr.violations.comments.bitbucketserver.lib.client.BitbucketServerInvoker.invokeUrl(BitbucketServerInvoker.java:56)
	at se.bjurr.violations.comments.bitbucketserver.lib.client.BitbucketServerClient.invokeAndParse(BitbucketServerClient.java:51)
	at se.bjurr.violations.comments.bitbucketserver.lib.client.BitbucketServerClient.pullRequestComments(BitbucketServerClient.java:81)
	at se.bjurr.violations.comments.bitbucketserver.lib.BitbucketServerCommentsProvider.getComments(BitbucketServerCommentsProvider.java:80)
	at se.bjurr.violations.comments.lib.CommentsCreator.createComments(CommentsCreator.java:47)
	at se.bjurr.violations.comments.lib.CommentsCreator.createComments(CommentsCreator.java:26)
	at se.bjurr.violations.comments.bitbucketserver.lib.ViolationCommentsToBitbucketServerApi.toPullRequest(ViolationCommentsToBitbucketServerApi.java:113)

Conjecture

Based on some StackOverflow stuff like this, I believe the issue is that spaces in the path are not URL encoded. If I try the URL directly in Chrome, the space is automatically encoded and I get a 200 response.

It seems it'll be impossible for me to work around the issue since Service References is a standard .NET folder for, well, referencing services. I tried filtering it out, but to no avail.

doInvokeUrl fails when urls contains spaces or other characters what should be escaped

If the URL contains spaces(or other characters what should be escaped), for example in the file path the new URI(url) fails:
(the single-argument constructor of URI does NOT escape illegal characters)

https://github.com/tomasbjerre/violation-comments-to-bitbucket-server-lib/issues/15
GET
null
	at se.bjurr.violations.comments.bitbucketserver.lib.client.BitbucketServerInvoker.doInvokeUrl(BitbucketServerInvoker.java:141)
	at se.bjurr.violations.comments.bitbucketserver.lib.client.BitbucketServerInvoker.invokeUrl(BitbucketServerInvoker.java:62)
	at se.bjurr.violations.comments.bitbucketserver.lib.client.BitbucketServerClient.doInvokeUrl(BitbucketServerClient.java:143)
	at se.bjurr.violations.comments.bitbucketserver.lib.client.BitbucketServerClient.pullRequestDiff(BitbucketServerClient.java:228)
	at se.bjurr.violations.comments.bitbucketserver.lib.BitbucketServerCommentsProvider$1.load(BitbucketServerCommentsProvider.java:47)
	at se.bjurr.violations.comments.bitbucketserver.lib.BitbucketServerCommentsProvider$1.load(BitbucketServerCommentsProvider.java:44)
	at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3568)
	at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2350)
	at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2313)
	at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2228)
	... 20 more
Caused by: java.net.URISyntaxException: Illegal character in path at index 109: http://bitbucket.omnia.int:7990/rest/api/1.0/projects/OMNIA/repos/ios-prototype/pull-requests/7920/diff/MB/MB Plugins/MBPluginRegistration.swift
	at java.net.URI$Parser.fail(URI.java:2848)
	at java.net.URI$Parser.checkChars(URI.java:3021)
	at java.net.URI$Parser.parseHierarchical(URI.java:3105)
	at java.net.URI$Parser.parse(URI.java:3053)
	at java.net.URI.<init>(URI.java:588)
	at se.bjurr.violations.comments.bitbucketserver.lib.client.BitbucketServerInvoker.doInvokeUrl(BitbucketServerInvoker.java:91)
	... 29 more

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.