diff options
author | Rémy Coutable <remy@rymai.me> | 2019-03-11 16:16:58 +0100 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2019-03-12 08:40:15 +0100 |
commit | 64bf46af38190bf24569add6095a9a8bbced0a68 (patch) | |
tree | 8eb7a545e5625dea312b9a1f538106ba1c8771ec /db | |
parent | f859b0e1e7f257a962866c98eca430c1338b7dba (diff) | |
download | gitlab-ce-64bf46af38190bf24569add6095a9a8bbced0a68.tar.gz |
Add labels to seeded issues and merge requests
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'db')
-rw-r--r-- | db/fixtures/development/02_settings.rb (renamed from db/fixtures/development/03_settings.rb) | 0 | ||||
-rw-r--r-- | db/fixtures/development/03_project.rb (renamed from db/fixtures/development/04_project.rb) | 2 | ||||
-rw-r--r-- | db/fixtures/development/04_labels.rb | 49 | ||||
-rw-r--r-- | db/fixtures/development/09_issues.rb | 6 | ||||
-rw-r--r-- | db/fixtures/development/10_merge_requests.rb | 6 | ||||
-rw-r--r-- | db/fixtures/development/22_labeled_issues_seed.rb | 103 |
6 files changed, 60 insertions, 106 deletions
diff --git a/db/fixtures/development/03_settings.rb b/db/fixtures/development/02_settings.rb index 3a4a5d436bf..3a4a5d436bf 100644 --- a/db/fixtures/development/03_settings.rb +++ b/db/fixtures/development/02_settings.rb diff --git a/db/fixtures/development/04_project.rb b/db/fixtures/development/03_project.rb index 9a5f7cf8175..46018cf68aa 100644 --- a/db/fixtures/development/04_project.rb +++ b/db/fixtures/development/03_project.rb @@ -60,7 +60,7 @@ Sidekiq::Testing.inline! do path: group_path ) group.description = FFaker::Lorem.sentence - group.save + group.save! group.add_owner(User.first) end diff --git a/db/fixtures/development/04_labels.rb b/db/fixtures/development/04_labels.rb new file mode 100644 index 00000000000..b9ae4098d76 --- /dev/null +++ b/db/fixtures/development/04_labels.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +require 'digest/md5' + +class Gitlab::Seeder::GroupLabels + def initialize(group, label_per_group: 10) + @group = group + @label_per_group = label_per_group + end + + def seed! + @label_per_group.times do + label_title = FFaker::Product.brand + Labels::CreateService + .new(title: label_title, color: "##{Digest::MD5.hexdigest(label_title)[0..5]}") + .execute(group: @group) + print '.' + end + end +end + +class Gitlab::Seeder::ProjectLabels + def initialize(project, label_per_project: 5) + @project = project + @label_per_project = label_per_project + end + + def seed! + @label_per_project.times do + label_title = FFaker::Vehicle.model + Labels::CreateService + .new(title: label_title, color: "##{Digest::MD5.hexdigest(label_title)[0..5]}") + .execute(project: @project) + print '.' + end + end +end + +Gitlab::Seeder.quiet do + puts "\nGenerating group labels" + Group.all.find_each do |group| + Gitlab::Seeder::GroupLabels.new(group).seed! + end + + puts "\nGenerating project labels" + Project.all.find_each do |project| + Gitlab::Seeder::ProjectLabels.new(project).seed! + end +end diff --git a/db/fixtures/development/09_issues.rb b/db/fixtures/development/09_issues.rb index 16243b72f9a..926401d8b9e 100644 --- a/db/fixtures/development/09_issues.rb +++ b/db/fixtures/development/09_issues.rb @@ -3,13 +3,17 @@ require './spec/support/sidekiq' Gitlab::Seeder.quiet do Project.all.each do |project| 10.times do + label_ids = project.labels.pluck(:id).sample(3) + label_ids += project.group.labels.sample(3) if project.group + issue_params = { title: FFaker::Lorem.sentence(6), description: FFaker::Lorem.sentence, state: ['opened', 'closed'].sample, milestone: project.milestones.sample, assignees: [project.team.users.sample], - created_at: rand(12).months.ago + created_at: rand(12).months.ago, + label_ids: label_ids } Issues::CreateService.new(project, project.team.users.sample, issue_params).execute diff --git a/db/fixtures/development/10_merge_requests.rb b/db/fixtures/development/10_merge_requests.rb index 2051bcff8f0..1952f84ed62 100644 --- a/db/fixtures/development/10_merge_requests.rb +++ b/db/fixtures/development/10_merge_requests.rb @@ -12,13 +12,17 @@ Gitlab::Seeder.quiet do source_branch = branches.pop target_branch = branches.pop + label_ids = project.labels.pluck(:id).sample(3) + label_ids += project.group.labels.sample(3) if project.group + params = { source_branch: source_branch, target_branch: target_branch, title: FFaker::Lorem.sentence(6), description: FFaker::Lorem.sentences(3).join(" "), milestone: project.milestones.sample, - assignee: project.team.users.sample + assignee: project.team.users.sample, + label_ids: label_ids } # Only create MRs with users that are allowed to create MRs diff --git a/db/fixtures/development/22_labeled_issues_seed.rb b/db/fixtures/development/22_labeled_issues_seed.rb deleted file mode 100644 index 3730e9c7958..00000000000 --- a/db/fixtures/development/22_labeled_issues_seed.rb +++ /dev/null @@ -1,103 +0,0 @@ -# Creates a project with labeled issues for an user. -# Run this single seed file using: rake db:seed_fu FILTER=labeled USER_ID=74. -# If an USER_ID is not provided it will use the last created user. -require './spec/support/sidekiq' - -class Gitlab::Seeder::LabeledIssues - include ::Gitlab::Utils - - def initialize(user) - @user = user - end - - def seed! - Sidekiq::Testing.inline! do - group = create_group - - create_projects(group) - create_labels(group) - create_issues(group) - end - - print '.' - end - - private - - def create_group - group_name = "group_of_#{@user.username}_#{SecureRandom.hex(4)}" - - group_params = { - name: group_name, - path: group_name, - description: FFaker::Lorem.sentence - } - - Groups::CreateService.new(@user, group_params).execute - end - - def create_projects(group) - 5.times do - project_name = "project_#{SecureRandom.hex(6)}" - - params = { - namespace_id: group.id, - name: project_name, - description: FFaker::Lorem.sentence, - visibility_level: Gitlab::VisibilityLevel.values.sample - } - - Projects::CreateService.new(@user, params).execute - end - end - - def create_labels(group) - group.projects.each do |project| - 5.times do - label_title = FFaker::Vehicle.model - Labels::CreateService.new(title: label_title, color: "#69D100").execute(project: project) - end - end - - 10.times do - label_title = FFaker::Product.brand - Labels::CreateService.new(title: label_title).execute(group: group) - end - end - - def create_issues(group) - # Get only group labels - group_labels = - LabelsFinder.new(@user, group_id: group.id).execute.where.not(group_id: nil) - - group.projects.each do |project| - label_ids = project.labels.pluck(:id).sample(5) - label_ids.push(*group.labels.sample(4)) - - 20.times do - issue_params = { - title: FFaker::Lorem.sentence(6), - description: FFaker::Lorem.sentence, - state: 'opened', - label_ids: label_ids - - } - - Issues::CreateService.new(project, @user, issue_params).execute if project.project_feature.present? - end - end - end -end - -Gitlab::Seeder.quiet do - user_id = ENV['USER_ID'] - - user = - if user_id.present? - User.find(user_id) - else - User.last - end - - Gitlab::Seeder::LabeledIssues.new(user).seed! -end |