Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create comment on pull request

GitHub's comment API seems to allow you to create comments on a pull request, but only if you supply a specific line number in the diff to comment on. Is there a way to create a comment on the pull request as a whole, the equivalent of typing at the bottom of the pull request screen in GitHub's web interface?

like image 999
cbmanica Avatar asked May 24 '13 21:05

cbmanica


People also ask

How do I add a comment to a pull request in bitbucket?

From the pull request you are reviewing, begin by selecting the Start review button in the top, right side of the page. You can also start a review from the comment form by selecting the Start review checkbox. Type your comment and then select Add comment. Add any other additional comments or tasks to your review.

How do I add a comment in Azure Devops pull request?

Choose Repos > Files, select the PR source branch, select a file, and then choose Edit. Make your changes in the editor, and then choose Commit to open the Commit dialog. In the Commit dialog, edit the commit message if necessary, and then choose Commit to commit and push the changes to your PR.


1 Answers

Yes, it is possible. The section of the API docs you are referencing relates to line comments (comments on specific lines of the commits in the pull req), and the docs say:

Pull Request Review Comments are comments on a portion of the unified diff. These are separate from Commit Comments (which are applied directly to a commit, outside of the Pull Request view), and Issue Comments (which do not reference a portion of the unified diff).

What you need are those Issue comments, which are explained at the top of this page:

The Pull Request API allows you to list, view, edit, create, and even merge pull requests. Comments on pull requests can be managed via the Issue Comments API.

So, in order to create a Pull Request comment, you actually need to create an Issue comment (since a pull request creates an issue to manage it). The page for Issue comments confirms this:

The Issue Comments API supports listing, viewing, editing, and creating comments on issues and pull requests.

So, the request you need to make is:

POST /repos/:owner/:repo/issues/:number/comments 

How do you know which issue comment URL to POST to? Well, if you look at the response for getting a single pull request, you will see that it contains an attribute called _links, and that this attribute has a nested comments attribute. This is the URL which you should use for reading and creating pull request comments, the same one as to be used in the POST request above.

like image 199
Ivan Zuzak Avatar answered Nov 04 '22 15:11

Ivan Zuzak