Commit 1f3a35f7 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'ce-to-ee-2018-06-04' into 'master'

CE upstream - 2018-06-04 14:04 UTC

Closes #3691

See merge request gitlab-org/gitlab-ee!5962
parents cf43b255 7d0145eb
......@@ -54,7 +54,7 @@ export default {
placement: 'top',
content: sprintf(
__(`
The character highligher helps you keep the subject line to %{titleLength} characters
The character highlighter helps you keep the subject line to %{titleLength} characters
and wrap the body at %{bodyLength} so they are readable in git.
`),
{ titleLength: MAX_TITLE_LENGTH, bodyLength: MAX_BODY_LENGTH },
......
......@@ -21,7 +21,6 @@ module Ci
end
has_one :source_pipeline, class_name: Ci::Sources::Pipeline
has_many :sourced_pipelines, class_name: Ci::Sources::Pipeline, foreign_key: :source_pipeline_id
has_one :triggered_by_pipeline, through: :source_pipeline, source: :source_pipeline
......@@ -30,6 +29,10 @@ module Ci
has_many :auto_canceled_pipelines, class_name: 'Ci::Pipeline', foreign_key: 'auto_canceled_by_id'
has_many :auto_canceled_jobs, class_name: 'CommitStatus', foreign_key: 'auto_canceled_by_id'
has_internal_id :iid, scope: :project, presence: false, init: ->(s) do
s&.project&.pipelines&.maximum(:iid) || s&.project&.pipelines&.count
end
has_many :stages
has_many :statuses, class_name: 'CommitStatus', foreign_key: :commit_id, inverse_of: :pipeline
has_many :builds, foreign_key: :commit_id, inverse_of: :pipeline
......
---
title: Include username in output when testing SSH to GitLab
merge_request: 19358
author:
type: other
---
title: Rails5 fix arel from
merge_request: 19340
author: Jasper Maes
type: fixed
---
title: Fix N+1 with source_projects in merge requests API
merge_request:
author:
type: performance
......@@ -40,7 +40,7 @@ module API
merge_requests = MergeRequestsFinder.new(current_user, args).execute
.reorder(args[:order_by] => args[:sort])
merge_requests = paginate(merge_requests)
.preload(:target_project)
.preload(:source_project, :target_project)
return merge_requests if args[:view] == 'simple'
......
......@@ -143,8 +143,13 @@ module Gitlab
.order(arel_table[column_sym])
).as('row_id')
count = arel_table.from(arel_table.alias)
.project('COUNT(*)')
arel_from = if Gitlab.rails5?
arel_table.from.from(arel_table.alias)
else
arel_table.from(arel_table.alias)
end
count = arel_from.project('COUNT(*)')
.where(arel_table[partition_column].eq(arel_table.alias[partition_column]))
.as('ct')
......
......@@ -3,7 +3,12 @@ require 'spec_helper'
describe Gitlab::CycleAnalytics::UsageData do
describe '#to_json' do
before do
Timecop.freeze do
# Since git commits only have second precision, round up to the
# nearest second to ensure we have accurate median and standard
# deviation calculations.
current_time = Time.at(Time.now.to_i)
Timecop.freeze(current_time) do
user = create(:user, :admin)
projects = create_list(:project, 2, :repository)
......@@ -37,13 +42,7 @@ describe Gitlab::CycleAnalytics::UsageData do
expected_values.each_pair do |op, value|
expect(stage_values).to have_key(op)
if op == :missing
expect(stage_values[op]).to eq(value)
else
# delta is used because of git timings that Timecop does not stub
expect(stage_values[op].to_i).to be_within(5).of(value.to_i)
end
expect(stage_values[op]).to eq(value)
end
end
end
......@@ -58,8 +57,8 @@ describe Gitlab::CycleAnalytics::UsageData do
missing: 0
},
plan: {
average: 2,
sd: 2,
average: 1,
sd: 0,
missing: 0
},
code: {
......
......@@ -4,12 +4,12 @@ module CycleAnalyticsHelpers
create_commit("Commit for ##{issue.iid}", issue.project, user, branch_name)
end
def create_commit(message, project, user, branch_name, count: 1)
def create_commit(message, project, user, branch_name, count: 1, commit_time: nil, skip_push_handler: false)
repository = project.repository
oldrev = repository.commit(branch_name).sha
oldrev = repository.commit(branch_name)&.sha || Gitlab::Git::BLANK_SHA
if Timecop.frozen? && Gitlab::GitalyClient.feature_enabled?(:operation_user_commit_files)
mock_gitaly_multi_action_dates(repository.raw)
mock_gitaly_multi_action_dates(repository.raw, commit_time)
end
commit_shas = Array.new(count) do |index|
......@@ -19,6 +19,8 @@ module CycleAnalyticsHelpers
commit_sha
end
return if skip_push_handler
GitPushService.new(project,
user,
oldrev: oldrev,
......@@ -44,13 +46,11 @@ module CycleAnalyticsHelpers
project.repository.add_branch(user, source_branch, 'master')
end
sha = project.repository.create_file(
user,
generate(:branch),
'content',
message: commit_message,
branch_name: source_branch)
project.repository.commit(sha)
# Cycle analytic specs often test with frozen times, which causes metrics to be
# pinned to the current time. For example, in the plan stage, we assume that an issue
# milestone has been created before any code has been written. We add a second
# to ensure that the plan time is positive.
create_commit(commit_message, project, user, source_branch, commit_time: Time.now + 1.second, skip_push_handler: true)
opts = {
title: 'Awesome merge_request',
......@@ -116,9 +116,9 @@ module CycleAnalyticsHelpers
protected: false)
end
def mock_gitaly_multi_action_dates(raw_repository)
def mock_gitaly_multi_action_dates(raw_repository, commit_time)
allow(raw_repository).to receive(:multi_action).and_wrap_original do |m, *args|
new_date = Time.now
new_date = commit_time || Time.now
branch_update = m.call(*args)
if branch_update.newrev
......
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