knux
knux

Reputation: 11

Comment file line in pull request with Github API

I am writing an application and I need to comment a file from pull request using GitHUb API. There is a github repository and a pull request to it. In this pull request one file is modified. I'd like to comment a specific line in this file using GitHub API. The problem is, that while we are using github API to create comment, we are passing the number of line in the diff file, not in the actual one. So, I am asking if there any way to pass an actual file line number to create a comment for it. Here is a link to GitHub API request I'am trying to use: Create a comment

Upvotes: 0

Views: 1446

Answers (1)

Ivan Zuzak
Ivan Zuzak

Reputation: 18772

So, I am asking if there any way to pass an actual file line number to create a comment for it.

That's not possible currently.

Pull request review comments are indeed comments created on lines of the diff, not lines of files. You can't comment on any line of any file in the pull request -- it needs to be a line in the diff. This behavior of the API matches the behavior on github.com -- give it a try and you won't be able to create a comment on any line in a file.

Also, if a line is changed in a file -- that line is shown two times in the diff: first the before (-), and then the after (+). So, it's not clear what you mean when you want to comment on a specific line in a file -- do you want to comment on the "old" line or the "new" line? Finally, how do you even know that a particular line of a file was changed in a pull request without viewing the diff?

My suggestion would be that you fetch the diff for the pull request, display that to the user and ask them to comment on a line of the diff. (This is basically what happens in the pull request UI on github.com). Is there a particular reason why that approach wouldn't work for you?

Upvotes: 1

Related Questions