Class: Gub::Repository

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(full_name) ⇒ Repository

Returns a new instance of Repository.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/gub/repository.rb', line 5

def initialize full_name
  self.full_name = full_name
  # Strip .git from the name
  self.full_name = self.full_name.split('.').first
  if self.full_name.nil? || self.full_name.empty?
    Gub.log.fatal 'Unable to find repo name'
    exit 1
  else
    Gub.log.debug "Loading information for #{self.full_name}"
    self.info = Gub.github.repo(repo: self.full_name)
  end
end

Instance Attribute Details

#full_nameObject

Returns the value of attribute full_name.



3
4
5
# File 'lib/gub/repository.rb', line 3

def full_name
  @full_name
end

#infoObject

Returns the value of attribute info.



3
4
5
# File 'lib/gub/repository.rb', line 3

def info
  @info
end

Instance Method Details

#add_upstreamObject



46
47
48
# File 'lib/gub/repository.rb', line 46

def add_upstream
  Gub.git.remote('add', 'upstream', "https://github.com/#{self.parent}")
end

#branchesObject



62
63
64
# File 'lib/gub/repository.rb', line 62

def branches
  Gub.git.branch()
end

#browseObject



66
67
68
69
# File 'lib/gub/repository.rb', line 66

def browse
  require 'launchy'
  ::Launchy.open("#{Gub.github.url}#{self.full_name}")
end

#has_issues?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/gub/repository.rb', line 22

def has_issues?
  self.info.has_issues
end

#is_fork?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/gub/repository.rb', line 50

def is_fork?
  self.info.fork
end

#issue(id, action = :fetch, extra_args = nil) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/gub/repository.rb', line 33

def issue id, action = :fetch, extra_args = nil
  if self.has_issues?
    name = self.full_name
  else
    name = self.parent
  end
  Gub::Issue.new(name, id)
end

#issues(params = {}) ⇒ Object



26
27
28
29
30
31
# File 'lib/gub/repository.rb', line 26

def issues params = {}
  issues = []
  issues << Gub.github.issues(self.full_name, params) if self.has_issues?
  issues << Gub.github.issues(self.parent, params)
  issues.flatten!
end

#nameObject



18
19
20
# File 'lib/gub/repository.rb', line 18

def name
  self.full_name.split('/').last
end

#ownerObject



42
43
44
# File 'lib/gub/repository.rb', line 42

def owner
  @full_name.split('/').first
end

#parentObject



54
55
56
# File 'lib/gub/repository.rb', line 54

def parent
  self.info.parent.full_name.split('.').first if self.info.parent
end

#syncObject



58
59
60
# File 'lib/gub/repository.rb', line 58

def sync
  Gub.git.sync('upstream')
end