Class: Pronto::Github
Instance Method Summary collapse
- #commit_comments(sha) ⇒ Object
- #create_commit_comment(comment) ⇒ Object
- #create_commit_status(status) ⇒ Object
- #create_pull_comment(comment) ⇒ Object
- #create_pull_request_review(comments) ⇒ Object
-
#initialize(repo) ⇒ Github
constructor
A new instance of Github.
- #pull_comments(sha) ⇒ Object
Methods inherited from Client
Constructor Details
#initialize(repo) ⇒ Github
Returns a new instance of Github.
5 6 7 8 |
# File 'lib/pronto/github.rb', line 5 def initialize(repo) super(repo) @github_pull = Pronto::GithubPull.new(client, slug) end |
Instance Method Details
#commit_comments(sha) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/pronto/github.rb', line 23 def commit_comments(sha) @comment_cache[sha.to_s] ||= begin client.commit_comments(slug, sha).map do |comment| Comment.new(sha, comment.body, comment.path, comment.position) end end end |
#create_commit_comment(comment) ⇒ Object
31 32 33 34 35 |
# File 'lib/pronto/github.rb', line 31 def create_commit_comment(comment) @config.logger.log("Creating commit comment on #{comment.sha}") client.create_commit_comment(slug, comment.sha, comment.body, comment.path, nil, comment.position) end |
#create_commit_status(status) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/pronto/github.rb', line 61 def create_commit_status(status) sha = pull_sha || status.sha @config.logger.log("Creating comment status on #{sha}") client.create_status(slug, sha, status.state, context: status.context, description: status.description) end |
#create_pull_comment(comment) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/pronto/github.rb', line 37 def create_pull_comment(comment) if comment.path && comment.position @config.logger.log("Creating pull request comment on #{pull_id}") client.create_pull_comment(slug, pull_id, comment.body, pull_sha || comment.sha, comment.path, comment.position) else create_commit_comment(comment) end end |
#create_pull_request_review(comments) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/pronto/github.rb', line 48 def create_pull_request_review(comments) return if comments.empty? = { event: 'COMMENT', accept: 'application/vnd.github.v3.diff+json', # https://developer.github.com/v3/pulls/reviews/#create-a-pull-request-review comments: comments.map do |c| { path: c.path, position: c.position, body: c.body } end } client.create_pull_request_review(slug, pull_id, ) end |
#pull_comments(sha) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/pronto/github.rb', line 10 def pull_comments(sha) @comment_cache["#{pull_id}/#{sha}"] ||= begin client.pull_comments(slug, pull_id).map do |comment| Comment.new(sha, comment.body, comment.path, comment.position || comment.original_position) end end rescue Octokit::NotFound => e @config.logger.log("Error raised and rescued: #{e}") msg = "Pull request for sha #{sha} with id #{pull_id} was not found." raise Pronto::Error, msg end |