diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-24 12:09:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-24 12:09:47 +0300 |
commit | b0d6a7fbff3f97a4b2b56b672902a21e0fc29195 (patch) | |
tree | 01ea5944b79765c1dd7dae3823e2072a8bc5482b /db/fixtures | |
parent | e3dc4fc8f5df44ccd33739908bd4df2494cc27cc (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db/fixtures')
-rw-r--r-- | db/fixtures/development/36_achievements.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/db/fixtures/development/36_achievements.rb b/db/fixtures/development/36_achievements.rb new file mode 100644 index 00000000000..bde854f34b3 --- /dev/null +++ b/db/fixtures/development/36_achievements.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +class Gitlab::Seeder::Achievements + attr_reader :group, :user_ids, :maintainer_ids + + def initialize(group, user_ids) + @group = group + @maintainer_ids = group.members.maintainers.pluck(:user_id) + @user_ids = user_ids + end + + def seed! + achievement_ids = [] + + ['revoked', 'first mr', 'hero', 'legend'].each do |achievement_name| + achievement_ids << ::Achievements::Achievement.create!( + namespace_id: group.id, + name: achievement_name + ).id + + print '.' + end + + user_ids.each_with_index do |user_id, user_index| + (user_index + 1).times do |achievement_index| + ::Achievements::UserAchievement.create!( + user_id: user_id, + achievement_id: achievement_ids[achievement_index], + awarded_by_user_id: maintainer_ids.sample, + revoked_by_user_id: achievement_index == 0 ? maintainer_ids.sample : nil, + revoked_at: achievement_index == 0 ? DateTime.current : nil + ) + + print '.' + end + end + end +end + +Gitlab::Seeder.quiet do + puts "\nGenerating ahievements" + + group = Group.first + users = User.last(4).pluck(:id) + Gitlab::Seeder::Achievements.new(group, users).seed! +rescue => e + warn "\nError seeding achievements: #{e}" +end |