diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-20 14:18:08 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-20 14:18:08 +0300 |
commit | 5afcbe03ead9ada87621888a31a62652b10a7e4f (patch) | |
tree | 9918b67a0d0f0bafa6542e839a8be37adf73102d /lib/quality | |
parent | c97c0201564848c1f53226fe19d71fdcc472f7d0 (diff) |
Add latest changes from gitlab-org/gitlab@16-4-stable-eev16.4.0-rc42
Diffstat (limited to 'lib/quality')
-rw-r--r-- | lib/quality/seeders/issues.rb | 59 |
1 files changed, 53 insertions, 6 deletions
diff --git a/lib/quality/seeders/issues.rb b/lib/quality/seeders/issues.rb index fb3d78bc8d2..813ff0bf097 100644 --- a/lib/quality/seeders/issues.rb +++ b/lib/quality/seeders/issues.rb @@ -5,7 +5,7 @@ module Quality module Seeders class Issues DEFAULT_BACKFILL_WEEKS = 52 - DEFAULT_AVERAGE_ISSUES_PER_WEEK = 10 + DEFAULT_AVERAGE_ISSUES_PER_WEEK = 20 attr_reader :project, :user @@ -14,23 +14,27 @@ module Quality end def seed(backfill_weeks: DEFAULT_BACKFILL_WEEKS, average_issues_per_week: DEFAULT_AVERAGE_ISSUES_PER_WEEK) + create_milestones! + create_team_members! + created_at = backfill_weeks.to_i.weeks.ago team = project.team.users created_issues_count = 0 loop do - rand(average_issues_per_week * 2).times do + rand(1..average_issues_per_week).times do params = { title: FFaker::Lorem.sentence(6), description: FFaker::Lorem.sentence, created_at: created_at + rand(6).days, state: %w[opened closed].sample, - milestone: project.milestones.sample, - assignee_ids: Array(team.pluck(:id).sample(3)), + milestone_id: project.milestones.sample&.id, + assignee_ids: Array(team.pluck(:id).sample(rand(3))), + due_date: rand(10).days.from_now, labels: labels.join(',') - } - params[:closed_at] = params[:created_at] + rand(35).days if params[:state] == 'closed' + }.merge(additional_params) + params[:closed_at] = params[:created_at] + rand(35).days if params[:state] == 'closed' create_result = ::Issues::CreateService.new(container: project, current_user: team.sample, params: params, perform_spam_check: false).execute_without_rate_limiting if create_result.success? @@ -49,6 +53,49 @@ module Quality private + # Overriden on Quality::Seeders::Insights::Issues + def additional_params + {} + end + + def create_team_members! + 3.times do |i| + user = FactoryBot.create( + :user, + name: "I User#{i}", + username: "i-user-#{i}-#{suffix}", + email: "i-user-#{i}@#{suffix}.com" + ) + + # need owner access to allow changing Issue#created_at + project.add_owner(user) + end + + Sidekiq::Worker.skipping_transaction_check do + AuthorizedProjectUpdate::ProjectRecalculateService.new(project).execute + end + + # Refind object toreload ProjectTeam association which is memoized at Project model + @project = Project.find(project.id) + end + + def create_milestones! + 3.times do |i| + params = { + project: project, + title: "Sprint #{i + suffix}", + description: FFaker::Lorem.sentence, + state: [:active, :closed].sample + } + + FactoryBot.create(:milestone, **params) + end + end + + def suffix + @suffix ||= Time.now.to_i + end + def labels @labels_pool ||= project.labels.limit(rand(3)).pluck(:title).tap do |labels_array| labels_array.concat(project.group.labels.limit(rand(3)).pluck(:title)) if project.group |