123456789_123456789_123456789_123456789_123456789_

Module: Octokit::Client::Commits

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Defined in: lib/octokit/client/commits.rb

Overview

Methods for the Commits API

Instance Method Summary

Instance Method Details

#commit(repo, sha, options = {}) ⇒ Sawyer::Resource

Get a single commit

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository

  • sha (String)

    The SHA of the commit to fetch

Returns:

  • (Sawyer::Resource)

    A hash representing the commit

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/commits.rb', line 143

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

#commits(repo, sha_or_branch, options = {}) ⇒ Array<Sawyer::Resource> #commits(repo, options = {}) ⇒ Array<Sawyer::Resource>
Also known as: #list_commits

List commits

Overloads:

  • #commits(repo, sha_or_branch, options = {}) ⇒ Array<Sawyer::Resource>
    Deprecated.

    Parameters:

    • repo (Integer, String, Hash, Repository)

      A GitHub repository

    • sha_or_branch (String)

      A commit SHA or branch name

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

      :sha Commit SHA or branch name from which to start the list

  • #commits(repo, options = {}) ⇒ Array<Sawyer::Resource>

    Parameters:

    • repo (Integer, String, Hash, Repository)

      A GitHub repository

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

      :sha Commit SHA or branch name from which to start the list

Returns:

  • (Array<Sawyer::Resource>)

    An array of hashes representing commits

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/commits.rb', line 23

def commits(*args)
  arguments = Octokit::RepoArguments.new(args)
  sha_or_branch = arguments.pop
  arguments.options[:sha] = sha_or_branch if sha_or_branch
  paginate "#{Repository.new(arguments.repo).path}/commits", arguments.options
end

#commits_before(repo, date, options = {}) ⇒ Array<Sawyer::Resource> #commits_before(repo, date, sha_or_branch, options = {}) ⇒ Array<Sawyer::Resource>

Get commits before a specified date

Examples:

Octokit.commits_before('octokit/octokit.rb', '2012-10-01')

Overloads:

  • #commits_before(repo, date, options = {}) ⇒ Array<Sawyer::Resource>

    Parameters:

    • repo (Integer, String, Hash, Repository)

      A GitHub repository

    • date (String)

      Date on which we want to compare

  • #commits_before(repo, date, sha_or_branch, options = {}) ⇒ Array<Sawyer::Resource>
    Deprecated.

    Parameters:

    • repo (Integer, String, Hash, Repository)

      A GitHub repository

    • date (String)

      Date on which we want to compare

    • sha_or_branch (String)

      Commit SHA or branch name from which to start the list

Returns:

  • (Array<Sawyer::Resource>)

    An array of hashes representing commits

See Also:

[ GitHub ]

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

def commits_before(*args)
  arguments = Octokit::RepoArguments.new(args)
  date = parse_date(arguments.shift)
  params = arguments.options
  params.merge!(until: iso8601(date))
  sha_or_branch = arguments.pop
  params[:sha] = sha_or_branch if sha_or_branch
  commits(arguments.repo, params)
end

#commits_between(repo, start_date, end_date, options = {}) ⇒ Array<Sawyer::Resource> #commits_between(repo, start_date, end_date, sha_or_branch, options = {}) ⇒ Array<Sawyer::Resource>

Get commits made between two nominated dates

Examples:

Octokit.commits_between('octokit/octokit.rb', '2012-10-01', '2012-11-01')

Overloads:

  • #commits_between(repo, start_date, end_date, options = {}) ⇒ Array<Sawyer::Resource>

    Parameters:

    • repo (Integer, String, Hash, Repository)

      A GitHub repository

    • start_date (String)

      Start Date on which we want to compare

    • end_date (String)

      End Date on which we want to compare

  • #commits_between(repo, start_date, end_date, sha_or_branch, options = {}) ⇒ Array<Sawyer::Resource>
    Deprecated.

    Parameters:

    • repo (Integer, String, Hash, Repository)

      A GitHub repository

    • start_date (String)

      Start Date on which we want to compare

    • end_date (String)

      End Date on which we want to compare

    • sha_or_branch (String)

      Commit SHA or branch name from which to start the list

Returns:

  • (Array<Sawyer::Resource>)

    An array of hashes representing commits

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/commits.rb', line 122

def commits_between(*args)
  arguments = Octokit::RepoArguments.new(args)
  date = parse_date(arguments.shift)
  end_date = parse_date(arguments.shift)
  if date > end_date
    raise ArgumentError, "Start date #{date} does not precede #{end_date}"
  end

  params = arguments.options
  params.merge!(since: iso8601(date), until: iso8601(end_date))
  sha_or_branch = arguments.pop
  params[:sha] = sha_or_branch if sha_or_branch
  commits(arguments.repo, params)
