Class: Octopi::Commit

Inherits:
Base
  • Object
show all
Includes:
Resource
Defined in:
lib/octopi/commit.rb

Constant Summary

Constants inherited from Base

Base::VALID

Instance Attribute Summary collapse

Attributes inherited from Base

#api

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Resource

for, included

Methods inherited from Base

#initialize, #property, #save

Constructor Details

This class inherits a constructor from Octopi::Base

Instance Attribute Details

#repositoryObject

Returns the value of attribute repository.



7
8
9
# File 'lib/octopi/commit.rb', line 7

def repository
  @repository
end

Class Method Details

.find(*args) ⇒ Object

TODO: Make find use hashes like find_all



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/octopi/commit.rb', line 37

def self.find(*args)
  if args.last.is_a?(Commit)
    commit = args.pop
    super "#{commit.repo_identifier}"
  else
    user, name, sha = *args
    user = user. if user.is_a? User
    name = repo.name  if name.is_a? Repository
    self.validate_args(user => :user, name => :repo, sha => :sha)
    super [user, name, sha]
  end
end

.find_all(*args) ⇒ Object

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


23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/octopi/commit.rb', line 23

def self.find_all(*args)
  api = args.last.is_a?(Api) ? args.pop : ANONYMOUS_API
  repo = args.first
  user ||= repo.owner if repo.is_a? Repository
  user, repo_name, opts = extract_user_repository(*args)
  self.validate_args(user => :user, repo_name => :repo)
  branch = opts[:branch] || "master"
  api = ANONYMOUS_API if repo.is_a?(Repository) && !repo.private
  commits = super user, repo_name, branch, api
  commits.each { |c| c.repository = repo } if repo.is_a? Repository
  commits
end

Instance Method Details

#detailsObject



50
51
52
# File 'lib/octopi/commit.rb', line 50

def details
  self.class.find(self)
end

#repo_identifierObject



54
55
56
57
58
59
60
61
62
63
# File 'lib/octopi/commit.rb', line 54

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