Commit 7897d04f authored by Robert Speicher's avatar Robert Speicher

Update CycleAnalytics seed to account for multiple issue assignees

parent d41e66cb
...@@ -4,7 +4,7 @@ require './spec/support/test_env' ...@@ -4,7 +4,7 @@ require './spec/support/test_env'
class Gitlab::Seeder::CycleAnalytics class Gitlab::Seeder::CycleAnalytics
def initialize(project, perf: false) def initialize(project, perf: false)
@project = project @project = project
@user = User.order(:id).last @user = User.admins.first
@issue_count = perf ? 1000 : 5 @issue_count = perf ? 1000 : 5
stub_git_pre_receive! stub_git_pre_receive!
end end
...@@ -77,39 +77,41 @@ class Gitlab::Seeder::CycleAnalytics ...@@ -77,39 +77,41 @@ class Gitlab::Seeder::CycleAnalytics
end end
def seed! def seed!
Sidekiq::Testing.inline! do Sidekiq::Worker.skipping_transaction_check do
issues = create_issues Sidekiq::Testing.inline! do
puts '.' issues = create_issues
puts '.'
# Stage 1
Timecop.travel 5.days.from_now # Stage 1
add_milestones_and_list_labels(issues) Timecop.travel 5.days.from_now
print '.' add_milestones_and_list_labels(issues)
print '.'
# Stage 2
Timecop.travel 5.days.from_now # Stage 2
branches = mention_in_commits(issues) Timecop.travel 5.days.from_now
print '.' branches = mention_in_commits(issues)
print '.'
# Stage 3
Timecop.travel 5.days.from_now # Stage 3
merge_requests = create_merge_requests_closing_issues(issues, branches) Timecop.travel 5.days.from_now
print '.' merge_requests = create_merge_requests_closing_issues(issues, branches)
print '.'
# Stage 4
Timecop.travel 5.days.from_now # Stage 4
run_builds(merge_requests) Timecop.travel 5.days.from_now
print '.' run_builds(merge_requests)
print '.'
# Stage 5
Timecop.travel 5.days.from_now # Stage 5
merge_merge_requests(merge_requests) Timecop.travel 5.days.from_now
print '.' merge_merge_requests(merge_requests)
print '.'
# Stage 6 / 7
Timecop.travel 5.days.from_now # Stage 6 / 7
deploy_to_production(merge_requests) Timecop.travel 5.days.from_now
print '.' deploy_to_production(merge_requests)
print '.'
end
end end
print '.' print '.'
...@@ -123,7 +125,7 @@ class Gitlab::Seeder::CycleAnalytics ...@@ -123,7 +125,7 @@ class Gitlab::Seeder::CycleAnalytics
title: "Cycle Analytics: #{FFaker::Lorem.sentence(6)}", title: "Cycle Analytics: #{FFaker::Lorem.sentence(6)}",
description: FFaker::Lorem.sentence, description: FFaker::Lorem.sentence,
state: 'opened', state: 'opened',
assignee: @project.team.users.sample assignees: [@project.team.users.sample]
} }
Issues::CreateService.new(@project, @project.team.users.sample, issue_params).execute Issues::CreateService.new(@project, @project.team.users.sample, issue_params).execute
...@@ -155,7 +157,7 @@ class Gitlab::Seeder::CycleAnalytics ...@@ -155,7 +157,7 @@ class Gitlab::Seeder::CycleAnalytics
issue.project.repository.add_branch(@user, branch_name, 'master') issue.project.repository.add_branch(@user, branch_name, 'master')
commit_sha = issue.project.repository.create_file(@user, filename, "content", message: "Commit for ##{issue.iid}", branch_name: branch_name) commit_sha = issue.project.repository.create_file(@user, filename, "content", message: "Commit for #{issue.to_reference}", branch_name: branch_name)
issue.project.repository.commit(commit_sha) issue.project.repository.commit(commit_sha)
GitPushService.new(issue.project, GitPushService.new(issue.project,
...@@ -210,6 +212,8 @@ class Gitlab::Seeder::CycleAnalytics ...@@ -210,6 +212,8 @@ class Gitlab::Seeder::CycleAnalytics
def deploy_to_production(merge_requests) def deploy_to_production(merge_requests)
merge_requests.each do |merge_request| merge_requests.each do |merge_request|
next unless merge_request.head_pipeline
Timecop.travel 12.hours.from_now Timecop.travel 12.hours.from_now
job = merge_request.head_pipeline.builds.where.not(environment: nil).last job = merge_request.head_pipeline.builds.where.not(environment: nil).last
...@@ -223,7 +227,14 @@ Gitlab::Seeder.quiet do ...@@ -223,7 +227,14 @@ Gitlab::Seeder.quiet do
flag = 'SEED_CYCLE_ANALYTICS' flag = 'SEED_CYCLE_ANALYTICS'
if ENV[flag] if ENV[flag]
Project.all.each do |project| Project.find_each do |project|
# This seed naively assumes that every project has a repository, and every
# repository has a `master` branch, which may be the case for a pristine
# GDK seed, but is almost never true for a GDK that's actually had
# development performed on it.
next unless project.repository_exists?
next unless project.repository.commit('master')
seeder = Gitlab::Seeder::CycleAnalytics.new(project) seeder = Gitlab::Seeder::CycleAnalytics.new(project)
seeder.seed! seeder.seed!
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