Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
654 views
in Technique[技术] by (71.8m points)

github - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...