Class: DevTools::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.



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

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.



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

def pulls
  @pulls
end

Instance Method Details

#auth!(token) ⇒ Object



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

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

#authorized?Boolean

Returns:

  • (Boolean)


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

def authorized?
  return !@github.nil?
end

#by_dateObject



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

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)


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

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



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

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