module Octokit::Client::Refs

Methods for References for Git Data API

@see developer.github.com/v3/git/refs/

Public Instance Methods

create_ref(repo, ref, sha, options = {}) click to toggle source

Create a reference

@param repo [Integer, String, Repository, Hash] A GitHub repository @param ref [String] The ref, e.g. tags/v0.0.3 @param sha [String] A SHA, e.g. 827efc6d56897b048c772eb4087f854f46256132 @return [Array<Sawyer::Resource>] The list of references, already containing the new one @see developer.github.com/v3/git/refs/#create-a-reference @example Create refs/heads/master for octocat/Hello-World with sha 827efc6d56897b048c772eb4087f854f46256132

Octokit.create_ref("octocat/Hello-World", "heads/master", "827efc6d56897b048c772eb4087f854f46256132")
# File lib/octokit/client/refs.rb, line 48
def create_ref(repo, ref, sha, options = {})
  ref = "refs/#{ref}" unless ref =~ %r{refs/}
  parameters = {
    :ref  => ref,
    :sha  => sha
  }
  post "#{Repository.path repo}/git/refs", options.merge(parameters)
end
Also aliased as: create_reference
create_reference(repo, ref, sha, options = {})
Alias for: create_ref
delete_branch(repo, branch, options = {}) click to toggle source

Delete a single branch

@param repo [Integer, String, Repository, Hash] A GitHub repository @param branch [String] The branch, e.g. fix-refs @return [Boolean] Success @see developer.github.com/v3/git/refs/#delete-a-reference @example Delete uritemplate for sigmavirus24/github3.py

Octokit.delete_branch("sigmavirus24/github3.py", "uritemplate")
# File lib/octokit/client/refs.rb, line 103
def delete_branch(repo, branch, options = {})
  delete_ref repo, "heads/#{branch}", options
end
delete_ref(repo, ref, options = {}) click to toggle source

Delete a single reference

@param repo [Integer, String, Repository, Hash] A GitHub repository @param ref [String] The ref, e.g. tags/v0.0.3 @return [Boolean] Success @see developer.github.com/v3/git/refs/#delete-a-reference @example Delete tags/v0.0.3 for sferik/rails_admin

Octokit.delete_ref("sferik/rails_admin","tags/v0.0.3")
# File lib/octokit/client/refs.rb, line 115
def delete_ref(repo, ref, options = {})
  boolean_from_response :delete, "#{Repository.path repo}/git/refs/#{ref}", options
end
Also aliased as: delete_reference
delete_reference(repo, ref, options = {})
Alias for: delete_ref
list_references(repo, namespace = nil, options = {})
Alias for: refs
list_refs(repo, namespace = nil, options = {})
Alias for: refs
ref(repo, ref, options = {}) click to toggle source

Fetch a given reference

@param repo [Integer, String, Repository, Hash] A GitHub repository @param ref [String] The ref, e.g. tags/v0.0.3 @return [Sawyer::Resource] The reference matching the given repo and the ref id @see developer.github.com/v3/git/refs/#get-a-reference @example Fetch tags/v0.0.3 for sferik/rails_admin

Octokit.ref("sferik/rails_admin","tags/v0.0.3")
# File lib/octokit/client/refs.rb, line 34
def ref(repo, ref, options = {})
  get "#{Repository.path repo}/git/refs/#{ref}", options
end
Also aliased as: reference
reference(repo, ref, options = {})
Alias for: ref
references(repo, namespace = nil, options = {})
Alias for: refs
refs(repo, namespace = nil, options = {}) click to toggle source

List all refs for a given user and repo

@param repo [Integer, String, Repository, Hash] A GitHub repository @param namespace [String] The ref namespace, e.g. tag or heads @return [Array<Sawyer::Resource>] A list of references matching the repo and the namespace @see developer.github.com/v3/git/refs/#get-all-references @example Fetch all refs for sferik/rails_admin

Octokit.refs("sferik/rails_admin")
# File lib/octokit/client/refs.rb, line 17
def refs(repo, namespace = nil, options = {})
  path = "#{Repository.path repo}/git/refs"
  path += "/#{namespace}" unless namespace.nil?
  paginate path, options
end
Also aliased as: list_refs, references, list_references
update_branch(repo, branch, sha, force = true, options = {}) click to toggle source

Update a branch

@param repo [Integer, String, Repository, Hash] A GitHub repository @param branch [String] The ref, e.g. feature/new-shiny @param sha [String] A SHA, e.g. 827efc6d56897b048c772eb4087f854f46256132 @param force [Boolean] A flag indicating whether to force the update or to make sure the update is a fast-forward update. @return [Array<Sawyer::Resource>] The list of references updated @see developer.github.com/v3/git/refs/#update-a-reference @example Force update heads/sc/featureA for octocat/Hello-World with sha aa218f56b14c9653891f9e74264a383fa43fefbd

Octokit.update_branch("octocat/Hello-World", "sc/featureA", "aa218f56b14c9653891f9e74264a383fa43fefbd")

@example Fast-forward update heads/sc/featureA for octocat/Hello-World with sha aa218f56b14c9653891f9e74264a383fa43fefbd

Octokit.update_branch("octocat/Hello-World", "sc/featureA", "aa218f56b14c9653891f9e74264a383fa43fefbd", false)
# File lib/octokit/client/refs.rb, line 91
def update_branch(repo, branch, sha, force = true, options = {})
  update_ref repo, "heads/#{branch}", sha, force, options
end
update_ref(repo, ref, sha, force = true, options = {}) click to toggle source

Update a reference

@param repo [Integer, String, Repository, Hash] A GitHub repository @param ref [String] The ref, e.g. tags/v0.0.3 @param sha [String] A SHA, e.g. 827efc6d56897b048c772eb4087f854f46256132 @param force [Boolean] A flag indicating whether to force the update or to make sure the update is a fast-forward update. @return [Array<Sawyer::Resource>] The list of references updated @see developer.github.com/v3/git/refs/#update-a-reference @example Force update heads/sc/featureA for octocat/Hello-World with sha aa218f56b14c9653891f9e74264a383fa43fefbd

Octokit.update_ref("octocat/Hello-World", "heads/sc/featureA", "aa218f56b14c9653891f9e74264a383fa43fefbd")

@example Fast-forward update heads/sc/featureA for octocat/Hello-World with sha aa218f56b14c9653891f9e74264a383fa43fefbd

Octokit.update_ref("octocat/Hello-World", "heads/sc/featureA", "aa218f56b14c9653891f9e74264a383fa43fefbd", false)
# File lib/octokit/client/refs.rb, line 70
def update_ref(repo, ref, sha, force = true, options = {})
  parameters = {
    :sha  => sha,
    :force => force
  }
  patch "#{Repository.path repo}/git/refs/#{ref}", options.merge(parameters)
end
Also aliased as: update_reference
update_reference(repo, ref, sha, force = true, options = {})
Alias for: update_ref