AmadeusITGroup / sonar-stash

Stash (BitBucket) plugin, a pull-request decorator which allows to integrate SonarQube violations directly into your pull-request
MIT License
165 stars 82 forks source link

BitBucket cloud support #66

Open 4n4n4s opened 7 years ago

4n4n4s commented 7 years ago

Hi, I want to test out your sonar analysis on my test project that I created on Bitbucket. Therefore I already set up a Jenkins build and added SonarQube to it.

My Test Repository is placed here: https://bitbucket.org/4n4n4s/hooktest

-Dsonar.host.url=http://mysonardomain.com:9000 -Dsonar.projectKey=hooktest -Dsonar.projectName=hooktest project -Dsonar.projectVersion=1.0 -Dsonar.projectBaseDir=/var/jenkins_home/workspace/hooktest -Dsonar.sources=.

-Dsonar.analysis.mode=preview -Dsonar.stash.url=https://bitbucket.org/4n4n4s/ -Dsonar.stash.notification=true -Dsonar.stash.login=4n4n4s -Dsonar.stash.password=MY_BITBUCKET_PASSWORD -Dsonar.stash.project=hooktest -Dsonar.stash.repository=hooktest -Dsonar.stash.pullrequest.id=1

When I start the jenkins build I get the following exception. Maybe I just misconfigured the sonar.stash properties but I found no documentation for bitbucket here.

INFO: Executing post-job org.sonar.plugins.stash.StashIssueReportingPostJob ERROR: Unable to get SonarQube reviewer from Stash: java.util.concurrent.ExecutionException: java.net.ConnectException: Received fatal alert: handshake_failure ERROR: Process stopped: no SonarQube reviewer identified to publish to Stash the SQ analysis

As a result I would also like to add some documentation how sonar-stash can be used with jenkins + bitbucket. Thanks for your help.

t-8ch commented 7 years ago

Hi @4n4n4s , This is a problem between our HTTP library and the bitbucket server. I'll sort it out. FYI: I don't know if the APIs between Bitbucket Server and Bitbucket Public are compatible

t-8ch commented 7 years ago

@4n4n4s Could you try again with the code from #67 ? It uses a different http client.

4n4n4s commented 7 years ago

@t-8ch I forked you code and also read the bitbucket api documentation. There are several things that need to be changed because server api and public api don't share much.

FYI: There is also a public API 2.0 but this does not support adding comments and it seems that they won't support it accoring to this link. answers.atlassian.com

It would be great to contribute some code but there need to be a lot of changes to support both server and public but I think it would be great to get it working on both.

About #67: I fixed the problem locally by updating the pom.xml at least I can get a request then but as mentioned above the api enpoints and responses are differnt.

<dependency>
  <groupId>com.ning</groupId>
  <artifactId>async-http-client</artifactId>
  <version>1.9.39</version>
</dependency>
t-8ch commented 7 years ago

So, @4n4n4s

I had a first shot at it (absolutely incomplete, more a showcase how I'd like it to be structured) in the bitbucket_cloud branch. It is not very nice to code against the BitBucket cloud API.

If you really want it you are absolutely welcome to provide a pull request (and have a look at my first try). I'll be happy to review your code.

4n4n4s commented 7 years ago

@t-8ch thanks for also doing research and setting up a base config I will start implementing tomorrow but can you please share the codeformat.xml because they are differnet from standard eclipse or springboot. Thx.

t-8ch commented 7 years ago

@4n4n4s The current code style is not a special one. For future development we will use the google java code style. You should find the xml file for it at https://google.github.io/styleguide/eclipse-java-google-style.xml

fantomas commented 7 years ago

I don`t know java (only php) in order to help here. But as a customer of the Cloud I would like to see if a PR follow PSR-2 etc. Have you talked with Atlassian for help in integrating SonarQube? They have Pipelines in beta tests. But I thing the real gold is static analysis on PRs.

sudr commented 7 years ago

I'm interested in picking this up since we've started to use SonarQube and we use BitBucket cloud. This integration would be greatly beneficial to us.

Is the bitbucket_cloud branch in a state where I can rebase from the master branch and pickup development of this integration. Any other pointers that might help me get started.

t-8ch commented 7 years ago

@sudr The bitbucket cloud branch has not been touched for a while. I doubt it will be worthwile to replace it. It would probably best to start over. Just rename StashClient to StashServerClient and make StashClient an interface with the used methods. Then implement those for BitbucketCloudClient.

As for more information have a look at https://confluence.atlassian.com/bitbucket/use-the-bitbucket-cloud-rest-apis-222724129.html , there are links to both version 1 and 2 of the apis to the right.

sudr commented 7 years ago

Thanks. I'll pick this up and post updates here.

sudr commented 7 years ago

There is a different plugin that allows you to run sonar analysis on a BitBucket Cloud project:

https://github.com/mibexsoftware/sonar-bitbucket-plugin

Given this, I'm no longer pursing this plugin for our use case.