Class: Github::GitData::Trees

Inherits:
API
  • Object
show all
Defined in:
lib/github_api/git_data/trees.rb

Constant Summary collapse

VALID_TREE_PARAM_NAMES =
%w[
  base_tree
  tree
  path
  mode
  type
  sha
  content
  url
].freeze
VALID_TREE_PARAM_VALUES =
{
  'mode' => %w[ 100644 100755 040000 160000 120000 ],
  'type' => %w[ blob tree commit ]
}

Constants included from Request

Request::METHODS, Request::METHODS_WITH_BODIES

Constants included from Connection

Connection::ALLOWED_OPTIONS

Constants included from Constants

Constants::ACCEPT, Constants::ACCEPTED_OAUTH_SCOPES, Constants::ACCEPT_CHARSET, Constants::CACHE_CONTROL, Constants::CONTENT_LENGTH, Constants::CONTENT_TYPE, Constants::DATE, Constants::ETAG, Constants::HEADER_LAST, Constants::HEADER_LINK, Constants::HEADER_NEXT, Constants::LOCATION, Constants::META_FIRST, Constants::META_LAST, Constants::META_NEXT, Constants::META_PREV, Constants::META_REL, Constants::OAUTH_SCOPES, Constants::PARAM_PAGE, Constants::PARAM_PER_PAGE, Constants::PARAM_START_PAGE, Constants::RATELIMIT_LIMIT, Constants::RATELIMIT_REMAINING, Constants::SERVER, Constants::USER_AGENT

Constants included from MimeType

MimeType::MEDIA_LOOKUP

Instance Attribute Summary

Attributes inherited from API

#current_options

Attributes included from Authorization

#scopes

Instance Method Summary collapse

Methods inherited from API

#api_methods_in, #append_arguments, #arguments, inherited, #initialize, #method_missing, #process_basic_auth, #set, #setup, #with, #yield_or_eval

Methods included from RateLimit

#ratelimit, #ratelimit_remaining

Methods included from Request

#delete_request, #get_request, #patch_request, #post_request, #put_request, #request

Methods included from Connection

#caching?, #clear_cache, #connection, #default_middleware, #default_options, #stack

Methods included from MimeType

#lookup_media, #parse

Methods included from Authorization

#auth_code, #authenticated?, #authentication, #authorize_url, #basic_authed?, #client, #get_token

Constructor Details

This class inherits a constructor from Github::API

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Github::API

Instance Method Details

#create(*args) ⇒ Object

Create a tree

The tree creation API will take nested entries as well. If both a tree and a nested path modifying that tree are specified, it will overwrite the contents of that tree with the new path contents and write a new tree out.

Parameters

  • :base_tree - optional string of the SHA1 of the tree you want to update with new data

  • :tree - array of hash objects(of :path, :mode, :type and sha)

  • tree.path

    String of the file referenced in the tree

  • tree.mode

    String of the file mode - one of 100644 for file(blob), 100755 for executable (blob), 040000 for subdirectory (tree), 160000 for submodule (commit) or 120000 for a blob that specifies the path of a symlink

  • tree.type

    String of blob, tree, commit

  • tree.sha

    String of SHA1 checksum ID of the object in the tree

  • tree.content

    String of content you want this file to have - GitHub will write this blob out and use the SHA for this entry. Use either this or tree.sha

Examples

github = Github.new
github.git_data.trees.create 'user-name', 'repo-name',
  "tree" => [
    {
      "path" => "file.rb",
      "mode" => "100644",
      "type" => "blob",
      "sha" => "44b4fc6d56897b048c772eb4087f854f46256132"
    },
    ...
  ]


81
82
83
84
85
86
87
88
89
# File 'lib/github_api/git_data/trees.rb', line 81

def create(*args)
  arguments(args, :required => [:user, :repo]) do
    assert_required %w[ tree ]
    sift VALID_TREE_PARAM_NAMES, 'tree', { recursive: true }
    assert_values VALID_TREE_PARAM_VALUES, 'tree'
  end

  post_request("/repos/#{user}/#{repo}/git/trees", arguments.params)
end

#get(*args) ⇒ Object Also known as: find

Get a tree

Examples

github = Github.new
github.git_data.trees.get 'user-name', 'repo-name', 'sha'
github.git_data.trees.get 'user-name', 'repo-name', 'sha' do |file|
  file.path
end

Get a tree recursively

Examples

github = Github.new
github.git_data.trees.get 'user-name', 'repo-name', 'sha', 'recursive' => true


37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/github_api/git_data/trees.rb', line 37

def get(*args)
  arguments(args, :required => [:user, :repo, :sha])
  params = arguments.params

  response = if params['recursive']
    params['recursive'] = 1
    get_request("/repos/#{user}/#{repo}/git/trees/#{sha}", params)
  else
    get_request("/repos/#{user}/#{repo}/git/trees/#{sha.to_s}", params)
  end
  return response unless block_given?
  response.tree.each { |el| yield el }
end