Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Bitbucket Server Rest API posting file LINE comments as general file comments

S. Rose Lindauer
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 22, 2019

I'm trying to post a comment to a specific line in a file on a Pull request. I was thrilled to see that's supported in the documentation (http://example.com/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/comments), but I must be doing something wrong, because all my attempts to make this POST call result in a general file comment instead of a file line comment. As in, it doesn't show up on the diff.

I'm making the call in a python script.

Here's the URL:

https://{my server}/bitbucket/rest/api/1.0/projects/{project}/repos/{repo}/pull-requests/{pull request id}/comments

The data: 

disp_json = {                        

    "text": disp_message,                        

    "anchor": {                            

        "diffType": "EFFECTIVE",                            

        "line": finding.flag_line_number,                            

        "lineType": "ADDED",                           

        "fileType": "TO",                            

        "fromHash": fromHash,                            

        "path": finding.file_path,                            

        "srcPath": finding.file_path,                            

        "toHash": toHash                        

    }                   

}

And the call itself: 

response = requests.post(url, data=json.dumps(disp_json), auth=(self.username, self.password), verify=Falseheaders={'content-type''application/json'})

 

I got the fromHash and toHash by doing this GET call on the PR:

url_to_pr_file: https://{my server}/bitbucket/rest/api/1.0/projects/{project}/repos/{repo}/pull-requests/{pull request id}/diff/{finding.file_path}

call: hash_response = requests.get(url_to_pr_file, auth=(self.username, self.password), verify=False)

 

I used "ADDED" and "TO" because the lines I want the rest api call to comment on are comments that have been automatically added and committed in the code via other python scripts. 

 

As for the diffType, in all the hullabaloo of trying to figure this out, I remember seeing "EFFECTIVE" in a pull request GET call's response json data... at some point. I also tried "COMMIT" to no avail.

 

I've also seen this request done without the to/from hashes and diff type. Tried that, and that didn't work either. 

 

Can anyone with fresh eyes point me in the right direction?

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events