Skip to content

Instantly share code, notes, and snippets.

@tjl2
Created July 1, 2014 12:55
Show Gist options
  • Save tjl2/7bd7e586edcb0522b648 to your computer and use it in GitHub Desktop.
Save tjl2/7bd7e586edcb0522b648 to your computer and use it in GitHub Desktop.
# Run this from the command line like so:
# ruby pr_comments.rb [user]/[repo] [pr-id]
require 'rest-client'
require 'json'
require 'pp'
# I usually configure a setup file to set the USERNAME, PASSWORD & HOSTNAME constants for use in the @api_url string
# You can just hard-code them in here, for testing purposes.
@api_url = "http://#{USERNAME}:#{PASSWORD}@#{HOSTNAME}/api/v3/"
@user_repo = ARGV[0]
@pr = ARGV[1]
pr_request = @api_url + "repos/#{@user_repo}/pulls/#{@pr}"
pr_json_response = JSON.parse(RestClient.get(pr_request))
# Uncomment this to see the full JSON response in your browser
#pp pr_json_response
comments = pr_json_response["comments"]
review_comments = pr_json_response["review_comments"]
puts "#" * @user_repo.length + "#" * 5
puts "#{@user_repo} has:\n #{comments} discussion comments\n #{review_comments} review comments"
# Grab the standard discussion comments https://developer.github.com/v3/issues/comments/
comments = JSON.parse(RestClient.get(@api_url + "repos/#{@user_repo}/issues/#{@pr}/comments"))
puts "### Discussion comments ###"
comments.each do |comment|
puts "#{comment["user"]["login"]} said:"
puts ">>"
puts comment["body"]
puts "<<"
end
# Grab the 'review comments (inline notes)' https://developer.github.com/v3/pulls/comments/
r_comments = JSON.parse(RestClient.get(@api_url + "repos/#{@user_repo}/pulls/#{@pr}/comments"))
puts "### Review comments ###"
r_comments.each do |comment|
puts "#{comment["user"]["login"]} said about line #{comment["position"]} of #{comment["path"]}:"
puts ">>"
puts comment["body"]
puts "<<"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment