Commit 64bf46af authored by Rémy Coutable's avatar Rémy Coutable

Add labels to seeded issues and merge requests

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent f859b0e1
...@@ -60,7 +60,7 @@ Sidekiq::Testing.inline! do ...@@ -60,7 +60,7 @@ Sidekiq::Testing.inline! do
path: group_path path: group_path
) )
group.description = FFaker::Lorem.sentence group.description = FFaker::Lorem.sentence
group.save group.save!
group.add_owner(User.first) group.add_owner(User.first)
end end
......
# 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
...@@ -3,13 +3,17 @@ require './spec/support/sidekiq' ...@@ -3,13 +3,17 @@ require './spec/support/sidekiq'
Gitlab::Seeder.quiet do Gitlab::Seeder.quiet do
Project.all.each do |project| Project.all.each do |project|
10.times do 10.times do
label_ids = project.labels.pluck(:id).sample(3)
label_ids += project.group.labels.sample(3) if project.group
issue_params = { issue_params = {
title: FFaker::Lorem.sentence(6), title: FFaker::Lorem.sentence(6),
description: FFaker::Lorem.sentence, description: FFaker::Lorem.sentence,
state: ['opened', 'closed'].sample, state: ['opened', 'closed'].sample,
milestone: project.milestones.sample, milestone: project.milestones.sample,
assignees: [project.team.users.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 Issues::CreateService.new(project, project.team.users.sample, issue_params).execute
......
...@@ -12,13 +12,17 @@ Gitlab::Seeder.quiet do ...@@ -12,13 +12,17 @@ Gitlab::Seeder.quiet do
source_branch = branches.pop source_branch = branches.pop
target_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 = { params = {
source_branch: source_branch, source_branch: source_branch,
target_branch: target_branch, target_branch: target_branch,
title: FFaker::Lorem.sentence(6), title: FFaker::Lorem.sentence(6),
description: FFaker::Lorem.sentences(3).join(" "), description: FFaker::Lorem.sentences(3).join(" "),
milestone: project.milestones.sample, 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 # Only create MRs with users that are allowed to create MRs
......
# 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
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