diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/concerns/taskable.rb | 2 | ||||
-rw-r--r-- | app/models/event.rb | 6 | ||||
-rw-r--r-- | app/models/merge_request.rb | 9 | ||||
-rw-r--r-- | app/models/note.rb | 1 | ||||
-rw-r--r-- | app/models/project_contributions.rb | 32 | ||||
-rw-r--r-- | app/models/project_services/emails_on_push_service.rb | 10 | ||||
-rw-r--r-- | app/models/repository.rb | 35 | ||||
-rw-r--r-- | app/models/user.rb | 8 |
8 files changed, 28 insertions, 75 deletions
diff --git a/app/models/concerns/taskable.rb b/app/models/concerns/taskable.rb index 410e8dc820b..bbb3b301a9f 100644 --- a/app/models/concerns/taskable.rb +++ b/app/models/concerns/taskable.rb @@ -5,7 +5,7 @@ # Used by MergeRequest and Issue module Taskable TASK_PATTERN_MD = /^(?<bullet> *[*-] *)\[(?<checked>[ xX])\]/.freeze - TASK_PATTERN_HTML = /^<li>\[(?<checked>[ xX])\]/.freeze + TASK_PATTERN_HTML = /^<li>(?<p_tag>\s*<p>)?\[(?<checked>[ xX])\]/.freeze # Change the state of a task list item for this Taskable. Edit the object's # description by finding the nth task item and changing its checkbox diff --git a/app/models/event.rb b/app/models/event.rb index 2103a48a71b..57f6d5cd4e0 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -55,6 +55,12 @@ class Event < ActiveRecord::Base order('id DESC').limit(100). update_all(updated_at: Time.now) end + + def contributions + where("action = ? OR (target_type in (?) AND action in (?))", + Event::PUSHED, ["MergeRequest", "Issue"], + [Event::CREATED, Event::CLOSED, Event::MERGED]) + end end def proper? diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 798306f6dcc..5634f9a686e 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -105,6 +105,15 @@ class MergeRequest < ActiveRecord::Base state :unchecked state :can_be_merged state :cannot_be_merged + + around_transition do |merge_request, transition, block| + merge_request.record_timestamps = false + begin + block.call + ensure + merge_request.record_timestamps = true + end + end end validates :source_project, presence: true, unless: :allow_broken diff --git a/app/models/note.rb b/app/models/note.rb index 27b583a869a..e86160e7cd9 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -48,6 +48,7 @@ class Note < ActiveRecord::Base scope :inline, ->{ where("line_code IS NOT NULL") } scope :not_inline, ->{ where(line_code: [nil, '']) } scope :system, ->{ where(system: true) } + scope :user, ->{ where(system: false) } scope :common, ->{ where(noteable_type: ["", nil]) } scope :fresh, ->{ order(created_at: :asc, id: :asc) } scope :inc_author_project, ->{ includes(:project, :author) } diff --git a/app/models/project_contributions.rb b/app/models/project_contributions.rb deleted file mode 100644 index bfe9928b158..00000000000 --- a/app/models/project_contributions.rb +++ /dev/null @@ -1,32 +0,0 @@ -class ProjectContributions - attr_reader :project, :user - - def initialize(project, user) - @project, @user = project, user - end - - def commits_log - repository = project.repository - - if !repository.exists? || repository.empty? - return {} - end - - Rails.cache.fetch(cache_key) do - repository.commits_per_day_for_user(user) - end - end - - def user_commits_on_date(date) - repository = @project.repository - - if !repository.exists? || repository.empty? - return [] - end - commits = repository.commits_by_user_on_date_log(@user, date) - end - - def cache_key - "#{Date.today.to_s}-commits-log-#{project.id}-#{user.email}" - end -end diff --git a/app/models/project_services/emails_on_push_service.rb b/app/models/project_services/emails_on_push_service.rb index acb5e7f1af5..6f6e5950aab 100644 --- a/app/models/project_services/emails_on_push_service.rb +++ b/app/models/project_services/emails_on_push_service.rb @@ -36,13 +36,19 @@ class EmailsOnPushService < Service end def supported_events - %w(push) + %w(push tag_push) end def execute(push_data) return unless supported_events.include?(push_data[:object_kind]) - EmailsOnPushWorker.perform_async(project_id, recipients, push_data, send_from_committer_email?, disable_diffs?) + EmailsOnPushWorker.perform_async( + project_id, + recipients, + push_data, + send_from_committer_email: send_from_committer_email?, + disable_diffs: disable_diffs? + ) end def send_from_committer_email? diff --git a/app/models/repository.rb b/app/models/repository.rb index 082ad7a0c6a..77765cae1a0 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -149,41 +149,6 @@ class Repository end end - def timestamps_by_user_log(user) - author_emails = '(' + user.all_emails.map{ |e| Regexp.escape(e) }.join('|') + ')' - args = %W(git log -E --author=#{author_emails} --since=#{(Date.today - 1.year).to_s} --branches --pretty=format:%cd --date=short) - dates = Gitlab::Popen.popen(args, path_to_repo).first.split("\n") - - if dates.present? - dates - else - [] - end - end - - def commits_by_user_on_date_log(user, date) - # format the date string for git - start_date = date.strftime("%Y-%m-%d 00:00:00") - end_date = date.strftime("%Y-%m-%d 23:59:59") - - author_emails = '(' + user.all_emails.map{ |e| Regexp.escape(e) }.join('|') + ')' - args = %W(git log -E --author=#{author_emails} --after=#{start_date.to_s} --until=#{end_date.to_s} --branches --pretty=format:%h) - commits = Gitlab::Popen.popen(args, path_to_repo).first.split("\n") - - commits.map! do |commit_id| - commit(commit_id) - end - end - - def commits_per_day_for_user(user) - timestamps_by_user_log(user). - group_by { |commit_date| commit_date }. - inject({}) do |hash, (timestamp_date, commits)| - hash[timestamp_date] = commits.count - hash - end - end - def lookup_cache @lookup_cache ||= {} end diff --git a/app/models/user.rb b/app/models/user.rb index ba325132df8..979150b4d68 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -110,6 +110,7 @@ class User < ActiveRecord::Base has_many :notes, dependent: :destroy, foreign_key: :author_id has_many :merge_requests, dependent: :destroy, foreign_key: :author_id has_many :events, dependent: :destroy, foreign_key: :author_id, class_name: "Event" + has_many :subscriptions, dependent: :destroy has_many :recent_events, -> { order "id DESC" }, foreign_key: :author_id, class_name: "Event" has_many :assigned_issues, dependent: :destroy, foreign_key: :assignee_id, class_name: "Issue" has_many :assigned_merge_requests, dependent: :destroy, foreign_key: :assignee_id, class_name: "MergeRequest" @@ -603,13 +604,10 @@ class User < ActiveRecord::Base end def contributed_projects_ids - Event.where(author_id: self). + Event.contributions.where(author_id: self). where("created_at > ?", Time.now - 1.year). - where("action = :pushed OR (target_type = 'MergeRequest' AND action = :created)", - pushed: Event::PUSHED, created: Event::CREATED). reorder(project_id: :desc). select(:project_id). - uniq - .map(&:project_id) + uniq.map(&:project_id) end end |