Class: Gitlab::ContributionsCalendar
- Inherits:
-
Object
- Object
- Gitlab::ContributionsCalendar
- Defined in:
- lib/gitlab/contributions_calendar.rb
Instance Attribute Summary collapse
-
#contributor ⇒ Object
readonly
Returns the value of attribute contributor.
-
#current_user ⇒ Object
readonly
Returns the value of attribute current_user.
-
#projects ⇒ Object
readonly
Returns the value of attribute projects.
Instance Method Summary collapse
-
#activity_dates ⇒ Object
rubocop: disable CodeReuse/ActiveRecord.
-
#events_by_date(date) ⇒ Object
rubocop: disable CodeReuse/ActiveRecord.
-
#initialize(contributor, current_user = nil) ⇒ ContributionsCalendar
constructor
A new instance of ContributionsCalendar.
- #starting_month ⇒ Object
-
#starting_year ⇒ Object
rubocop: enable CodeReuse/ActiveRecord.
Constructor Details
#initialize(contributor, current_user = nil) ⇒ ContributionsCalendar
Returns a new instance of ContributionsCalendar.
9 10 11 12 13 14 15 16 17 |
# File 'lib/gitlab/contributions_calendar.rb', line 9 def initialize(contributor, current_user = nil) @contributor = contributor @current_user = current_user @projects = if @contributor.include_private_contributions? ContributedProjectsFinder.new(@contributor).execute(@contributor) else ContributedProjectsFinder.new(contributor).execute(current_user) end end |
Instance Attribute Details
#contributor ⇒ Object (readonly)
Returns the value of attribute contributor
5 6 7 |
# File 'lib/gitlab/contributions_calendar.rb', line 5 def contributor @contributor end |
#current_user ⇒ Object (readonly)
Returns the value of attribute current_user
6 7 8 |
# File 'lib/gitlab/contributions_calendar.rb', line 6 def current_user @current_user end |
#projects ⇒ Object (readonly)
Returns the value of attribute projects
7 8 9 |
# File 'lib/gitlab/contributions_calendar.rb', line 7 def projects @projects end |
Instance Method Details
#activity_dates ⇒ Object
rubocop: disable CodeReuse/ActiveRecord
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gitlab/contributions_calendar.rb', line 20 def activity_dates return @activity_dates if @activity_dates.present? # Can't use Event.contributions here because we need to check 3 different # project_features for the (currently) 3 different contribution types date_from = 1.year.ago repo_events = event_counts(date_from, :repository) .having(action: :pushed) issue_events = event_counts(date_from, :issues) .having(action: [:created, :closed], target_type: "Issue") mr_events = event_counts(date_from, :merge_requests) .having(action: [:merged, :created, :closed], target_type: "MergeRequest") note_events = event_counts(date_from, :merge_requests) .having(action: :commented) events = Event .from_union([repo_events, issue_events, mr_events, note_events]) .map(&:attributes) @activity_dates = events.each_with_object(Hash.new {|h, k| h[k] = 0 }) do |event, activities| activities[event["date"]] += event["total_amount"] end end |
#events_by_date(date) ⇒ Object
rubocop: disable CodeReuse/ActiveRecord
46 47 48 49 50 51 52 53 |
# File 'lib/gitlab/contributions_calendar.rb', line 46 def events_by_date(date) return Event.none unless can_read_cross_project? Event.contributions.where(author_id: contributor.id) .where(created_at: date.beginning_of_day..date.end_of_day) .where(project_id: projects) .with_associations end |
#starting_month ⇒ Object
60 61 62 |
# File 'lib/gitlab/contributions_calendar.rb', line 60 def starting_month Date.current.month end |
#starting_year ⇒ Object
rubocop: enable CodeReuse/ActiveRecord
56 57 58 |
# File 'lib/gitlab/contributions_calendar.rb', line 56 def starting_year 1.year.ago.year end |