Class: Github::GitData::References

Inherits:
API
  • Object
show all
Defined in:
lib/github_api/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 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 reference

Inputs

  • :ref - String of the name of the fully qualified reference (ie: refs/heads/master). If it doesn’t start with ‘refs’ and have at least two slashes, it will be rejected.

  • :sha - String of the SHA1 value to set this reference to

Examples

github = Github.new
github.git_data.references.create 'user-name', 'repo-name',
  "ref" => "refs/heads/master",
  "sha" =>  "827efc6d56897b048c772eb4087f854f46256132"


74
75
76
77
78
79
80
81
82
83
# File 'lib/github_api/git_data/references.rb', line 74

def create(*args)
  arguments(args, :required => [:user, :repo]) do
    sift VALID_REF_PARAM_NAMES
    assert_required REQUIRED_REF_PARAMS
  end
  params = arguments.params
  validate_reference params['ref']

  post_request("/repos/#{user}/#{repo}/git/refs", params)
end

#delete(*args) ⇒ Object Also known as: remove

Delete a reference

Examples

github = Github.new
github.git_data.references.delete 'user-name', 'repo-name',
  "ref" => "refs/heads/master",


114
115
116
117
118
119
# File 'lib/github_api/git_data/references.rb', line 114

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

  delete_request("/repos/#{user}/#{repo}/git/refs/#{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

Examples

github = Github.new
github.git_data.references.get 'user-name', 'repo-name', 'heads/branch'


53
54
55
56
57
58
59
# File 'lib/github_api/git_data/references.rb', line 53

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

  get_request("/repos/#{user}/#{repo}/git/refs/#{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.

Examples

github = Github.new
github.git_data.references.list 'user-name', 'repo-name'

github.git_data.references.list 'user-name', 'repo-name', ref:'tags'


27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/github_api/git_data/references.rb', line 27

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

  response = if (ref = params.delete('ref'))
    validate_reference ref
    get_request("/repos/#{user}/#{repo}/git/refs/#{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

Inputs

  • :sha - String of the SHA1 value to set this reference to

  • :force - Boolean indicating whether to force the update or to make sure the update is a fast-forward update. The default is false, so leaving this out or setting it to false will make sure you’re not overwriting work.

Examples

github = Github.new
github.git_data.references.update 'user-name', 'repo-name', 'heads/master',
  "sha" =>  "827efc6d56897b048c772eb4087f854f46256132",
  "force" => true


97
98
99
100
101
102
103
104
105
# File 'lib/github_api/git_data/references.rb', line 97

def update(*args)
  arguments(args, :required => [:user, :repo, :ref]) do
    sift VALID_REF_PARAM_NAMES
    assert_required %w[ sha ]
  end
  params = arguments.params

  patch_request("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
end