In my PR, a file MyFile.java is updated. Old line number is 123 and new line number after change is 234. I am trying to add a comment on new line 234 via REST API. I have tried several combinations of request body but its adding comment on old line number 123. Can someone please help with this behavior?
curl --location --request POST 'https://{{bitbucket-host}}/rest/api/latest/users/testuser/repos/my-service/pull-requests/2/comments' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ABCD-123' \
--data-raw '{
"text": "Field can be converted to a local variable - AT1",
"severity": "BLOCKER",
"anchor": {
"line": 234,
"lineType": "CONTEXT",
"fileType": "TO",
"path": "src/func-test/java/com/test/MyFile.java"
}
}'
Hi Avinash,
I believe that this is expected behaviour. If you attempt to post a comment on the new line within the PR view in the UI, it will automatically post it on the old line.
Are you able to try this for me in the UI?
I would also like to know the error message you receive for the API request.
Cheers!
- Ben (Bitbucket Cloud Support)
First of all thanks @Ben for quick response!
Yeah, you are right. When I am adding a comment on new line number its showing the comment on new line number itself. But it is actually attached to old line number.
This I have verified with API:
GET https://{{bitbucket-host}}/rest/api/latest/users/testuser/repos/my-service/pull-requests/2/comments?start=0&limit=300&path=src/java/com/avinash/TestFile.java)
In response, I see the old-line number itself.
Even though this is expected behaviour, I am not seeing the path forward to achieve my goal. Can you suggest something for below usecase?
Task: I parse the diff which I get from Stream Diff API, I want to add a comment on updated line number with this Add comment API and passing the line field as new line number (because, we can't determine the old-line from the diff, or I am not aware about it??). However, its adding that comment on a line which corresponds to old-line. Which is totally different than what I expected.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have confirmed with my colleagues that this is expected behaviour, this is because there are new lines being added to the destination branch that the source branch does not have - therefore the comment is added to the destination branch side to highlight this.
If you would like to see a change in this behaviour - I am able to raise a feature request on your behalf with our developers. Please let me know your use case.
Cheers!
- Ben (Bitbucket Cloud Support)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ben ,
As you said, "there are new lines being added to the destination branch that the source branch does not have." Based on this, I should be able to provide the line number (from the destination side) and the comment should be attached to the destination line number.
However, the current behavior is not the same. The line number we provide is treated as the source line number (NOT the destination), and the comment gets attached to the updated code based on the source line number.
For example, if int age = 27 is on line 123 in the source file and, after the code update, this code is now present on line 300, I would provide the line number as 300 via the API. I expect this comment to attach to the updated line of code. But in reality, the comment gets attached to the code that was originally on line number 300 in the source file.
I believe the API should behave this way. It would be very helpful if you could raise a feature request or bug report for this. Thank you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.