Module: Octokit::Client::Refs

Included in:
Octokit::Client
Defined in:
lib/octokit/client/refs.rb

Overview

Methods for References for Git Data API

See Also:

Instance Method Summary (collapse)

Instance Method Details

- (Array<Sawyer::Resource>) create_ref(repo, ref, sha, options = {}) Also known as: create_reference

Create a reference

Examples:

Create refs/heads/master for octocat/Hello-World with sha 827efc6d56897b048c772eb4087f854f46256132

Octokit.create_ref("octocat/Hello-World","heads/master", "827efc6d56897b048c772eb4087f854f46256132")

Parameters:

  • repo (Integer, String, Repository, Hash)

    A GitHub repository

  • ref (String)

    The ref, e.g. tags/v0.0.3

  • sha (String)

    A SHA, e.g. 827efc6d56897b048c772eb4087f854f46256132

Returns:

  • (Array<Sawyer::Resource>)

    The list of references, already containing the new one

See Also:



48
49
50
51
52
53
54
# File 'lib/octokit/client/refs.rb', line 48

def create_ref(repo, ref, sha, options = {})
  parameters = {
    :ref  => "refs/#{ref}",
    :sha  => sha
  }
  post "#{Repository.path repo}/git/refs", options.merge(parameters)
end

- (Boolean) delete_branch(repo, branch, options = {})

Delete a single branch

Examples:

Delete uritemplate for sigmavirus24/github3.py

Octokit.delete_branch("sigmavirus24/github3.py", "uritemplate")

Parameters:

  • repo (Integer, String, Repository, Hash)

    A GitHub repository

  • branch (String)

    The branch, e.g. fix-refs

Returns:

  • (Boolean)

    Success

See Also:



98
99
100
# File 'lib/octokit/client/refs.rb', line 98

def delete_branch(repo, branch, options = {})
  delete_ref repo, "heads/#{branch}", options
end

- (Boolean) delete_ref(repo, ref, options = {}) Also known as: delete_reference

Delete a single reference

Examples:

Delete tags/v0.0.3 for sferik/rails_admin

Octokit.delete_ref("sferik/rails_admin","tags/v0.0.3")

Parameters:

  • repo (Integer, String, Repository, Hash)

    A GitHub repository

  • ref (String)

    The ref, e.g. tags/v0.0.3

Returns:

  • (Boolean)

    Success

See Also:



110
111
112
# File 'lib/octokit/client/refs.rb', line 110

def delete_ref(repo, ref, options = {})
  boolean_from_response :delete, "#{Repository.path repo}/git/refs/#{ref}", options
end

- (Sawyer::Resource) ref(repo, ref, options = {}) Also known as: reference

Fetch a given reference

Examples:

Fetch tags/v0.0.3 for sferik/rails_admin

Octokit.ref("sferik/rails_admin","tags/v0.0.3")

Parameters:

  • repo (Integer, String, Repository, Hash)

    A GitHub repository

  • ref (String)

    The ref, e.g. tags/v0.0.3

Returns:

  • (Sawyer::Resource)

    The reference matching the given repo and the ref id

See Also:



34
35
36
# File 'lib/octokit/client/refs.rb', line 34

def ref(repo, ref, options = {})
  get "#{Repository.path repo}/git/refs/#{ref}", options
end

- (Array<Sawyer::Resource>) refs(repo, namespace = nil, options = {}) Also known as: list_refs, references, list_references

List all refs for a given user and repo

Examples:

Fetch all refs for sferik/rails_admin

Octokit.refs("sferik/rails_admin")

Parameters:

  • repo (Integer, String, Repository, Hash)

    A GitHub repository

  • namespace (String) (defaults to: nil)

    The ref namespace, e.g. tag or heads

Returns:

  • (Array<Sawyer::Resource>)

    A list of references matching the repo and the namespace

See Also:



17
18
19
20
21
# 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

- (Array<Sawyer::Resource>) update_branch(repo, branch, sha, force = true, options = {})

Update a branch

Examples:

Force update heads/sc/featureA for octocat/Hello-World with sha aa218f56b14c9653891f9e74264a383fa43fefbd

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

Parameters:

  • repo (Integer, String, Repository, Hash)

    A GitHub repository

  • branch (String)

    The ref, e.g. feature/new-shiny

  • sha (String)

    A SHA, e.g. 827efc6d56897b048c772eb4087f854f46256132

  • force (Boolean) (defaults to: true)

    A flag indicating one wants to force the update to make sure the update is a fast-forward update.

Returns:

  • (Array<Sawyer::Resource>)

    The list of references updated

See Also:



86
87
88
# File 'lib/octokit/client/refs.rb', line 86

def update_branch(repo, branch, sha, force = true, options = {})
  update_ref repo, "heads/#{branch}", sha, force, options
end

- (Array<Sawyer::Resource>) update_ref(repo, ref, sha, force = true, options = {}) Also known as: update_reference

Update a reference

Examples:

Force update heads/sc/featureA for octocat/Hello-World with sha aa218f56b14c9653891f9e74264a383fa43fefbd

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

Parameters:

  • repo (Integer, String, Repository, Hash)

    A GitHub repository

  • ref (String)

    The ref, e.g. tags/v0.0.3

  • sha (String)

    A SHA, e.g. 827efc6d56897b048c772eb4087f854f46256132

  • force (Boolean) (defaults to: true)

    A flag indicating one wants to force the update to make sure the update is a fast-forward update.

Returns:

  • (Array<Sawyer::Resource>)

    The list of references updated

See Also:



67
68
69
70
71
72
73
# File 'lib/octokit/client/refs.rb', line 67

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