Module: Octokit::Client::Commits

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

Instance Method Summary collapse

Instance Method Details

#commit(repo, sha, options = {}) ⇒ Hashie::Mash

Get a single commit

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository

  • sha (String)

    The SHA of the commit to fetch

Returns:

  • (Hashie::Mash)

    A hash representing the commit

See Also:



26
27
28
# File 'lib/octokit/client/commits.rb', line 26

def commit(repo, sha, options={})
  get("repos/#{Repository.new(repo)}/commits/#{sha}", options, 3)
end

#commit_comment(repo, id, options = {}) ⇒ Hashie::Mash

Get a single commit comment

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository

  • id (String)

    The ID of the comment to fetch

Returns:

  • (Hashie::Mash)

    A hash representing the comment

See Also:



80
81
82
# File 'lib/octokit/client/commits.rb', line 80

def commit_comment(repo, id, options={})
  get("repos/#{Repository.new(repo)}/comments/#{id}", options, 3)
end

#commit_comments(repo, sha, options = {}) ⇒ Array

List comments for a single commit

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository

  • sha (String)

    The SHA of the commit whose comments will be fetched

Returns:

  • (Array)

    An array of hashes representing comments

See Also:



70
71
72
# File 'lib/octokit/client/commits.rb', line 70

def commit_comments(repo, sha, options={})
  get("repos/#{Repository.new(repo)}/commits/#{sha}/comments", options, 3)
end

#commits(repo, sha_or_branch = "master", options = {}) ⇒ Array Also known as: list_commits

List commits

Optionally pass path => "path/to/file.rb" in options to only return commits containing the given file path.

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository

  • sha_or_branch (String) (defaults to: "master")

    Commit SHA or branch name from which to start the list

Returns:

  • (Array)

    An array of hashes representing commits

See Also:



14
15
16
17
# File 'lib/octokit/client/commits.rb', line 14

def commits(repo, sha_or_branch="master", options={})
  params = { :sha => sha_or_branch, :per_page => 35 }
  get("repos/#{Repository.new(repo)}/commits", params.merge(options), 3)
end

#compare(repo, start, endd, options = {}) ⇒ Hashie::Mash

Compare two commits

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository

  • base (String)

    The sha of the starting commit

  • end (String)

    The sha of the ending commit

Returns:

  • (Hashie::Mash)

    A hash representing the comparison

See Also:



91
92
93
# File 'lib/octokit/client/commits.rb', line 91

def compare(repo, start, endd, options={})
  get("repos/#{Repository.new(repo)}/compare/#{start}...#{endd}", options, 3)
end

#create_commit(repo, message, tree, parents = nil, options = {}) ⇒ Hashie::Mash

Create a commit

Optionally pass author and committer hashes in options if you’d like manual control over those parameters. If absent, details will be inferred from the authenticated user. See <a href=“developer.github.com/v3/git/commits/”>GitHub’s documentation</a> for details about how to format committer identities.

Examples:

Create a commit

commit = Octokit.create_commit("octocat/Hello-World", "My commit message", "827efc6d56897b048c772eb4087f854f46256132", "7d1b31e74ee336d15cbd21741bc88a537ed063a0")
commit.sha # => "7638417db6d59f3c431d3e1f261cc637155684cd"
commit.tree.sha # => "827efc6d56897b048c772eb4087f854f46256132"
commit.message # => "My commit message"
commit.committer # => { "name" => "Wynn Netherland", "email" => "[email protected]", ... }

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository

  • message (String)

    The commit message

  • tree (String)

    The SHA of the tree object the new commit will point to

  • parents (String, Array) (defaults to: nil)

    One SHA (for a normal commit) or an array of SHAs (for a merge) of the new commit’s parent commits. If ommitted or empty, a root commit will be created

Returns:

  • (Hashie::Mash)

    A hash representing the new commit

See Also:



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

def create_commit(repo, message, tree, parents=nil, options={})
  params = { :message => message, :tree => tree }
  params[:parents] = [parents].flatten if parents
  post("repos/#{Repository.new(repo)}/git/commits", options.merge(params), 3)
end

#list_commit_comments(repo, options = {}) ⇒ Array

List all commit comments

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository

Returns:

  • (Array)

    An array of hashes representing comments

See Also:



60
61
62
# File 'lib/octokit/client/commits.rb', line 60

def list_commit_comments(repo, options={})
  get("repos/#{Repository.new(repo)}/comments", options, 3)
end

#merge(repo, base, head, options = {}) ⇒ Hashie::Mash

Merge a branch or sha

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository

  • base (String)

    The name of the base branch to merge into

  • head (String)

    The branch or SHA1 to merge

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :commit_message (String)

    The commit message for the merge

Returns:

  • (Hashie::Mash)

    A hash representing the comparison

See Also:



103
104
105
106
107
108
109
# File 'lib/octokit/client/commits.rb', line 103

def merge(repo, base, head, options={})
  params = {
    :base => base,
    :head => head
  }.merge(options)
  post("repos/#{Repository.new(repo)}/merges", params, 3)
end