Class: Fuselage::Repository

Inherits:
Base
  • Object
show all
Defined in:
lib/fuselage/repository.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#api

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

delete_method, get, #initialize, post

Constructor Details

This class inherits a constructor from Fuselage::Base

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#forkObject

Returns the value of attribute fork.



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

def fork
  @fork
end

#forksObject

Returns the value of attribute forks.



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

def forks
  @forks
end

#homepageObject

Returns the value of attribute homepage.



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

def homepage
  @homepage
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#open_issuesObject

Returns the value of attribute open_issues.



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

def open_issues
  @open_issues
end

#ownerObject

Returns the value of attribute owner.



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

def owner
  @owner
end

#pledgieObject

Returns the value of attribute pledgie.



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

def pledgie
  @pledgie
end

#privateObject

Returns the value of attribute private.



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

def private
  @private
end

#sizeObject

Returns the value of attribute size.



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

def size
  @size
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

#watchersObject

Returns the value of attribute watchers.



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

def watchers
  @watchers
end

Class Method Details

.create(name, options = {}) ⇒ Object



43
44
45
46
# File 'lib/fuselage/repository.rb', line 43

def self.create(name, options={})
  raise AuthenticationRequired unless Api.authenticated
  Repository.new(post('/user/repos', {:name => name}.merge(options)))
end

.find(repo, options = {}) ⇒ Object

Finds a repo with current authenticated user



10
11
12
13
14
15
16
17
18
# File 'lib/fuselage/repository.rb', line 10

def self.find(repo, options={})
  options = {:type => 'all'}.merge(options)
  if options[:user]
    Repository.new(get("/repos/#{options[:user]}/#{repo}", {:type => options[:type]}))
  else
    raise AuthenticationRequired unless Api.authenticated
    Repository.new(get("/repos/#{User.current.}/#{repo}", {:type => options[:type]}))
  end
end

.find_all(options = {}) ⇒ Object

Finds all public repos identified by the given username



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fuselage/repository.rb', line 22

def self.find_all(options={})
  options = {:type => 'all'}.merge(options)
  repos = []
  if options[:user]
    get("/users/#{options[:user]}/repos", {:type => options[:type]}).each { |r| repos << Repository.new(r) }
  else
    raise AuthenticationRequired unless Api.authenticated
    get("/user/repos", {:type => options[:type]}).each { |r| repos << Repository.new(r) }
  end
  repos
end

.find_by_organization(organization, options = {}) ⇒ Object

Finds all public repos identified by the given organization



36
37
38
39
40
41
# File 'lib/fuselage/repository.rb', line 36

def self.find_by_organization(organization, options={})
  options = {:type => 'all'}.merge(options)
  repos = []
  get("/orgs/#{organization}/repos", {:type => options[:type]}).each { |r| repos << Repository.new(r) }
  repos
end

Instance Method Details

#branchesObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/fuselage/repository.rb', line 63

def branches
  raise AuthenticationRequired unless Api.authenticated
  branches = []
  Repository.get("/repos/#{User.current.}/#{self.name}/branches").each do |b| 
    branch = Reference.new
    branch.ref = 'ref/heads/' + b['name']
    branch.url = b['url']
    if b['commit']
      branch.object = b['commit']
      branch.object['type'] = 'commit'
    end
    branches << branch
  end
  branches
end

#commits(options = {}) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/fuselage/repository.rb', line 79

def commits(options={})
  raise AuthenticationRequired unless Api.authenticated
  commits = []
  Repository.get("/repos/#{User.current.}/#{self.name}/commits", options).each do |c| 
    commit = Commit.new(c)
    if c['commit']
      commit.merge_attributes(c['commit'])
    end
    commits << commit
  end
  commits
end

#create_branch(name, parent_sha) ⇒ Object



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

def create_branch(name, parent_sha)
  Reference.create(self.name, "refs/heads/#{name}", parent_sha)
end

#most_recent_commit(ref_sha) ⇒ Object



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

def most_recent_commit(ref_sha)
  commits = self.commits(:sha => ref_sha)
  commits.first
end

#ppObject



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

def pp
  
end

#tagsObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fuselage/repository.rb', line 48

def tags
  raise AuthenticationRequired unless Api.authenticated
  tags = []
  Repository.get("/repos/#{User.current.}/#{self.name}/tags").each do |t| 
    tag = Tag.new
    tag.tag = t['name']
    if t['commit']
      tag.object = t['commit']
      tag.object['type'] = 'commit'
    end
    tags << tag
  end
  tags
end

#to_sObject



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

def to_s
  name
end