Class: Gitlab::ContributionsCalendar

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/contributions_calendar.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(projects, user) ⇒ ContributionsCalendar

Returns a new instance of ContributionsCalendar


5
6
7
8
# File 'lib/gitlab/contributions_calendar.rb', line 5

def initialize(projects, user)
  @projects = projects
  @user = user
end

Instance Attribute Details

#projectsObject (readonly)

Returns the value of attribute projects


3
4
5
# File 'lib/gitlab/contributions_calendar.rb', line 3

def projects
  @projects
end

#timestampsObject (readonly)

Returns the value of attribute timestamps


3
4
5
# File 'lib/gitlab/contributions_calendar.rb', line 3

def timestamps
  @timestamps
end

#userObject (readonly)

Returns the value of attribute user


3
4
5
# File 'lib/gitlab/contributions_calendar.rb', line 3

def user
  @user
end

Instance Method Details

#events_by_date(date) ⇒ Object


37
38
39
40
41
42
43
44
45
# File 'lib/gitlab/contributions_calendar.rb', line 37

def events_by_date(date)
  events = Event.contributions.where(author_id: user.id).
    where("created_at > ? AND created_at < ?", date.beginning_of_day, date.end_of_day).
    where(project_id: projects)

  events.select do |event|
    event.push? || event.issue? || event.merge_request?
  end
end

#starting_monthObject


51
52
53
# File 'lib/gitlab/contributions_calendar.rb', line 51

def starting_month
  Date.today.month
end

#starting_yearObject


47
48
49
# File 'lib/gitlab/contributions_calendar.rb', line 47

def starting_year
  1.year.ago.year
end