Commit 9edf06d9 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'backport-productivty-analytics-migrations' into 'master'

Backport productivity analytics migrations

See merge request gitlab-org/gitlab-ce!31298
parents 3c03db12 5b70ffcf
......@@ -194,10 +194,9 @@ module IssuableCollections
end
def collection_type
@collection_type ||= case finder_type.name
when 'IssuesFinder'
@collection_type ||= if finder_type <= IssuesFinder
'Issue'
when 'MergeRequestsFinder'
elsif finder_type <= MergeRequestsFinder
'MergeRequest'
end
end
......
......@@ -196,6 +196,12 @@ class MergeRequestDiff < ApplicationRecord
real_size.presence || raw_diffs.size
end
def lines_count
strong_memoize(:lines_count) do
diffs.diff_files.sum(&:line_count)
end
end
def raw_diffs(options = {})
if options[:ignore_whitespace_change]
@diffs_no_whitespace ||= compare.diffs(options)
......
# frozen_string_literal: true
class AddMrProductivityMetrics < ActiveRecord::Migration[5.1]
DOWNTIME = false
def change
add_column :merge_request_metrics, :first_comment_at, :datetime_with_timezone
add_column :merge_request_metrics, :first_commit_at, :datetime_with_timezone
add_column :merge_request_metrics, :last_commit_at, :datetime_with_timezone
add_column :merge_request_metrics, :diff_size, :integer
add_column :merge_request_metrics, :modified_paths_size, :integer
add_column :merge_request_metrics, :commits_count, :integer
end
end
......@@ -1979,6 +1979,12 @@ ActiveRecord::Schema.define(version: 2019_08_02_012622) do
t.integer "merged_by_id"
t.integer "latest_closed_by_id"
t.datetime_with_timezone "latest_closed_at"
t.datetime_with_timezone "first_comment_at"
t.datetime_with_timezone "first_commit_at"
t.datetime_with_timezone "last_commit_at"
t.integer "diff_size"
t.integer "modified_paths_size"
t.integer "commits_count"
t.index ["first_deployed_to_production_at"], name: "index_merge_request_metrics_on_first_deployed_to_production_at"
t.index ["latest_closed_at"], name: "index_merge_request_metrics_on_latest_closed_at", where: "(latest_closed_at IS NOT NULL)"
t.index ["latest_closed_by_id"], name: "index_merge_request_metrics_on_latest_closed_by_id"
......
......@@ -235,6 +235,12 @@ MergeRequest::Metrics:
- latest_build_started_at
- latest_build_finished_at
- first_deployed_to_production_at
- first_comment_at
- first_commit_at
- last_commit_at
- diff_size
- modified_paths_size
- commits_count
Ci::Pipeline:
- id
- project_id
......
......@@ -484,4 +484,12 @@ describe MergeRequestDiff do
end
end
end
describe '#lines_count' do
subject { diff_with_commits }
it 'returns sum of all changed lines count in diff files' do
expect(subject.lines_count).to eq 109
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment