Create a reference
: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
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 a reference
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
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
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
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.
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
Update a reference
: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.
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
# 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