Sha256: 664348b7bed5b5e08fa6959c685e98a642c2d7afa49f20e6b473efce4e23a248

Contents?: true

Size: 1.74 KB

Versions: 1

Compression:

Stored size: 1.74 KB

Contents

module Octopi
  class Commit < Base
    include Resource
    find_path "/commits/list/:query"
    resource_path "/commits/show/:id"
    
    attr_accessor :repository
    
    # Finds all commits for a given Repository's branch
    #
    # You can provide the user and repo parameters as
    # String or as User and Repository objects. When repo
    # is provided as a Repository object, user is superfluous.
    # 
    # If no branch is given, "master" is assumed.
    #
    # Sample usage:
    #
    #   find_all(repo, :branch => "develop") # repo must be an object
    #   find_all("octopi", :user => "fcoury") # user must be provided
    #   find_all(:user => "fcoury", :repo => "octopi") # branch defaults to master
    #
    def self.find_all(*args)
      repo = args.first
      user ||= repo.owner if repo.is_a? Repository
      user, repo_name, opts = extract_user_repository(*args)
      branch = opts[:branch] || "master"
      
      commits = super user, repo_name, branch
      commits.each { |c| c.repository = repo } if repo.is_a? Repository
      commits
    end
    
    # TODO: Make find use hashes like find_all
    def self.find(*args)
      if args.last.is_a?(Commit)
        commit = args.pop
        super "#{commit.repo_identifier}"
      else
        user, name, sha = *args
        user = user.login if user.is_a? User
        name = repo.name  if name.is_a? Repository
        super [user, name, sha]
      end
    end
    
    def details
      self.class.find(self)
    end
    
    def repo_identifier
      url_parts = url.split('/')
      if @repository
        parts = [@repository.owner, @repository.name, url_parts[6]] 
      else
        parts = [url_parts[3], url_parts[4], url_parts[6]]
      end
      
      parts.join('/')
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fcoury-octopi-0.0.5 lib/octopi/commit.rb