Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

404 error because trying to update a deleted comment #110

Open
oosterad opened this issue Sep 5, 2019 · 6 comments
Open

404 error because trying to update a deleted comment #110

oosterad opened this issue Sep 5, 2019 · 6 comments

Comments

@oosterad
Copy link

oosterad commented Sep 5, 2019

Expected Behavior

I expected the comments from the sonar PR analysis to successfully be sent to bitbucket.

Cause of the problem

The plugin deletes comments when the sonar problem on that line has disappeared. However, a comment is not really deleted, but bitbucket sets the flag "deleted" to true. when a new problem arises on the same line, the plugin does not detect this and tries to update this comment which is not allowed because it is deleted.

Possible solution

Extend the PullRequestComment class with an isDeleted property.
In the method fetchPullRequestCommentsPage set this property.
In the method processExistingComments filter not only on isInLine, but add filtering on !isDeleted.
This way a new comment will be created instead of updating a deleted one.

I have implement this, code can be found here and the release here.

Actual Behavior

First few runs it works as expected and I see my sonar comments in the PR, but then suddenly after a new commit I get the following error:
Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.6.1.1688:sonar (default-cli) on project my-project-name: PUT https://api.bitbucket.org/2.0/repositories/myname/my-repo-slug/pullrequests/174/comments/115431040 returned a response status of 404 Not Found

and

Caused by: com.sun.jersey.api.client.UniformInterfaceException: PUT https://api.bitbucket.org/2.0/repositories/crv4all/fertility-domain/pullrequests/174/comments/115431040 returned a response status of 404 Not Found at com.sun.jersey.api.client.WebResource.voidHandle (WebResource.java:707) at com.sun.jersey.api.client.WebResource.access$400 (WebResource.java:74) at com.sun.jersey.api.client.WebResource$Builder.put (WebResource.java:517) at ch.mibex.bitbucket.sonar.client.BitbucketClient.updateReviewComment (BitbucketClient.scala:263) at ch.mibex.bitbucket.sonar.review.ReviewCommentsHandler.ch$mibex$bitbucket$sonar$review$ReviewCommentsHandler$$updateComment (ReviewCommentsHandler.scala:148) at ch.mibex.bitbucket.sonar.review.ReviewCommentsHandler$$anonfun$updateComments$1$$anonfun$apply$1.apply (ReviewCommentsHandler.scala:43) at ch.mibex.bitbucket.sonar.review.ReviewCommentsHandler$$anonfun$updateComments$1$$anonfun$apply$1.apply (ReviewCommentsHandler.scala:37)

Plug-in version, SonarQube version, CI system, build type

Latest plug-in version, 1.3.0
Running from Jenkins.
SonarQube 7.2.1

Additional information

The sonar analysis runs fine according to the following logging:
[INFO] ANALYSIS SUCCESSFUL [INFO] Executing post-job Sonar Plug-in for Bitbucket Cloud [INFO] [sonar4bitbucket] Plug-in is active and will analyze pull request #174...

When I do a GET (using Postman) of this comment, everything works fine:
https://api.bitbucket.org/2.0/repositories/myname/my-repo-slug/pullrequests/174/comments/115431040

However when I do a PUT with this in the body:
{ "content": { "raw": "Test of oosterad" } }
I get exactly the same result. A 404 and the following json:
{ "type": "error", "error": { "message": "115431040" } }

Regards,
Ad

@oosterad oosterad changed the title 404 error because comment id cannot be found in bitbucket 404 error because trying to update a deleted comment Oct 25, 2019
@joshuabergeron
Copy link

I believe I have been running into this issue as well, thank you for your effort in implementing a solution!

@oosterad
Copy link
Author

You're welcome!

@thuypt
Copy link

thuypt commented Mar 4, 2020

Confirmed the fix works for me.
@oosterad Could you pls open a PR to this repository instead of fix in your fork repository?
So we unable to have your fix along with the plugin update.

@oosterad
Copy link
Author

oosterad commented Mar 4, 2020

@thuypt I would like to make a PR, but I cannot make a branch (or do not know how to do it). And since I got totally no response back then, I decided to create a fork instead.

@thuypt
Copy link

thuypt commented Mar 4, 2020

@oosterad I couldn't find the repo's contribution policy. But by taking a look at the recent PRs list, people created PRs from their fork repo(any branch) to master of this repo. I think you can do the same.

@nfalco79
Copy link

We have the same issue here

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants