Skip to content

Commit c0ce2e5

Browse files
authored
Add support for file comments in PRs (#1717)
* Add specs for file PR comments * Add support for file comments in PRs
1 parent 6c62c46 commit c0ce2e5

File tree

3 files changed

+386
-10
lines changed

3 files changed

+386
-10
lines changed

lib/octokit/client/pull_requests.rb

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,22 +197,30 @@ def pull_request_comment(repo, comment_id, options = {})
197197
# @param body [String] Comment content
198198
# @param commit_id [String] Sha of the commit to comment on.
199199
# @param path [String] Relative path of the file to comment on.
200-
# @param line [Integer] Line index in the diff to comment on.
200+
# @param line [Integer] Optional line index in the diff to comment on.
201201
# For a multi-line comment, the last line of the range
202202
# and specify 'start_line' in the 'options'.
203+
# If not specified, the comment will be on the whole file.
203204
# @return [Sawyer::Resource] Hash representing the new comment
204205
# @deprecated The position will be deprecated in the next major version. Please refer to the details below.
205206
# @see https://developer.github.com/v3/pulls/comments/#create-a-comment
206207
# @example
207208
# @client.create_pull_request_comment("octokit/octokit.rb", 163, ":shipit:",
208209
# "2d3201e4440903d8b04a5487842053ca4883e5f0", "lib/octokit/request.rb", 47)
209-
def create_pull_request_comment(repo, pull_id, body, commit_id, path, line, options = {})
210-
options.merge!({
211-
body: body,
212-
commit_id: commit_id,
213-
path: path,
214-
line: line
215-
})
210+
def create_pull_request_comment(repo, pull_id, body, commit_id, path, line = nil, options = {})
211+
comment = {
212+
body: body,
213+
commit_id: commit_id,
214+
path: path
215+
}
216+
217+
if line.nil?
218+
comment[:subject_type] = 'file'
219+
else
220+
comment[:line] = line
221+
end
222+
223+
options.merge! comment
216224
post "#{Repository.path repo}/pulls/#{pull_id}/comments", options
217225
end
218226
alias create_pull_comment create_pull_request_comment

0 commit comments

Comments
 (0)