Sha256: 91d5181fca16302bbc86157dff1857ea1f7d2f62b1eb80ddbd2751b2a9010100

Contents?: true

Size: 2 KB

Versions: 6

Compression:

Stored size: 2 KB

Contents

# encoding: utf-8

module Github
  class Repos::Commits < API

    VALID_COMMITS_OPTIONS = %w[
      sha
      path
      author
      since
      until
    ].freeze

    # List commits on a repository
    #
    # = Parameters
    # * <tt>:sha</tt>     Optional string. Sha or branch to start listing commits from.
    # * <tt>:path</tt>    Optional string. Only commits containing this file path will be returned.
    # * <tt>:author</tt>  GitHub login, name, or email by which to filter by commit author.
    #
    # = Examples
    #  github = Github.new
    #  github.repos.commits.list 'user-name', 'repo-name', :sha => '...'
    #  github.repos.commits.list 'user-name', 'repo-name', :sha => '...' { |commit| ... }
    #
    def list(user_name, repo_name, params={})
      set :user => user_name, :repo => repo_name
      assert_presence_of user, repo
      normalize! params
      filter! VALID_COMMITS_OPTIONS, params

      response = get_request("/repos/#{user}/#{repo}/commits", params)
      return response unless block_given?
      response.each { |el| yield el }
    end
    alias :all :list

    # Gets a single commit
    #
    # = Examples
    #  github = Github.new
    #  github.repos.commits.get 'user-name', 'repo-name', '6dcb09b5b57875f334f61aebed6')
    #
    def get(user_name, repo_name, sha, params={})
      set :user => user_name, :repo => repo_name
      assert_presence_of user, repo, sha
      normalize! params

      get_request("/repos/#{user}/#{repo}/commits/#{sha}", params)
    end
    alias :find :get

    # Compares two commits
    #
    # = Examples
    #  github = Github.new
    #  github.repos.commits.compare
    #    'user-name',
    #    'repo-name',
    #    'v0.4.8',
    #    'master'
    #
    def compare(user_name, repo_name, base, head, params={})
      set :user => user_name, :repo => repo_name
      assert_presence_of base, head
      normalize! params

      get_request("/repos/#{user_name}/#{repo_name}/compare/#{base}...#{head}", params)
    end

  end # Repos::Commits
end # Github

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
github_api-0.9.0 lib/github_api/repos/commits.rb
github_api-0.8.11 lib/github_api/repos/commits.rb
github_api-0.8.10 lib/github_api/repos/commits.rb
github_api-0.8.9 lib/github_api/repos/commits.rb
github_api-0.8.8 lib/github_api/repos/commits.rb
github_api-0.8.7 lib/github_api/repos/commits.rb