Skip to content

Commit

Permalink
Add support for file comments in PRs (#1717)
Browse files Browse the repository at this point in the history
* Add specs for file PR comments

* Add support for file comments in PRs
  • Loading branch information
camillof authored Oct 11, 2024
1 parent 6c62c46 commit c0ce2e5
Show file tree
Hide file tree
Showing 3 changed files with 386 additions and 10 deletions.
24 changes: 16 additions & 8 deletions lib/octokit/client/pull_requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,22 +197,30 @@ def pull_request_comment(repo, comment_id, options = {})
# @param body [String] Comment content
# @param commit_id [String] Sha of the commit to comment on.
# @param path [String] Relative path of the file to comment on.
# @param line [Integer] Line index in the diff to comment on.
# @param line [Integer] Optional line index in the diff to comment on.
# For a multi-line comment, the last line of the range
# and specify 'start_line' in the 'options'.
# If not specified, the comment will be on the whole file.
# @return [Sawyer::Resource] Hash representing the new comment
# @deprecated The position will be deprecated in the next major version. Please refer to the details below.
# @see https://developer.github.com/v3/pulls/comments/#create-a-comment
# @example
# @client.create_pull_request_comment("octokit/octokit.rb", 163, ":shipit:",
# "2d3201e4440903d8b04a5487842053ca4883e5f0", "lib/octokit/request.rb", 47)
def create_pull_request_comment(repo, pull_id, body, commit_id, path, line, options = {})
options.merge!({
body: body,
commit_id: commit_id,
path: path,
line: line
})
def create_pull_request_comment(repo, pull_id, body, commit_id, path, line = nil, options = {})
comment = {
body: body,
commit_id: commit_id,
path: path
}

if line.nil?
comment[:subject_type] = 'file'
else
comment[:line] = line
end

options.merge! comment
post "#{Repository.path repo}/pulls/#{pull_id}/comments", options
end
alias create_pull_comment create_pull_request_comment
Expand Down
Loading

0 comments on commit c0ce2e5

Please sign in to comment.