Class: ListPullRequests::User

Inherits:
Object
  • Object
show all
Defined in:
lib/list_pull_requests/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ User

Returns a new instance of User.



4
5
6
7
# File 'lib/list_pull_requests/user.rb', line 4

def initialize(name)
  @name = name
  @all = []
end

Instance Attribute Details

#allObject

Returns the value of attribute all.



2
3
4
# File 'lib/list_pull_requests/user.rb', line 2

def all
  @all
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/list_pull_requests/user.rb', line 2

def name
  @name
end

Instance Method Details

#create_prs(url) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/list_pull_requests/user.rb', line 24

def create_prs(url)
  puts "Retrieving list of pulls....".red
  page = 1
  begin
    # begin
      json = JSON.parse(open(url + "&page=#{page}").read)
      amount ||= json["total_count"]
      json["items"].each do |pr|
        all << ListPullRequests::Pr.new(pr["pull_request"]["url"], pr["html_url"], pr["title"], pr["created_at"])
      end
      page += 1
    # rescue OpenURI::HTTPError
    #   puts "error control"
    # end
  end until all.count == amount
  all
end

#get_allObject



9
10
11
12
# File 'lib/list_pull_requests/user.rb', line 9

def get_all
  result = create_prs("https://api.github.com/search/issues?per_page=100&q=is:pr+author:#{name}")
  # binding.pry
end

#get_mergedObject



14
15
16
17
# File 'lib/list_pull_requests/user.rb', line 14

def get_merged
  create_prs("https://api.github.com/search/issues?per_page=100&q=is:merged+author:#{name}")
  # binding.pry
end

#get_unmergedObject



19
20
21
22
# File 'lib/list_pull_requests/user.rb', line 19

def get_unmerged
  create_prs("https://api.github.com/search/issues?per_page=100&q=is:unmerged+author:#{name}")
  # binding.pry
end