Class: Octopi::Repository

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

Constant Summary

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



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

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)
  if options[:user]
    self.validate_args(options[:user] => :user)
    options[:name] = "#{options[:user]}/#{options[:name]}"
  end
  new(Api.api.post(path_for(:create), options.merge( :cache => false ))["repository"])
end

.find(options = {}) ⇒ Object



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

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



85
86
87
88
89
# File 'lib/octopi/repository.rb', line 85

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



103
104
105
# File 'lib/octopi/repository.rb', line 103

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



67
68
69
70
# File 'lib/octopi/repository.rb', line 67

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

#collaboratorsObject



111
112
113
# File 'lib/octopi/repository.rb', line 111

def collaborators
  property('collaborators', [self.owner, self.name].join('/')).values.flatten.map { |v| User.find(v) }
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
64
65
# File 'lib/octopi/repository.rb', line 44

def comments
  # We have to specify xmlns as a prefix as the document is namespaced.
  # Be wary!
  path = "https://github.com/#{owner}/#{name}/comments.atom"
  xml = Nokogiri::XML(open(URI.parse(path)))
  entries = xml.xpath("//xmlns:entry")
  comments = []
  for entry in entries
    content = entry.xpath("xmlns:content").text.gsub("&lt;", "<").gsub("&gt;", ">")
    comments << Comment.new(
      :id => entry.xpath("xmlns:id"),
      :published => Time.parse(entry.xpath("xmlns:published").text),
      :updated => Time.parse(entry.xpath("xmlns:updated").text),
      :link => entry.xpath("xmlns:link/@href").text,
      :title => entry.xpath("xmlns:title").text,
      :content => content,
      :author => entry.xpath("xmlns:author/xmlns:name").text,
      :repository => self
    )
  end
  comments
end

#commits(branch = "master") ⇒ Object



95
96
97
# File 'lib/octopi/repository.rb', line 95

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

#delete!Object

Raises:



129
130
131
132
133
# File 'lib/octopi/repository.rb', line 129

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



107
108
109
# File 'lib/octopi/repository.rb', line 107

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

#issues(state = "open") ⇒ Object



99
100
101
# File 'lib/octopi/repository.rb', line 99

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

#languagesObject



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

def languages
  property('languages', [self.owner, self.name].join('/')).values.inject({}){|sum,map| map.each{|k,v| sum[k] = v}}
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



135
136
137
# File 'lib/octopi/repository.rb', line 135

def to_s
  name
end