Module: Octokit::Client::Commits

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

Overview

Methods for the Commits API

Instance Method Summary collapse

Instance Method Details

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

Get a single commit

Parameters:

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



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

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

#commit_comment(repo, id, options = {}) ⇒ Sawyer::Resource

Get a single commit comment

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository

  • id (String)

    The ID of the comment to fetch

Returns:

  • (Sawyer::Resource)

    A hash representing the comment

See Also:



207
208
209
# File 'lib/octokit/client/commits.rb', line 207

def commit_comment(repo, id, options = {})
  get "repos/#{Repository.new(repo)}/comments/#{id}", options
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:



197
198
199
# File 'lib/octokit/client/commits.rb', line 197

def commit_comments(repo, sha, options = {})
  get "repos/#{Repository.new(repo)}/commits/#{sha}/comments", 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 (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 (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:



23
24
25
26
27
28
29
30
# File 'lib/octokit/client/commits.rb', line 23

def commits(*args)
  arguments = Octokit::RepoArguments.new(args)
  sha_or_branch = arguments.pop
  if sha_or_branch
    arguments.options[:sha] = sha_or_branch
  end
  paginate "repos/#{Repository.new(arguments.repo)}/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 (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 (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:



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/octokit/client/commits.rb', line 76

def commits_before(*args)
  arguments = Octokit::RepoArguments.new(args)
  date   = parse_date(arguments.shift)
  params = arguments.options
  end_date = date + 1
  params.merge!(:until => iso8601(date))
  sha_or_branch = arguments.pop
  if sha_or_branch
    params[:sha] = sha_or_branch
  end
  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_on('octokit/octokit.rb', '2012-10-01', '2012-11-01')

Overloads:

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

    Parameters:

    • repo (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 (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

Raises:

  • (ArgumentError)

See Also:



132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/octokit/client/commits.rb', line 132

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

  params = arguments.options
  params.merge!(:since => iso8601(date), :until => iso8601(end_date))
  sha_or_branch = arguments.pop
  if sha_or_branch
    params[:sha] = sha_or_branch
  end
  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 (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 (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:



103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/octokit/client/commits.rb', line 103

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
  if sha_or_branch
    params[:sha] = sha_or_branch
  end
  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 (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 (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:



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/octokit/client/commits.rb', line 49

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

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

Compare two commits

Parameters:

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



274
275
276
# File 'lib/octokit/client/commits.rb', line 274

def compare(repo, start, endd, options = {})
  get "repos/#{Repository.new(repo)}/compare/#{start}...#{endd}", options
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 <a href=“GitHub’s”>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" => "wynn@github.com", ... }

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:

  • (Sawyer::Resource)

    A hash representing the new commit

See Also:



176
177
178
179
180
# 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 "repos/#{Repository.new(repo)}/git/commits", options.merge(params)
end

#create_commit_comment(repo, sha, body, path = nil, line = nil, position = nil, options = {}) ⇒ Sawyer::Resource

Create a commit comment

Examples:

Create a commit comment

commit = Octokit.create_commit_comment("octocat/Hello-World", "827efc6d56897b048c772eb4087f854f46256132", "My comment message", "README.md", 10, 1)
commit.commit_id # => "827efc6d56897b048c772eb4087f854f46256132"
commit.body # => "My comment message"
commit.path # => "README.md"
commit.line # => 10
commit.position # => 1

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository

  • sha (String)

    Sha of the commit to comment on

  • body (String)

    Message

  • path (String) (defaults to: nil)

    Relative path of file to comment on

  • line (Integer) (defaults to: nil)

    Line number in the file to comment on

  • position (Integer) (defaults to: nil)

    Line index in the diff to comment on

Returns:

  • (Sawyer::Resource)

    A hash representing the new commit comment

See Also:



228
229
230
231
232
233
234
235
236
237
# File 'lib/octokit/client/commits.rb', line 228

def create_commit_comment(repo, sha, body, path=nil, line=nil, position=nil, options = {})
  params = {
    :body => body,
    :commit_id => sha,
    :path => path,
    :line => line,
    :position => position
  }
  post "repos/#{Repository.new(repo)}/commits/#{sha}/comments", options.merge(params)
end

#delete_commit_comment(repo, id, options = {}) ⇒ nil

Delete a commit comment

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository

  • id (String)

    The ID of the comment to delete

Returns:

  • (nil)

    nil

See Also:



263
264
265
# File 'lib/octokit/client/commits.rb', line 263

def delete_commit_comment(repo, id, options = {})
  boolean_from_response :delete, "repos/#{Repository.new(repo)}/comments/#{id}", options
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:



187
188
189
# File 'lib/octokit/client/commits.rb', line 187

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

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

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:

  • (Sawyer::Resource)

    A hash representing the comparison

See Also:



286
287
288
289
290
291
292
# File 'lib/octokit/client/commits.rb', line 286

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

#update_commit_comment(repo, id, body, options = {}) ⇒ Sawyer::Resource

Update a commit comment

Examples:

Update a commit comment

commit = Octokit.update_commit_comment("octocat/Hello-World", "860296", "Updated commit comment")
commit.id # => 860296
commit.body # => "Updated commit comment"

Parameters:

  • repo (String, Hash, Repository)

    A GitHub repository

  • id (String)

    The ID of the comment to update

  • body (String)

    Message

Returns:

  • (Sawyer::Resource)

    A hash representing the updated commit comment

See Also:



250
251
252
253
254
255
# File 'lib/octokit/client/commits.rb', line 250

def update_commit_comment(repo, id, body, options = {})
  params = {
    :body => body
  }
  patch "repos/#{Repository.new(repo)}/comments/#{id}", options.merge(params)
end