end

#commits_on(repo, date, options = {}) ⇒ Array<Sawyer::Resource> #commits_on(repo, date, sha_or_branch, options = {}) ⇒ Array<Sawyer::Resource>

Get commits on a specified date

Examples:

Octokit.commits_on('octokit/octokit.rb', '2012-10-01')

Overloads:

  • #commits_on(repo, date, options = {}) ⇒ Array<Sawyer::Resource>

    Parameters:

    • repo (Integer, String, Hash, Repository)

      A GitHub repository

    • date (String)

      Date on which we want to compare

  • #commits_on(repo, date, sha_or_branch, options = {}) ⇒ Array<Sawyer::Resource>
    Deprecated.

    Parameters:

    • repo (Integer, String, Hash, Repository)

      A GitHub repository

    • date (String)

      Date on which we want to compare

    • sha_or_branch (String)

      Commit SHA or branch name from which to start the list

Returns:

  • (Array<Sawyer::Resource>)

    An array of hashes representing commits

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/commits.rb', line 95

def commits_on(*args)
  arguments = Octokit::RepoArguments.new(args)
  date = parse_date(arguments.shift)
  params = arguments.options
  end_date = date + 1
  params.merge!(since: iso8601(date), until: iso8601(end_date))
  sha_or_branch = arguments.pop
  params[:sha] = sha_or_branch if sha_or_branch
  commits(arguments.repo, params)
end

#commits_since(repo, date, options = {}) ⇒ Array<Sawyer::Resource> #commits_since(repo, date, sha_or_branch, options = {}) ⇒ Array<Sawyer::Resource>

Get commits after a specified date

Examples:

Octokit.commits_since('octokit/octokit.rb', '2012-10-01')

Overloads:

  • #commits_since(repo, date, options = {}) ⇒ Array<Sawyer::Resource>

    Parameters:

    • repo (Integer, String, Hash, Repository)

      A GitHub repository

    • date (String)

      Date on which we want to compare

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

      :sha Commit SHA or branch name from which to start the list

  • #commits_since(repo, date, sha_or_branch, options = {}) ⇒ Array<Sawyer::Resource>
    Deprecated.

    Parameters:

    • repo (Integer, String, Hash, Repository)

      A GitHub repository

    • date (String)

      Date on which we want to compare

    • sha_or_branch (String)

      A commit SHA or branch name

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

      :sha Commit SHA or branch name from which to start the list

Returns:

  • (Array<Sawyer::Resource>)

    An array of hashes representing commits

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/commits.rb', line 47

def commits_since(*args)
  arguments = Octokit::RepoArguments.new(args)
  date = parse_date(arguments.shift)
  params = arguments.options
  params.merge!(since: iso8601(date))
  sha_or_branch = arguments.pop
  params[:sha] = sha_or_branch if sha_or_branch
  commits(arguments.repo, params)
end

#compare(repo, start, endd, options = {}) ⇒ Sawyer::Resource

Compare two commits

When using auto_pagination, commits from all pages will be concatenated into the commits attribute of the first page's response.

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository

  • start (String)

    The sha of the starting commit

  • endd (String)

    The sha of the ending commit

Returns:

  • (Sawyer::Resource)

    A hash representing the comparison

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/commits.rb', line 192

def compare(repo, start, endd, options = {})
  paginate "#{Repository.path repo}/compare/#{start}...#{endd}", options do |data, last_response|
    data.commits.concat last_response.data.commits
  end
end

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

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 GitHub's documentation 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" => "wynn@github.com", ... }

Parameters:

  • repo (Integer, 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:

  • (Sawyer::Resource)

    A hash representing the new commit

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/commits.rb', line 176

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

#git_commit(repo, sha, options = {}) ⇒ Sawyer::Resource

Get a detailed git commit

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository

  • sha (String)

    The SHA of the commit to fetch

Returns:

  • (Sawyer::Resource)

    A hash representing the commit

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/commits.rb', line 153

def git_commit(repo, sha, options = {})
  get "#{Repository.path repo}/git/commits/#{sha}", options
end

#list_commits(*args)

Alias for #commits.

[ GitHub ]

  
# File 'lib/octokit/client/commits.rb', line 29

alias list_commits commits

#merge(repo, base, head, options = {}) ⇒ Sawyer::Resource

Merge a branch or sha

Parameters:

  • repo (Integer, 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:

  • (Sawyer::Resource)

    A hash representing the comparison

See Also:

[ GitHub ]

  
# File 'lib/octokit/client/commits.rb', line 206

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