Skip to content

Commit

Permalink
Add commits to user contribution graph
Browse files Browse the repository at this point in the history
The contributions accounted so far are only requests, reviews
and comments to packages/projects.

Source changes next to requests are contributions/activity too,
so take it into the user graph. This is missing past activities,
import script will be provided later.

Co-authored-by: Ana María Martínez Gómez <anamaria@martinezgomez.name>
  • Loading branch information
coolo and Ana06 committed May 23, 2019
1 parent 643a968 commit 7035d64
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/api/app/models/user.rb
Expand Up @@ -64,6 +64,7 @@ class User < ApplicationRecord
has_many :rss_feed_items, -> { order(created_at: :desc) }, class_name: 'Notification::RssFeedItem', as: :subscriber, dependent: :destroy

has_and_belongs_to_many :announcements
has_many :commit_activities

scope :all_without_nobody, -> { where('login != ?', NOBODY_LOGIN) }
scope :not_deleted, -> { where.not(state: 'deleted') }
Expand Down
6 changes: 5 additions & 1 deletion src/api/app/models/user/contributions.rb
Expand Up @@ -7,7 +7,7 @@ def initialize(user, first_day)
end

def activity_hash
merge_hashes([requests_created, comments, reviews_done])
merge_hashes([requests_created, comments, reviews_done, commits_done])
end

private
Expand All @@ -25,6 +25,10 @@ def reviews_done
Review.where(reviewer: user.login, state: [:accepted, :declined]).where('created_at > ?', first_day).group('date(created_at)').count
end

def commits_done
user.commit_activities.group(:date).where('date > ?', first_day).sum(:count)
end

def merge_hashes(hashes_array)
hashes_array.inject { |h1, h2| h1.merge(h2) { |_, value1, value2| value1 + value2 } }
end
Expand Down

0 comments on commit 7035d64

Please sign in to comment.