class Github::GitData::References

Constants

REQUIRED_REF_PARAMS
VALID_REF_PARAM_NAMES
VALID_REF_PARAM_VALUES

Public Instance Methods

all(*args)
Alias for: list
create(*args) click to toggle source

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"
# File lib/github_api/git_data/references.rb, line 73
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) click to toggle source

Delete a reference

Examples

github = Github.new
github.git_data.references.delete 'user-name', 'repo-name',
  "ref" => "refs/heads/master",
# File lib/github_api/git_data/references.rb, line 113
def delete(*args)
  arguments(args, :required => [:user, :repo, :ref])
  params = arguments.params

  delete_request("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
end
Also aliased as: remove
find(*args)
Alias for: get
get(*args) click to toggle source

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'
# File lib/github_api/git_data/references.rb, line 52
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
Also aliased as: find
list(*args) { |el| ... } click to toggle source

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'
# File lib/github_api/git_data/references.rb, line 26
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
Also aliased as: all
remove(*args)
Alias for: delete
update(*args) click to toggle source

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
# File lib/github_api/git_data/references.rb, line 96
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

Private Instance Methods

validate_reference(ref) click to toggle source
# File lib/github_api/git_data/references.rb, line 123
def validate_reference(ref)
  refs = (ref =~ (/^(\/)?refs.*/) ? ref : "refs/#{ref}").gsub(/(\/)+/, '/')
  refs.gsub!(/^\//, '')
  unless VALID_REF_PARAM_VALUES['ref'] =~ refs
    raise ArgumentError, "Provided 'reference' is invalid"
  end
end