Class: Octopi::Repository

Included Modules

Octopi::Resource

Attributes

Instance Attributes

description [RW] public

Sets the attribute description.

forks [RW] public

Sets the attribute forks.

fork [RW] public

Sets the attribute fork.

homepage [RW] public

Sets the attribute homepage.

name [RW] public

Sets the attribute name.

open_issues [RW] public

Sets the attribute open_issues.

owner [RW] public

Sets the attribute owner.

pledgie [RW] public

Sets the attribute pledgie.

private [RW] public

Sets the attribute private.

url [RW] public

Sets the attribute url.

watchers [RW] public

Sets the attribute watchers.

Constants Inherited from Octopi::Base

VALID

Constructor Summary

This class inherits a constructor from Octopi::Base.

Public Visibility

Public Class Method Summary

create(owner, name, opts = {})
find(options = {})
find_all(*args)
open_issue(args)

Public Instance Method Summary

#all_issues
#branches

Returns all branches for the Repository.

#clone_url
#collaborators
#comments

Returns all the comments for a Repository.

#commits(branch = "master")
#delete
#issue(number)
#issues(state = "open")
#open_issue(args)
#owner=(owner)

Sets the attribute owner..

#tags

Returns all tags for the Repository.

#to_s

Public Instance Methods Inherited from Octopi::Base

error=, property, save

Public Class Method Details

create

public create(owner, name, opts = {})

Meta Tags

Raises:

[APIError]
[View source]


114
115
116
117
118
119
120
# File 'lib/octopi/repository.rb', line 114

def self.create(owner, name, opts = {})
  api = owner.is_a?(User) ? owner.api : ANONYMOUS_API
  raise APIError, "To create a repository you must be authenticated." if api.read_only?
  self.validate_args(name => :repo)
  api.post(path_for(:create), opts.merge(:name => name))
  self.find(owner, name, api)
end

find

public find(options = {})
[View source]


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

def self.find(options={})
  self.validate_hash(options)
  # Lots of people call the same thing differently.
  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

public find_all(*args)
[View source]


80
81
82
83
84
# File 'lib/octopi/repository.rb', line 80

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

open_issue

public open_issue(args)
[View source]


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

def self.open_issue(args)
  Issue.open(args[:user], args[:repo], args)
end

Public Instance Method Details

all_issues

public all_issues
[View source]


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

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

branches

public branches

Returns all branches for the Repository

Example:

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


24
25
26
# File 'lib/octopi/repository.rb', line 24

def branches
  BranchSet
end

clone_url

public clone_url
[View source]


63
64
65
66
# File 'lib/octopi/repository.rb', line 63

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

collaborators

public collaborators
[View source]


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

def collaborators
  property('collaborators', [self.owner,self.name].join('/')).values
end

comments

public comments

Returns all the comments for a Repository

[View source]


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

def comments
  # We have to specify xmlns as a prefix as the document is namespaced.
  # Be wary!
  path = "http#{'s' if private}://github.com/#{owner}/#{name}/comments.atom"
  xml = Nokogiri::XML(Net::HTTP.get(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

public commits(branch = "master")
[View source]


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

def commits(branch = "master")
  Commit.find_all(self, {:branch => branch})
end

delete

public delete
[View source]


122
123
124
125
# File 'lib/octopi/repository.rb', line 122

def delete
  token = @api.post(self.class.path_for(:delete), :id => self.name)['delete_token']
  @api.post(self.class.path_for(:delete), :id => self.name, :delete_token => token) unless token.nil?
end

issue

public issue(number)
[View source]


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

def issue(number)
  Issue.find(self.owner, self, number)
end

issues

public issues(state = "open")
[View source]


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

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

open_issue

public open_issue(args)
[View source]


90
91
92
# File 'lib/octopi/repository.rb', line 90

def open_issue(args)
  Issue.open(self.owner, self, args)
end

owner=

public owner=(owner)

Sets the attribute owner

Meta Tags

[View source]


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

def owner=(owner)
  @owner = User.find(owner)
end

tags

public tags

Returns all tags for the Repository

Example:

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


34
35
36
# File 'lib/octopi/repository.rb', line 34

def tags
  Tag.all(self.owner, self.name)
end

to_s

public to_s
[View source]


127
128
129
# File 'lib/octopi/repository.rb', line 127

def to_s
  name
end
Generated on Friday, July 31 2009 at 05:01:56 PM by YARD 0.2.3.2 (ruby-1.8.6).