Class: Octopi::Repository

Inherits:
Base
  • Object
show all
Includes:
Resource
Defined in:
lib/octopi/repository.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

#error=, #initialize, #property, #save

Constructor Details

This class inherits a constructor from Octopi::Base

Instance Attribute Details

#actionsObject

Returns the value of attribute actions.



4
5
6
# File 'lib/octopi/repository.rb', line 4

def actions
  @actions
end

#createdObject

Returns the value of attribute created.



4
5
6
# File 'lib/octopi/repository.rb', line 4

def created
  @created
end

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/octopi/repository.rb', line 4

def description
  @description
end

#followersObject

Returns the value of attribute followers.



4
5
6
# File 'lib/octopi/repository.rb', line 4

def followers
  @followers
end

#forkObject

Returns the value of attribute fork.



4
5
6
# File 'lib/octopi/repository.rb', line 4

def fork
  @fork
end

#forksObject

Returns the value of attribute forks.



4
5
6
# File 'lib/octopi/repository.rb', line 4

def forks
  @forks
end

#homepageObject

Returns the value of attribute homepage.



4
5
6
# File 'lib/octopi/repository.rb', line 4

def homepage
  @homepage
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/octopi/repository.rb', line 4

def id
  @id
end

#languageObject

Returns the value of attribute language.



4
5
6
# File 'lib/octopi/repository.rb', line 4

def language
  @language
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/octopi/repository.rb', line 4

def name
  @name
end

#open_issuesObject

Returns the value of attribute open_issues.



4
5
6
# File 'lib/octopi/repository.rb', line 4

def open_issues
  @open_issues
end

#ownerObject

Returns the value of attribute owner.



4
5
6
# File 'lib/octopi/repository.rb', line 4

def owner
  @owner
end

#pledgieObject

Returns the value of attribute pledgie.



4
5
6
# File 'lib/octopi/repository.rb', line 4

def pledgie
  @pledgie
end

#privateObject

Returns the value of attribute private.



4
5
6
# File 'lib/octopi/repository.rb', line 4

def private
  @private
end

#pushedObject

Returns the value of attribute pushed.



4
5
6
# File 'lib/octopi/repository.rb', line 4

def pushed
  @pushed
end

#scoreObject

Returns the value of attribute score.



4
5
6
# File 'lib/octopi/repository.rb', line 4

def score
  @score
end

#sizeObject

Returns the value of attribute size.



4
5
6
# File 'lib/octopi/repository.rb', line 4

def size
  @size
end

#typeObject

Returns the value of attribute type.



4
5
6
# File 'lib/octopi/repository.rb', line 4

def type
  @type
end

#urlObject

Returns the value of attribute url.



4
5
6
# File 'lib/octopi/repository.rb', line 4

def url
  @url
end

#usernameObject

Returns the value of attribute username.



4
5
6
# File 'lib/octopi/repository.rb', line 4

def username
  @username
end

#watchersObject

Returns the value of attribute watchers.



4
5
6
# File 'lib/octopi/repository.rb', line 4

def watchers
  @watchers
end

Class Method Details

.create(options = {}) ⇒ Object



113
114
115
116
117
# File 'lib/octopi/repository.rb', line 113

def self.create(options={})
  raise AuthenticationRequired, "To create a repository you must be authenticated." if Api.api.read_only?
  self.validate_args(options[:name] => :repo)
  new(Api.api.post(path_for(:create), options)["repository"])
end

.find(options = {}) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/octopi/repository.rb', line 70

def self.find(options={})
  ensure_hash(options)
  # Lots of people call the same thing differently.
  # Can't call gather_details here because this method is used by it internally.
  repo = options[:repo] || options[:repository] || options[:name]
  user = options[:user].to_s

  return find_plural(user, :resource) if repo.nil?
  
  self.validate_args(user => :user, repo => :repo)
  super user, repo
end

.find_all(*args) ⇒ Object Also known as: search



83
84
85
86
87
# File 'lib/octopi/repository.rb', line 83

def self.find_all(*args)
  # FIXME: This should be URI escaped, but have to check how the API
  # handles escaped characters first.
  super args.join(" ").gsub(/ /,'+')
end

Instance Method Details

#all_issuesObject



101
102
103
# File 'lib/octopi/repository.rb', line 101

def all_issues
  Issue::STATES.map{|state| self.issues(state)}.flatten
end

#branchesObject

Returns all branches for the Repository

Example:

repo = Repository.find("fcoury", "octopi")
repo.branches.each { |r| puts r.name }


28
29
30
# File 'lib/octopi/repository.rb', line 28

def branches
  Branch.all(:user => self.owner, :repo => self)
end

#clone_urlObject



65
66
67
68
# File 'lib/octopi/repository.rb', line 65

def clone_url
  url = private || Api.api. == self.owner. ? "[email protected]:" : "git://github.com/"
  url += "#{self.owner}/#{self.name}.git"
end

#collaboratorsObject



109
110
111
# File 'lib/octopi/repository.rb', line 109

def collaborators
  property('collaborators', [self.owner, self.name].join('/')).values.map { |v| User.find(v.join) }
end

#commentsObject

Returns all the comments for a Repository



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/octopi/repository.rb', line 44

def comments
  path = "http#{'s' if private}://github.com/#{owner}/#{name}/comments.atom"
  xml = Crack::XML.parse(Net::HTTP.get(URI.parse(path)))

  # handle crack not always returning an array
  entries = [xml["feed"]["entry"]].flatten

  comments = entries.map do |entry|
    Comment.new(
      :id => entry["id"],
      :published => Time.parse(entry["published"]),
      :updated => Time.parse(entry["updated"]),
      :link => entry["link"]["href"],
      :title => entry["title"],
      :content => entry["content"].gsub("&lt;", "<").gsub("&gt;", ">"),
      :author => entry["author"]["name"],
      :repository => self
    )
  end
end

#commits(branch = "master") ⇒ Object



93
94
95
# File 'lib/octopi/repository.rb', line 93

def commits(branch = "master")
  Commit.find_all(:user => self.owner, :repo => self, :branch => branch)
end

#delete!Object

Raises:



119
120
121
122
123
# File 'lib/octopi/repository.rb', line 119

def delete!
  raise APIError, "You must be authenticated as the owner of this repository to delete it" if Api.me. != owner.
  token = Api.api.post(self.class.path_for(:delete), :id => self.name)['delete_token']
  Api.api.post(self.class.path_for(:delete), :id => self.name, :delete_token => token) unless token.nil?
end

#issue(number) ⇒ Object



105
106
107
# File 'lib/octopi/repository.rb', line 105

def issue(number)
  Issue.find(:user => self.owner, :repo => self, :number => number)
end

#issues(state = "open") ⇒ Object



97
98
99
# File 'lib/octopi/repository.rb', line 97

def issues(state = "open")
  IssueSet.new(Octopi::Issue.find_all(:user => owner, :repository => self))
end

#tagsObject

Returns all tags for the Repository

Example:

repo = Repository.find("fcoury", "octopi")
repo.tags.each { |t| puts t.name }


38
39
40
# File 'lib/octopi/repository.rb', line 38

def tags
  Tag.all(:user => self.owner, :repo => self)
end

#to_sObject



125
126
127
# File 'lib/octopi/repository.rb', line 125

def to_s
  name
end