Class: Takoyaki::Commands::Activities
- Inherits:
-
Object
- Object
- Takoyaki::Commands::Activities
- Defined in:
- lib/takoyaki/commands/activities.rb
Instance Attribute Summary collapse
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize ⇒ Activities
constructor
A new instance of Activities.
Constructor Details
#initialize ⇒ Activities
Returns a new instance of Activities.
8 9 10 11 12 13 14 |
# File 'lib/takoyaki/commands/activities.rb', line 8 def initialize now = Time.now to = now + 24 * 60 * 60 @to = Time.new(to.year, to.month, to.day) from = to - 7 * 24 * 60 * 60 @from = Time.new(from.year, from.month, from.day) end |
Instance Attribute Details
#from ⇒ Object (readonly)
Returns the value of attribute from.
6 7 8 |
# File 'lib/takoyaki/commands/activities.rb', line 6 def from @from end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
6 7 8 |
# File 'lib/takoyaki/commands/activities.rb', line 6 def to @to end |
Instance Method Details
#execute ⇒ Object
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 52 53 54 55 |
# File 'lib/takoyaki/commands/activities.rb', line 16 def execute events = [] page = 0 res = client.user_events(user, per_page: 100, page: page) loop do res.each do |event| if from <= event.created_at && event.created_at < to events << event end end break if res.last.created_at < from page += 1 res = client.user_events(user, per_page: 100, page: page) end repo_events = Hash.new { |h, k| h[k] = {} } events.each do |event| next unless repositories.include?(event.repo&.name) case event.type when "IssueCommentEvent", "IssuesEvent" repo_events[event.repo.name][event.payload.issue.number] = event when "PullRequestReviewCommentEvent", "PullRequestEvent" repo_events[event.repo.name][event.payload.pull_request.number] = event when "CreateEvent", "DeleteEvent", "PushEvent" else binding.pry end end repo_events.each do |repo, events| puts "### #{repo}" events.sort { |a, b| a[0] <=> b[0] }.each do |number, event| case event.type when /^Issue/ puts "- [##{number} #{event.payload.issue.title}](#{event.payload.issue.html_url})" when /^PullRequest/ puts "- [##{number} #{event.payload.pull_request.title}](#{event.payload.pull_request.html_url})" end end puts end end |