class ScrumYo::Activity

Attributes

github_activity[R]
user[R]

Public Class Methods

new() click to toggle source
# File lib/scrum_yo/activity.rb, line 5
def initialize
  @user = ScrumYo::User.new
  @github = @user.github_client
  @github_activity = load_activities
end

Private Instance Methods

filter_activity(events) click to toggle source
# File lib/scrum_yo/activity.rb, line 29
def filter_activity(events)
  events.select! { |e| %w{PushEvent PullRequestEvent}.include? e.type }

  events.each do |event|
    if event.payload.commits
      event.payload.commits.select! { |commit| @user.emails.include? commit.author.email }
    end
  end

  events
end
load_activities(page = 1) click to toggle source
# File lib/scrum_yo/activity.rb, line 13
def load_activities(page = 1)
  activities = @github.user_events(@user.username, page: page)

  if older_than_one_day(activities.last)
    return filter_activity(activities)
  else
    # recursion alert! get events from next page
    activities.push(*load_activities(page + 1))
  end
end
older_than_one_day(event) click to toggle source
# File lib/scrum_yo/activity.rb, line 24
def older_than_one_day(event)
  # 3600 = seconds in an hour
  (DateTime.now.in_time_zone('UTC') - event.created_at) / 3600 > 24
end