1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
# frozen_string_literal: true
module Octokit
class Client
# Methods for the Commit Comments API
#
# @see https://developer.github.com/v3/repos/comments/
module CommitComments
# List all commit comments
#
# @param repo [Integer, String, Hash, Repository] A GitHub repository
# @return [Array] List of commit comments
# @see https://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository
def list_commit_comments(repo, options = {})
paginate "#{Repository.path repo}/comments", options
end
# List comments for a single commit
#
# @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param sha [String] The SHA of the commit whose comments will be fetched
# @return [Array] List of commit comments
# @see https://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit
def commit_comments(repo, sha, options = {})
paginate "#{Repository.path repo}/commits/#{sha}/comments", options
end
# Get a single commit comment
#
# @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param id [String] The ID of the comment to fetch
# @return [Sawyer::Resource] Commit comment
# @see https://developer.github.com/v3/repos/comments/#get-a-single-commit-comment
def commit_comment(repo, id, options = {})
get "#{Repository.path repo}/comments/#{id}", options
end
# Create a commit comment
#
# @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param sha [String] Sha of the commit to comment on
# @param body [String] Message
# @param path [String] Relative path of file to comment on
# @param line [Integer] Line number in the file to comment on
# @param position [Integer] Line index in the diff to comment on
# @return [Sawyer::Resource] Commit comment
# @see https://developer.github.com/v3/repos/comments/#create-a-commit-comment
# @example Create a commit comment
# comment = Octokit.create_commit_comment("octocat/Hello-World", "827efc6d56897b048c772eb4087f854f46256132", "My comment message", "README.md", 10, 1)
# comment.commit_id # => "827efc6d56897b048c772eb4087f854f46256132"
# comment.id # => 54321
# comment.body # => "My comment message"
# comment.path # => "README.md"
# comment.line # => 10
# comment.position # => 1
def create_commit_comment(repo, sha, body, path = nil, line = nil, position = nil, options = {})
params = {
body: body,
path: path,
line: line,
position: position
}
post "#{Repository.path repo}/commits/#{sha}/comments", options.merge(params)
end
# Update a commit comment
#
# @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param id [String] The ID of the comment to update
# @param body [String] Message
# @return [Sawyer::Resource] Updated commit comment
# @see https://developer.github.com/v3/repos/comments/#update-a-commit-comment
# @example Update a commit comment
# comment = Octokit.update_commit_comment("octocat/Hello-World", "860296", "Updated commit comment")
# comment.id # => 860296
# comment.body # => "Updated commit comment"
def update_commit_comment(repo, id, body, options = {})
params = {
body: body
}
patch "#{Repository.path repo}/comments/#{id}", options.merge(params)
end
# Delete a commit comment
#
# @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param id [String] The ID of the comment to delete
# @return [Boolean] Success
# @see https://developer.github.com/v3/repos/comments/#delete-a-commit-comment
def delete_commit_comment(repo, id, options = {})
boolean_from_response :delete, "#{Repository.path repo}/comments/#{id}", options
end
end
end
end
|