Module: Github::Commit
- Defined in:
- lib/github/commit.rb
Constant Summary collapse
- ENDPOINT =
URI.join(Github::ROOT_ENDPOINT, 'repos/', "#{Github::OWNER}/", "#{Github::REPO}/", 'git/', 'commits').to_s
- AUTHOR_KEYS =
%w( name email date )
Class Method Summary collapse
Class Method Details
.create(message, tree, parents, author = {}) ⇒ Object
Returns - commit sha.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/github/commit.rb', line 24 def self.create(, tree, parents, ={}) input = { 'message' => , 'tree' => tree, 'parents' => parents } .slice!(*AUTHOR_KEYS) input.merge!({'author' => }) if .present? resp = Github.post(ENDPOINT, input) raise "Github commit POST failed with http code: #{resp.code}" if resp.code != '201' ActiveSupport::JSON.decode(resp.body)['sha'] end |
.get(sha) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/github/commit.rb', line 11 def self.get(sha) raise 'invalid sha #{sha} when retrieving github commit' unless Github.valid_sha?(sha) resp = Github.get("#{ENDPOINT}/#{sha}") raise "Github commit retrieve failed with http code: #{resp.code}" if resp.code != '200' ActiveSupport::JSON.decode(resp.body) end |