Class: Octopi::Repository
- Includes:
- Resource
- Defined in:
- lib/octopi/repository.rb
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
-
#created ⇒ Object
Returns the value of attribute created.
-
#description ⇒ Object
Returns the value of attribute description.
-
#followers ⇒ Object
Returns the value of attribute followers.
-
#fork ⇒ Object
Returns the value of attribute fork.
-
#forks ⇒ Object
Returns the value of attribute forks.
-
#homepage ⇒ Object
Returns the value of attribute homepage.
-
#id ⇒ Object
Returns the value of attribute id.
-
#language ⇒ Object
Returns the value of attribute language.
-
#name ⇒ Object
Returns the value of attribute name.
-
#open_issues ⇒ Object
Returns the value of attribute open_issues.
-
#owner ⇒ Object
Returns the value of attribute owner.
-
#pledgie ⇒ Object
Returns the value of attribute pledgie.
-
#private ⇒ Object
Returns the value of attribute private.
-
#pushed ⇒ Object
Returns the value of attribute pushed.
-
#score ⇒ Object
Returns the value of attribute score.
-
#size ⇒ Object
Returns the value of attribute size.
-
#type ⇒ Object
Returns the value of attribute type.
-
#url ⇒ Object
Returns the value of attribute url.
-
#username ⇒ Object
Returns the value of attribute username.
-
#watchers ⇒ Object
Returns the value of attribute watchers.
Attributes inherited from Base
Class Method Summary collapse
- .create(options = {}) ⇒ Object
- .find(options = {}) ⇒ Object
- .find_all(*args) ⇒ Object (also: search)
Instance Method Summary collapse
- #all_issues ⇒ Object
-
#branches ⇒ Object
Returns all branches for the Repository.
- #clone_url ⇒ Object
- #collaborators ⇒ Object
-
#comments ⇒ Object
Returns all the comments for a Repository.
- #commits(branch = "master") ⇒ Object
- #delete! ⇒ Object
- #issue(number) ⇒ Object
- #issues(state = "open") ⇒ Object
- #languages ⇒ Object
-
#tags ⇒ Object
Returns all tags for the Repository.
- #to_s ⇒ Object
Methods included from Resource
Methods inherited from Base
#error=, #initialize, #property, #save
Constructor Details
This class inherits a constructor from Octopi::Base
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
4 5 6 |
# File 'lib/octopi/repository.rb', line 4 def actions @actions end |
#created ⇒ Object
Returns the value of attribute created.
4 5 6 |
# File 'lib/octopi/repository.rb', line 4 def created @created end |
#description ⇒ Object
Returns the value of attribute description.
4 5 6 |
# File 'lib/octopi/repository.rb', line 4 def description @description end |
#followers ⇒ Object
Returns the value of attribute followers.
4 5 6 |
# File 'lib/octopi/repository.rb', line 4 def followers @followers end |
#fork ⇒ Object
Returns the value of attribute fork.
4 5 6 |
# File 'lib/octopi/repository.rb', line 4 def fork @fork end |
#forks ⇒ Object
Returns the value of attribute forks.
4 5 6 |
# File 'lib/octopi/repository.rb', line 4 def forks @forks end |
#homepage ⇒ Object
Returns the value of attribute homepage.
4 5 6 |
# File 'lib/octopi/repository.rb', line 4 def homepage @homepage end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/octopi/repository.rb', line 4 def id @id end |
#language ⇒ Object
Returns the value of attribute language.
4 5 6 |
# File 'lib/octopi/repository.rb', line 4 def language @language end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/octopi/repository.rb', line 4 def name @name end |
#open_issues ⇒ Object
Returns the value of attribute open_issues.
4 5 6 |
# File 'lib/octopi/repository.rb', line 4 def open_issues @open_issues end |
#owner ⇒ Object
Returns the value of attribute owner.
4 5 6 |
# File 'lib/octopi/repository.rb', line 4 def owner @owner end |
#pledgie ⇒ Object
Returns the value of attribute pledgie.
4 5 6 |
# File 'lib/octopi/repository.rb', line 4 def pledgie @pledgie end |
#private ⇒ Object
Returns the value of attribute private.
4 5 6 |
# File 'lib/octopi/repository.rb', line 4 def private @private end |
#pushed ⇒ Object
Returns the value of attribute pushed.
4 5 6 |
# File 'lib/octopi/repository.rb', line 4 def pushed @pushed end |
#score ⇒ Object
Returns the value of attribute score.
4 5 6 |
# File 'lib/octopi/repository.rb', line 4 def score @score end |
#size ⇒ Object
Returns the value of attribute size.
4 5 6 |
# File 'lib/octopi/repository.rb', line 4 def size @size end |
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/octopi/repository.rb', line 4 def type @type end |
#url ⇒ Object
Returns the value of attribute url.
4 5 6 |
# File 'lib/octopi/repository.rb', line 4 def url @url end |
#username ⇒ Object
Returns the value of attribute username.
4 5 6 |
# File 'lib/octopi/repository.rb', line 4 def username @username end |
#watchers ⇒ Object
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(={}) raise AuthenticationRequired, "To create a repository you must be authenticated." if Api.api.read_only? self.validate_args([:name] => :repo) if [:user] self.validate_args([:user] => :user) [:name] = "#{[:user]}/#{[:name]}" end new(Api.api.post(path_for(:create), .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(={}) ensure_hash() # Lots of people call the same thing differently. # Can't call gather_details here because this method is used by it internally. repo = [:repo] || [:repository] || [:name] user = [: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_issues ⇒ Object
103 104 105 |
# File 'lib/octopi/repository.rb', line 103 def all_issues Issue::STATES.map{|state| self.issues(state)}.flatten end |
#branches ⇒ Object
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_url ⇒ Object
67 68 69 70 |
# File 'lib/octopi/repository.rb', line 67 def clone_url url = private || Api.api.login == self.owner.login ? "[email protected]:" : "git://github.com/" url += "#{self.owner}/#{self.name}.git" end |
#collaborators ⇒ Object
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 |
#comments ⇒ Object
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("<", "<").gsub(">", ">") 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
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.login != owner.login 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 |
#languages ⇒ Object
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 |
#tags ⇒ Object
Returns all tags for the Repository
Example:
repo = Repository.find("fcoury", "octopi")
repo..each { |t| puts t.name }
38 39 40 |
# File 'lib/octopi/repository.rb', line 38 def Tag.all(:user => self.owner, :repo => self) end |
#to_s ⇒ Object
135 136 137 |
# File 'lib/octopi/repository.rb', line 135 def to_s name end |