Class: Github::Client::GitData::References
- Defined in:
- lib/github_api2/client/git_data/references.rb
Constant Summary collapse
- VALID_REF_PARAM_NAMES =
%w[ ref sha force ].freeze
- REQUIRED_REF_PARAMS =
%w[ ref sha ].freeze
- VALID_REF_PARAM_VALUES =
{ 'ref' => %r{^refs\/\w+(\/\w+)*} # test fully qualified reference }
Constants included from MimeType
Constants included from Github::Constants
Github::Constants::ACCEPT, Github::Constants::ACCEPTED_OAUTH_SCOPES, Github::Constants::ACCEPT_CHARSET, Github::Constants::CACHE_CONTROL, Github::Constants::CONTENT_LENGTH, Github::Constants::CONTENT_TYPE, Github::Constants::DATE, Github::Constants::ETAG, Github::Constants::HEADER_LAST, Github::Constants::HEADER_LINK, Github::Constants::HEADER_NEXT, Github::Constants::LOCATION, Github::Constants::META_FIRST, Github::Constants::META_LAST, Github::Constants::META_NEXT, Github::Constants::META_PREV, Github::Constants::META_REL, Github::Constants::OAUTH_SCOPES, Github::Constants::PARAM_PAGE, Github::Constants::PARAM_PER_PAGE, Github::Constants::PARAM_START_PAGE, Github::Constants::RATELIMIT_LIMIT, Github::Constants::RATELIMIT_REMAINING, Github::Constants::RATELIMIT_RESET, Github::Constants::SERVER, Github::Constants::USER_AGENT
Instance Attribute Summary
Attributes inherited from API
Instance Method Summary collapse
-
#create(*args) ⇒ Object
Create a reference.
-
#delete(*args) ⇒ Object
(also: #remove)
Delete a reference.
-
#get(*args) ⇒ Object
(also: #find)
Get a reference.
-
#list(*args) ⇒ Object
(also: #all)
Get all references.
-
#update(*args) ⇒ Object
Update a reference.
Methods inherited from API
after_callbacks, after_request, #api_methods_in, #arguments, before_callbacks, before_request, clear_request_methods!, #disable_redirects, #execute, extend_with_actions, extra_methods, #extract_basic_auth, extract_class_name, #filter_callbacks, inherited, #initialize, internal_methods, method_added, #method_missing, #module_methods_in, namespace, request_methods, require_all, #respond_to?, root!, #run_callbacks, #set, #yield_or_eval
Methods included from Request::Verbs
#delete_request, #get_request, #head_request, #options_request, #patch_request, #post_request, #put_request
Methods included from RateLimit
#ratelimit, #ratelimit_remaining, #ratelimit_reset
Methods included from MimeType
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 reference
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/github_api2/client/git_data/references.rb', line 85 def create(*args) arguments(args, required: [:user, :repo]) do permit VALID_REF_PARAM_NAMES assert_required REQUIRED_REF_PARAMS end params = arguments.params validate_reference params['ref'] post_request("/repos/#{arguments.user}/#{arguments.repo}/git/refs", params) end |
#delete(*args) ⇒ Object Also known as: remove
Delete a reference
130 131 132 133 134 135 |
# File 'lib/github_api2/client/git_data/references.rb', line 130 def delete(*args) arguments(args, required: [:user, :repo, :ref]) params = arguments.params delete_request("/repos/#{arguments.user}/#{arguments.repo}/git/refs/#{arguments.ref}", params) end |
#get(*args) ⇒ Object Also known as: find
Get a reference
The ref in the URL must be formatted as heads/branch
, not just branch. For example, the call to get the data for a branch named sc/featureA would be formatted as heads/sc/featureA
59 60 61 62 63 64 65 |
# File 'lib/github_api2/client/git_data/references.rb', line 59 def get(*args) arguments(args, required: [:user, :repo, :ref]) validate_reference arguments.ref params = arguments.params get_request("/repos/#{arguments.user}/#{arguments.repo}/git/refs/#{arguments.ref}", params) end |
#list(*args) ⇒ Object Also known as: all
Get all references
This will return an array of all the references on the system, including things like notes and stashes if they exist on the server. Anything in the namespace, not just heads
and tags
, though that would be the most common.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/github_api2/client/git_data/references.rb', line 31 def list(*args) arguments(args, required: [:user, :repo]) params = arguments.params user = arguments.user repo = arguments.repo response = if (ref = params.delete('ref')) formatted_ref = validate_reference ref get_request("/repos/#{user}/#{repo}/git/#{formatted_ref}", params) else get_request("/repos/#{user}/#{repo}/git/refs", params) end return response unless block_given? response.each { |el| yield el } end |
#update(*args) ⇒ Object
Update a reference
113 114 115 116 117 118 119 120 |
# File 'lib/github_api2/client/git_data/references.rb', line 113 def update(*args) arguments(args, required: [:user, :repo, :ref]) do permit VALID_REF_PARAM_NAMES assert_required %w[ sha ] end patch_request("/repos/#{arguments.user}/#{arguments.repo}/git/refs/#{arguments.ref}", arguments.params) end |