Skip to content

Instantly share code, notes, and snippets.

@tjl2
Created September 13, 2013 20:48
Show Gist options
  • Save tjl2/6555849 to your computer and use it in GitHub Desktop.
Save tjl2/6555849 to your computer and use it in GitHub Desktop.
Add a commit comment with the GitHub API
require 'rubygems'
require 'rest-client'
require 'json'
require 'pp'
@config = YAML.load(File.open('.github.yml'))
HOSTNAME = '' # add your GHE hostname here
USERNAME = '' # add your username here
PASSWORD = '' # add your password or OAuth token here
api_url = "http://#{USERNAME}:#{PASSWORD}@#{HOSTNAME}/api/v3/"
repo = '' # the name of the repo
sha = '' # the SHA of the commit
payload = {
'path' => 'something.rb', # the path to the file your comment applies to
'body' => 'This is your commment',
'position' => 1 # this is the line number of the of the diff output
}
json_response = JSON.parse(RestClient.post(@api_url +
"repos/#{USERNAME}/#{repo}/commits/#{sha}/comments",
payload.to_json, content_type: 'text/json'))
pp json_response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment