Sha256: 860607256600be1f6fc388dacee3d0a891637ebaba9015f4adbe8660f1f3edd6

Contents?: true

Size: 1.25 KB

Versions: 16

Compression:

Stored size: 1.25 KB

Contents

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

    def self.get(sha, recursive=false)
      raise 'invalid sha #{sha} when retrieving github tree' unless Github.valid_sha?(sha)
      params = recursive ? { 'recursive' => 1 } : {}
      resp = Github.get("#{ENDPOINT}/#{sha}", params)
      raise "Github tree retrieve failed with http code: #{resp.code}" if resp.code != '200'
      ActiveSupport::JSON.decode(resp.body)
    end


    # @param - tree: array of hashes. Objects (of path, mode, type, and sha) specifying a tree structure
    # @param - base_tree: The SHA1 of the tree you want to update with new data. If you don’t set this, the commit will be created on top of everything;
    #   however, it will only contain your change, the rest of your files will show up as deleted.
    def self.create(tree, base_tree)
      return unless tree.instance_of?(Array)
      params = {
        'base_tree' => base_tree,
        'tree' => tree
      }

      resp = Github.post(ENDPOINT, params)
      raise "Github tree POST failed with http code: #{resp.code}\nBody is: #{resp.body}" 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/tree.rb
aleph_analytics-0.4.8 lib/github/tree.rb
aleph_analytics-0.4.7 lib/github/tree.rb
aleph_analytics-0.4.4 lib/github/tree.rb
aleph_analytics-0.4.2 lib/github/tree.rb
aleph_analytics-0.4.1 lib/github/tree.rb
aleph_analytics-0.3.0 lib/github/tree.rb
aleph_analytics-0.2.0 lib/github/tree.rb
aleph_analytics-0.1.0 lib/github/tree.rb
aleph_analytics-0.0.6 lib/github/tree.rb
aleph_analytics-0.0.5 lib/github/tree.rb
aleph_analytics-0.0.4 lib/github/tree.rb
aleph_analytics-0.0.3 lib/github/tree.rb
aleph_analytics-0.0.2 lib/github/tree.rb
aleph_analytics-0.0.1.alpha lib/github/tree.rb
aleph_analytics-0.0.0.alpha lib/github/tree.rb