Class: PRlist::PullRequests

Inherits:
Object
  • Object
show all
Defined in:
lib/pr_list/pull_requests.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token = nil, repos = []) ⇒ PullRequests

Returns a new instance of PullRequests.



41
42
43
44
45
46
# File 'lib/pr_list/pull_requests.rb', line 41

def initialize(token = nil, repos = [])
  @pulls  ||= []
  @github ||= __authenticate token

  repos.each { |repo| load!(repo) } if authorized?
end

Instance Attribute Details

#pullsObject (readonly)

Returns the value of attribute pulls.



39
40
41
# File 'lib/pr_list/pull_requests.rb', line 39

def pulls
  @pulls
end

Instance Method Details

#auth!(token) ⇒ Object



52
53
54
# File 'lib/pr_list/pull_requests.rb', line 52

def auth!(token)
  @github = __authenticate token
end

#authorized?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/pr_list/pull_requests.rb', line 48

def authorized?
  return !@github.nil?
end

#by_dateObject



64
65
66
67
68
# File 'lib/pr_list/pull_requests.rb', line 64

def by_date
  sorted_pulls = @pulls.sort_by { |pr| pr.date }

  block_given? ? sorted_pulls.each { |pr| yield pr } : sorted_pulls
end

#load!(repo) ⇒ Object

Raises:

  • (NoAuthError)


56
57
58
59
60
61
62
# File 'lib/pr_list/pull_requests.rb', line 56

def load!(repo)
  raise NoAuthError, "You must authorized with github using #auth first" unless authorized?

  @github.issues(repo).each do |issue|
    __load_issue issue if issue.pull_request?
  end
end

#reposObject



70
71
72
# File 'lib/pr_list/pull_requests.rb', line 70

def repos
  @pulls.collect { |pr| pr.repo }.uniq
end