Commit 39f80884db394decdb4b4a21a30bc1ecb3203944
1 parent
6e73b208
Exists in
spb-stable
and in
3 other branches
Improve developer seeds
Return execution of observers in seeds. Mute email sending to letter opening in you browser. Added `rake dev` task to reset db and add seeds. Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
11 changed files
with
96 additions
and
86 deletions
Show diff stats
db/fixtures/development/01_admin.rb
db/fixtures/development/04_project.rb
1 | -project_urls = [ | |
2 | - 'https://github.com/documentcloud/underscore.git', | |
3 | - 'https://github.com/diaspora/diaspora.git', | |
4 | - 'https://github.com/diaspora/diaspora-project-site.git', | |
5 | - 'https://github.com/diaspora/diaspora-client.git', | |
6 | - 'https://github.com/brightbox/brightbox-cli.git', | |
7 | - 'https://github.com/brightbox/puppet.git', | |
8 | - 'https://github.com/gitlabhq/gitlabhq.git', | |
9 | - 'https://github.com/gitlabhq/gitlab-ci.git', | |
10 | - 'https://github.com/gitlabhq/gitlab-recipes.git', | |
11 | - 'https://github.com/gitlabhq/gitlab-shell.git', | |
12 | - 'https://github.com/gitlabhq/grack.git', | |
13 | - 'https://github.com/gitlabhq/testme.git', | |
14 | - 'https://github.com/twitter/flight.git', | |
15 | - 'https://github.com/twitter/typeahead.js.git', | |
16 | - 'https://github.com/h5bp/html5-boilerplate.git', | |
17 | - 'https://github.com/h5bp/mobile-boilerplate.git', | |
18 | -] | |
19 | - | |
20 | -project_urls.each_with_index do |url, i| | |
21 | - group_path, project_path = url.split('/')[-2..-1] | |
22 | - | |
23 | - group = Group.find_by(path: group_path) | |
24 | - | |
25 | - unless group | |
26 | - group = Group.new( | |
27 | - name: group_path.titleize, | |
28 | - path: group_path | |
29 | - ) | |
30 | - group.description = Faker::Lorem.sentence | |
31 | - group.save | |
32 | - | |
33 | - group.add_owner(User.first) | |
34 | - end | |
35 | - | |
36 | - project_path.gsub!(".git", "") | |
37 | - | |
38 | - params = { | |
39 | - import_url: url, | |
40 | - namespace_id: group.id, | |
41 | - name: project_path.titleize, | |
42 | - description: Faker::Lorem.sentence | |
43 | - } | |
44 | - | |
45 | - project = Projects::CreateService.new(User.first, params).execute | |
46 | - | |
47 | - if project.valid? | |
48 | - print '.' | |
49 | - else | |
50 | - puts project.errors.full_messages | |
51 | - print 'F' | |
1 | +Gitlab::Seeder.quiet do | |
2 | + project_urls = [ | |
3 | + 'https://github.com/documentcloud/underscore.git', | |
4 | + 'https://github.com/diaspora/diaspora.git', | |
5 | + 'https://github.com/diaspora/diaspora-project-site.git', | |
6 | + 'https://github.com/diaspora/diaspora-client.git', | |
7 | + 'https://github.com/brightbox/brightbox-cli.git', | |
8 | + 'https://github.com/brightbox/puppet.git', | |
9 | + 'https://github.com/gitlabhq/gitlabhq.git', | |
10 | + 'https://github.com/gitlabhq/gitlab-ci.git', | |
11 | + 'https://github.com/gitlabhq/gitlab-recipes.git', | |
12 | + 'https://github.com/gitlabhq/gitlab-shell.git', | |
13 | + 'https://github.com/gitlabhq/grack.git', | |
14 | + 'https://github.com/gitlabhq/testme.git', | |
15 | + 'https://github.com/twitter/flight.git', | |
16 | + 'https://github.com/twitter/typeahead.js.git', | |
17 | + 'https://github.com/h5bp/html5-boilerplate.git', | |
18 | + 'https://github.com/h5bp/mobile-boilerplate.git', | |
19 | + ] | |
20 | + | |
21 | + project_urls.each_with_index do |url, i| | |
22 | + group_path, project_path = url.split('/')[-2..-1] | |
23 | + | |
24 | + group = Group.find_by(path: group_path) | |
25 | + | |
26 | + unless group | |
27 | + group = Group.new( | |
28 | + name: group_path.titleize, | |
29 | + path: group_path | |
30 | + ) | |
31 | + group.description = Faker::Lorem.sentence | |
32 | + group.save | |
33 | + | |
34 | + group.add_owner(User.first) | |
35 | + end | |
36 | + | |
37 | + project_path.gsub!(".git", "") | |
38 | + | |
39 | + params = { | |
40 | + import_url: url, | |
41 | + namespace_id: group.id, | |
42 | + name: project_path.titleize, | |
43 | + description: Faker::Lorem.sentence | |
44 | + } | |
45 | + | |
46 | + project = Projects::CreateService.new(User.first, params).execute | |
47 | + | |
48 | + if project.valid? | |
49 | + print '.' | |
50 | + else | |
51 | + puts project.errors.full_messages | |
52 | + print 'F' | |
53 | + end | |
52 | 54 | end |
53 | 55 | end | ... | ... |
db/fixtures/development/05_users.rb
db/fixtures/development/06_teams.rb
db/fixtures/development/09_issues.rb
1 | -ActiveRecord::Base.observers.disable :all | |
2 | - | |
3 | 1 | Gitlab::Seeder.quiet do |
4 | 2 | (1..300).each do |i| |
5 | 3 | # Random Project |
... | ... | @@ -12,9 +10,7 @@ Gitlab::Seeder.quiet do |
12 | 10 | |
13 | 11 | user_id = user.id |
14 | 12 | |
15 | - begin | |
16 | - Thread.current[:current_user] = user | |
17 | - | |
13 | + Gitlab::Seeder.by_user(user) do | |
18 | 14 | Issue.seed(:id, [{ |
19 | 15 | id: i, |
20 | 16 | project_id: project.id, |
... | ... | @@ -25,8 +21,6 @@ Gitlab::Seeder.quiet do |
25 | 21 | title: Faker::Lorem.sentence(6), |
26 | 22 | description: Faker::Lorem.sentence |
27 | 23 | }]) |
28 | - ensure | |
29 | - Thread.current[:current_user] = nil | |
30 | 24 | end |
31 | 25 | print('.') |
32 | 26 | end | ... | ... |
db/fixtures/development/10_merge_requests.rb
1 | -ActiveRecord::Base.observers.disable :all | |
2 | - | |
3 | 1 | Gitlab::Seeder.quiet do |
4 | 2 | (1..100).each do |i| |
5 | 3 | # Random Project |
... | ... | @@ -17,9 +15,8 @@ Gitlab::Seeder.quiet do |
17 | 15 | next if branches.uniq.size < 2 |
18 | 16 | |
19 | 17 | user_id = user.id |
20 | - begin | |
21 | - Thread.current[:current_user] = user | |
22 | 18 | |
19 | + Gitlab::Seeder.by_user(user) do | |
23 | 20 | MergeRequest.seed(:id, [{ |
24 | 21 | id: i, |
25 | 22 | source_branch: branches.first, |
... | ... | @@ -31,8 +28,6 @@ Gitlab::Seeder.quiet do |
31 | 28 | milestone: project.milestones.sample, |
32 | 29 | title: Faker::Lorem.sentence(6) |
33 | 30 | }]) |
34 | - ensure | |
35 | - Thread.current[:current_user] = nil | |
36 | 31 | end |
37 | 32 | print('.') |
38 | 33 | end | ... | ... |
db/fixtures/development/11_keys.rb
db/fixtures/development/12_snippets.rb
db/fixtures/development/13_comments.rb
1 | -ActiveRecord::Base.observers.disable :all | |
1 | +Gitlab::Seeder.quiet do | |
2 | + Issue.all.limit(10).each_with_index do |issue, i| | |
3 | + 5.times do | |
4 | + user = issue.project.team.users.sample | |
2 | 5 | |
3 | -Issue.all.limit(10).each_with_index do |issue, i| | |
4 | - 5.times do | |
5 | - Note.seed(:id, [{ | |
6 | - project_id: issue.project.id, | |
7 | - author_id: issue.project.team.users.sample.id, | |
8 | - note: Faker::Lorem.sentence, | |
9 | - noteable_id: issue.id, | |
10 | - noteable_type: 'Issue' | |
11 | - }]) | |
6 | + Gitlab::Seeder.by_user(user) do | |
7 | + Note.seed(:id, [{ | |
8 | + project_id: issue.project.id, | |
9 | + author_id: user.id, | |
10 | + note: Faker::Lorem.sentence, | |
11 | + noteable_id: issue.id, | |
12 | + noteable_type: 'Issue' | |
13 | + }]) | |
14 | + | |
15 | + print '.' | |
16 | + end | |
17 | + end | |
12 | 18 | end |
13 | 19 | end | ... | ... |
lib/gitlab/seeder.rb
1 | 1 | module Gitlab |
2 | 2 | class Seeder |
3 | 3 | def self.quiet |
4 | + mute_mailer | |
4 | 5 | SeedFu.quiet = true |
5 | 6 | yield |
6 | 7 | SeedFu.quiet = false |
7 | 8 | puts "\nOK".green |
8 | 9 | end |
10 | + | |
11 | + def self.by_user(user) | |
12 | + begin | |
13 | + Thread.current[:current_user] = user | |
14 | + yield | |
15 | + ensure | |
16 | + Thread.current[:current_user] = nil | |
17 | + end | |
18 | + end | |
19 | + | |
20 | + def self.mute_mailer | |
21 | + code = <<-eos | |
22 | +def Notify.delay | |
23 | + self | |
24 | +end | |
25 | + eos | |
26 | + eval(code) | |
27 | + end | |
9 | 28 | end |
10 | 29 | end | ... | ... |
lib/tasks/dev.rake
1 | +task dev: ["dev:setup"] | |
2 | + | |
1 | 3 | namespace :dev do |
2 | 4 | desc "GITLAB | Setup developer environment (db, fixtures)" |
3 | 5 | task :setup => :environment do |
4 | 6 | ENV['force'] = 'yes' |
5 | - Rake::Task["db:setup"].invoke | |
6 | - Rake::Task["db:seed_fu"].invoke | |
7 | + Rake::Task["gitlab:setup"].invoke | |
7 | 8 | Rake::Task["gitlab:shell:setup"].invoke |
8 | 9 | end |
9 | 10 | end |
10 | - | ... | ... |