Class: GithubActivities::CommentAndReaction

Inherits:
Object
  • Object
show all
Defined in:
lib/github_activities/comment_and_reaction.rb

Instance Method Summary collapse

Instance Method Details

#get(options) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/github_activities/comment_and_reaction.rb', line 6

def get(options)
  Octokit.configure do |c|
    c. = options[:login_user]
    c.password = options[:password]
  end

  name = options[:name]
  repository = options[:repository]
  pages = options[:pages]

  puts name
  puts repository
  puts pages

  result = []
  client = Octokit::Client.new
  (1..pages).each do |index|
    client.pulls(repository, state: :all, page: index).map(&:number).each do |number|
      client.issue_reactions(repository, number, :accept => 'application/vnd.github.squirrel-girl-preview').
        select {|reaction| reaction.user. == name}.
        each {|reaction|
          result << OpenStruct.new(user_id: name, number: number, content: reaction.content, created_at: reaction.created_at)
        }
      client.pull_comments(repository, number).
        select {|comment| comment.user. == name}.
        each {|comment|
          result << OpenStruct.new(user_id: name, number: number, content: comment.body, created_at: comment.created_at)
        }
      client.issue_comments(repository, number).
        select {|comment| comment.user. == name}.
        each {|comment|
          result << OpenStruct.new(user_id: name, number: number, content: comment.body, created_at: comment.created_at)
        }
    end
  end

  puts '----------'
  puts '----------'
  puts '----------'

  result.sort_by(&:created_at).each do |reaction|
    p reaction
  end

  nil
end