Reading pull request comments via REST API fails

jaakkosipari July 20, 2015

Hi!

Calling the /comments endpoint of the pull-request REST API returns an error response: "The path query parameter is required when retrieving comments."

I tried adding a "path" query parameter, but can't figure out it's content. My intention is to fetch all the comments for a PR, but I'm especially interested in the general comments which aren't specifically targeted at any file. The REST API description doesn't even mention the path query parameter.

The curl command line I've tried is:

curl --user xyz "https://pgit1.ray.fi/rest/api/1.0/projects/XYZ/repos/ABC/pull-requests/51/comments"

And with path (this gives a proper response, but without any comment payload):

curl --user xyz "https://pgit1.ray.fi/rest/api/1.0/projects/XYZ/repos/ABC/pull-requests/51/comments?path=/"

 

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
gustavo_refosco
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 20, 2015

Hi Jaakko,

I tested the REST API function locally and in fact you can't use the "comments" function without the "path" parameter, thus it looks it can't be used to retrieve general comments. I think it would be nice to have it as optional, so though I can't provide a resolution for you to get general comments using it I've created a suggestion to change this, which you can check at https://jira.atlassian.com/browse/STASH-7643. Please feel free to add any comments to it, as well as voting for it and adding yourself as a watcher to track its progress. You may refer to Atlassian's Policy for the implementation and changes on features.

As per the "path" parameter itself, you should be able to retrieve comments for specific files within your pull request by setting all the path to them, but without the first slash in front of the name, e.g. if I have a file named file2 which is under the dir1 directory located at the root of my repository the call to the function to retrieve comments within file2 would be as follows:

http://localhost:7990/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/comments?path=dir1/file2

For general comments, in the meantime, I'd recommend using the function /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/activities, which will return all the activity for a pull request, including general comments.

Regards,

Gustavo Refosco

jaakkosipari July 21, 2015

Thank you! While it kind of feels like a work-a-round, the activities API fulfilled our needs.

veerpal kaur June 28, 2019

What is the path?

is it "/"

or what should i specify there?

0 votes
jaakkosipari July 22, 2015

We have a code review coverage checker script which checks all commits and whether they're review'd or not (based on approvers in PR's and commit authors). The script also checks the PR comments for additional approvals added *after* the PR has been merged. Such additional approvals are required if it's later discovered the PR has been approved by a single person who also authored commits to the PR. The PR comment contains a marker text and the hash of a commit, which basically means 'I approve all commits in this PR up until this commit'. We do the coverage analysis for PCI (Payment Cards Industry) compliance.

0 votes
Adam
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 21, 2015

Jaakko, can I ask why you want this? What are you planning to do with the comments? I'm trying to gauge the usefulness of an endpoint like this in general and make sure we get the API right for it if we do implement it. Cheers!.

Brent Dowdy January 2, 2019

Yes, there is great need for this. I can think of plenty of uses for fetching comments from a Pull Request. 

For me, I need to fetch comments so I can present them to our clients during code reviews of their SDK submissions. They can't see our internal BitBucket server, we copy over the approvals and comments to a JIRA ticket they have access to. 

I am having to use the activities endpoint as well, which is chaos, and would love a dedicated endpoint to return the latest version all line item comments, file level comments and overview level comments. 

In addition, the information out there regarding the "comments" endpoint is incorrect, nor do the examples provided in the community work. I've passed in the exact path (as returned by the activities endpoint) to the comments endpoint and did not see any success. Not to mention, I have to hit the activities endpoint to get the variable values for the comments endpoint (?? blunder). 

Anyways, yeah there's a huge need for this. 

Andrew Dant June 3, 2019

I've made an application for my company tracking stats across Bitbucket (and Jira) and I would have loved to have this feature.

TAGS
AUG Leaders

Atlassian Community Events