Sha256: b4c071f61f79a1e66e7f324aa791ec95550cfa392d80c08c49295c1ee8484c44

Contents?: true

Size: 1.4 KB

Versions: 16

Compression:

Stored size: 1.4 KB

Contents

module Github
  module Commit
    ENDPOINT = URI.join(Github::ROOT_ENDPOINT, 'repos/', "#{Github::OWNER}/", "#{Github::REPO}/", 'git/', 'commits').to_s

    AUTHOR_KEYS = %w(
      name
      email
      date
    )

    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

    # @param - message: The commit message
    # @param - tree: The SHA of the tree object this commit points to
    # @param - parents: Array of strings. 
    #   The SHAs of the commits that were the parents of this commit. If omitted or empty, the commit will be written as a root commit.
    #   For a single parent, an array of one SHA should be provided; for a merge commit, an array of more than one should be provided.
    # @return - commit sha
    def self.create(message, tree, parents, author={})
      input = {
        'message' => message,
        'tree' => tree,
        'parents' => parents
      }
      author.slice!(*AUTHOR_KEYS)
      input.merge!({'author' => author}) if author.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
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
aleph_analytics-0.4.9.pre.dev lib/github/commit.rb
aleph_analytics-0.4.8 lib/github/commit.rb
aleph_analytics-0.4.7 lib/github/commit.rb
aleph_analytics-0.4.4 lib/github/commit.rb
aleph_analytics-0.4.2 lib/github/commit.rb
aleph_analytics-0.4.1 lib/github/commit.rb
aleph_analytics-0.3.0 lib/github/commit.rb
aleph_analytics-0.2.0 lib/github/commit.rb
aleph_analytics-0.1.0 lib/github/commit.rb
aleph_analytics-0.0.6 lib/github/commit.rb
aleph_analytics-0.0.5 lib/github/commit.rb
aleph_analytics-0.0.4 lib/github/commit.rb
aleph_analytics-0.0.3 lib/github/commit.rb
aleph_analytics-0.0.2 lib/github/commit.rb
aleph_analytics-0.0.1.alpha lib/github/commit.rb
aleph_analytics-0.0.0.alpha lib/github/commit.rb