Class: Github::Repos::Comments

Inherits:
API
  • Object
show all
Defined in:
lib/github_api/repos/comments.rb

Constant Summary collapse

REQUIRED_COMMENT_OPTIONS =
%w[ body ].freeze
VALID_COMMENT_OPTIONS =
%w[
  body
  line
  path
  position
].freeze

Constants included from Github::Request

Github::Request::METHODS, Github::Request::METHODS_WITH_BODIES

Constants included from Connection

Connection::ALLOWED_OPTIONS

Constants included from Constants

Constants::ACCEPT, Constants::ACCEPTED_OAUTH_SCOPES, Constants::ACCEPT_CHARSET, Constants::CACHE_CONTROL, Constants::CONTENT_LENGTH, Constants::CONTENT_TYPE, Constants::DATE, Constants::ETAG, Constants::HEADER_LAST, Constants::HEADER_LINK, Constants::HEADER_NEXT, Constants::LOCATION, Constants::META_FIRST, Constants::META_LAST, Constants::META_NEXT, Constants::META_PREV, Constants::META_REL, Constants::OAUTH_SCOPES, Constants::PARAM_PAGE, Constants::PARAM_PER_PAGE, Constants::PARAM_START_PAGE, Constants::RATELIMIT_LIMIT, Constants::RATELIMIT_REMAINING, Constants::SERVER, Constants::USER_AGENT

Constants included from MimeType

MimeType::MEDIA_LOOKUP

Instance Attribute Summary

Attributes inherited from API

#current_options

Attributes included from Authorization

#scopes

Instance Method Summary collapse

Methods inherited from API

#api_methods_in, #append_arguments, #arguments, inherited, #initialize, #method_missing, #process_basic_auth, #set, #setup, #with, #yield_or_eval

Methods included from Github::RateLimit

#ratelimit, #ratelimit_remaining

Methods included from Github::Request

#delete_request, #get_request, #patch_request, #post_request, #put_request, #request

Methods included from Connection

#caching?, #clear_cache, #connection, #default_middleware, #default_options, #stack

Methods included from MimeType

#lookup_media, #parse

Methods included from Authorization

#auth_code, #authenticated?, #authentication, #authorize_url, #basic_authed?, #client, #get_token

Constructor Details

This class inherits a constructor from Github::API

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Github::API

Instance Method Details

#create(*args) ⇒ Object

Creates a commit comment

Inputs

  • :body - Required string.

  • :comment_id - Required string - Sha of the commit to comment on.

  • :line - Required number - Line number in the file to comment on.

  • :path - Required string - Relative path of the file to comment on.

  • :position - Required number - Line index in the diff to comment on.

Examples

github = Github.new
github.repos.comments.create 'user-name', 'repo-name', 'sha-key', 
  "body" => "Nice change",
  "commit_id" => "6dcb09b5b57875f334f61aebed695e2e4193db5e",
  "line" => 1,
  "path" =>  "file1.txt",
  "position" =>  4


74
75
76
77
78
79
80
81
82
# File 'lib/github_api/repos/comments.rb', line 74

def create(*args)
  arguments(args, :required => [:user, :repo, :sha]) do
    sift VALID_COMMENT_OPTIONS
    assert_required REQUIRED_COMMENT_OPTIONS
  end
  params = arguments.params

  post_request("/repos/#{user}/#{repo}/commits/#{sha}/comments", params)
end

#delete(*args) ⇒ Object

Deletes a commit comment

Examples

github = Github.new
github.repos.comments.delete 'user-name', 'repo-name', 'comment-id'


109
110
111
112
113
114
# File 'lib/github_api/repos/comments.rb', line 109

def delete(*args)
  arguments(args, :required => [:user, :repo, :comment_id])
  params = arguments.params

  delete_request("/repos/#{user}/#{repo}/comments/#{comment_id}", params)
end

#get(*args) ⇒ Object Also known as: find

Gets a single commit comment

Examples

github = Github.new
github.repos.comments.get 'user-name', 'repo-name', 'comment-id'


48
49
50
51
52
53
# File 'lib/github_api/repos/comments.rb', line 48

def get(*args)
  arguments(args, :required => [:user, :repo, :comment_id])
  params = arguments.params

  get_request("/repos/#{user}/#{repo}/comments/#{comment_id}", params)
end

#list(*args) ⇒ Object Also known as: all

List commit comments for a repository

Examples

github = Github.new
github.repos.comments.list 'user-name', 'repo-name'
github.repos.comments.list 'user-name', 'repo-name' { |com| ... }

List comments for a single commit

Examples

github.repos.comments.list 'user-name', 'repo-name',
 :sha => '6dcb09b5b57875f334f61aebed695e2e4193db5e'


28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/github_api/repos/comments.rb', line 28

def list(*args)
  arguments(args, :required => [:user, :repo])
  params = arguments.params

  response = if (sha = params.delete('sha'))
    get_request("/repos/#{user}/#{repo}/commits/#{sha}/comments", params)
  else
    get_request("/repos/#{user}/#{repo}/comments", params)
  end
  return response unless block_given?
  response.each { |el| yield el }
end

#update(*args) ⇒ Object

Update a commit comment

Inputs

  • :body - Required string.

Examples

github = Github.new
github.repos.comments.update 'user-name', 'repo-name',
  'comment-id', "body" => "Nice change"


94
95
96
97
98
99
100
101
# File 'lib/github_api/repos/comments.rb', line 94

def update(*args)
  arguments(args, :required => [:user, :repo, :comment_id]) do
    assert_required REQUIRED_COMMENT_OPTIONS
  end
  params = arguments.params

  patch_request("/repos/#{user}/#{repo}/comments/#{comment_id}", params)
end