From 38985390b061a0d1d0d91d5574f612b4710768b6 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sat, 9 Feb 2013 15:13:56 +0200 Subject: [PATCH] Refactored and fixed seeds to work with gitlab-shell --- db/fixtures/development/001_admin.rb | 11 ----------- db/fixtures/development/002_project.rb | 26 -------------------------- db/fixtures/development/003_users.rb | 15 --------------- db/fixtures/development/004_teams.rb | 29 ----------------------------- db/fixtures/development/005_milestones.rb | 13 ------------- db/fixtures/development/006_wall.rb | 21 --------------------- db/fixtures/development/007_issues.rb | 25 ------------------------- db/fixtures/development/008_merge_requests.rb | 26 -------------------------- db/fixtures/development/009_source_code.rb | 31 ------------------------------- db/fixtures/development/010_keys.rb | 14 -------------- db/fixtures/development/01_admin.rb | 11 +++++++++++ db/fixtures/development/02_source_code.rb | 29 +++++++++++++++++++++++++++++ db/fixtures/development/03_group.rb | 5 +++++ db/fixtures/development/04_project.rb | 20 ++++++++++++++++++++ db/fixtures/development/05_users.rb | 15 +++++++++++++++ db/fixtures/development/06_teams.rb | 22 ++++++++++++++++++++++ db/fixtures/development/07_milestones.rb | 13 +++++++++++++ db/fixtures/development/08_wall.rb | 21 +++++++++++++++++++++ db/fixtures/development/09_issues.rb | 25 +++++++++++++++++++++++++ db/fixtures/development/10_merge_requests.rb | 26 ++++++++++++++++++++++++++ db/fixtures/development/11_keys.rb | 14 ++++++++++++++ 21 files changed, 201 insertions(+), 211 deletions(-) delete mode 100644 db/fixtures/development/001_admin.rb delete mode 100644 db/fixtures/development/002_project.rb delete mode 100644 db/fixtures/development/003_users.rb delete mode 100644 db/fixtures/development/004_teams.rb delete mode 100644 db/fixtures/development/005_milestones.rb delete mode 100644 db/fixtures/development/006_wall.rb delete mode 100644 db/fixtures/development/007_issues.rb delete mode 100644 db/fixtures/development/008_merge_requests.rb delete mode 100644 db/fixtures/development/009_source_code.rb delete mode 100644 db/fixtures/development/010_keys.rb create mode 100644 db/fixtures/development/01_admin.rb create mode 100644 db/fixtures/development/02_source_code.rb create mode 100644 db/fixtures/development/03_group.rb create mode 100644 db/fixtures/development/04_project.rb create mode 100644 db/fixtures/development/05_users.rb create mode 100644 db/fixtures/development/06_teams.rb create mode 100644 db/fixtures/development/07_milestones.rb create mode 100644 db/fixtures/development/08_wall.rb create mode 100644 db/fixtures/development/09_issues.rb create mode 100644 db/fixtures/development/10_merge_requests.rb create mode 100644 db/fixtures/development/11_keys.rb diff --git a/db/fixtures/development/001_admin.rb b/db/fixtures/development/001_admin.rb deleted file mode 100644 index fbe41e4..0000000 --- a/db/fixtures/development/001_admin.rb +++ /dev/null @@ -1,11 +0,0 @@ -User.seed(:id, [ - { - id: 1, - name: "Administrator", - email: "admin@local.host", - username: 'root', - password: "5iveL!fe", - password_confirmation: "5iveL!fe", - admin: true, - } -]) diff --git a/db/fixtures/development/002_project.rb b/db/fixtures/development/002_project.rb deleted file mode 100644 index e50ab5d..0000000 --- a/db/fixtures/development/002_project.rb +++ /dev/null @@ -1,26 +0,0 @@ -Group.seed(:id, [ - { id: 99, name: "GitLab", path: 'gitlab', owner_id: 1 }, - { id: 100, name: "Brightbox", path: 'brightbox', owner_id: 1 }, - { id: 101, name: "KDE", path: 'kde', owner_id: 1 }, -]) - -Project.seed(:id, [ - - # Global - { id: 1, name: "Underscore.js", path: "underscore", creator_id: 1 }, - { id: 2, name: "Diaspora", path: "diaspora", creator_id: 1 }, - - # Brightbox - { id: 3, namespace_id: 100, name: "Brightbox CLI", path: "brightbox-cli", creator_id: 1 }, - { id: 4, namespace_id: 100, name: "Puppet", path: "puppet", creator_id: 1 }, - - # KDE - { id: 5, namespace_id: 101, name: "kdebase", path: "kdebase", creator_id: 1}, - { id: 6, namespace_id: 101, name: "kdelibs", path: "kdelibs", creator_id: 1}, - { id: 7, namespace_id: 101, name: "amarok", path: "amarok", creator_id: 1}, - - # GitLab - { id: 8, namespace_id: 99, name: "gitlabhq", path: "gitlabhq", creator_id: 1}, - { id: 9, namespace_id: 99, name: "gitlab-ci", path: "gitlab-ci", creator_id: 1}, - { id: 10, namespace_id: 99, name: "gitlab-recipes", path: "gitlab-recipes", creator_id: 1}, -]) diff --git a/db/fixtures/development/003_users.rb b/db/fixtures/development/003_users.rb deleted file mode 100644 index abcb025..0000000 --- a/db/fixtures/development/003_users.rb +++ /dev/null @@ -1,15 +0,0 @@ -Gitlab::Seeder.quiet do - (2..300).each do |i| - begin - User.seed(:id, [{ - id: i, - username: Faker::Internet.user_name, - name: Faker::Name.name, - email: Faker::Internet.email, - }]) - print '.' - rescue ActiveRecord::RecordNotSaved - print 'F' - end - end -end diff --git a/db/fixtures/development/004_teams.rb b/db/fixtures/development/004_teams.rb deleted file mode 100644 index 7a8f913..0000000 --- a/db/fixtures/development/004_teams.rb +++ /dev/null @@ -1,29 +0,0 @@ -UsersProject.skip_callback(:save, :after, :update_repository) - -Gitlab::Seeder.quiet do - - (1..300).each do |i| - # Random Project - project = Project.scoped.sample - - # Random user - user = User.not_in_project(project).sample - - next unless user - - UsersProject.seed(:id, [{ - id: i, - project_id: project.id, - user_id: user.id, - project_access: UsersProject.access_roles.values.sample - }]) - - print('.') - end -end - -UsersProject.set_callback(:save, :after, :update_repository) - -puts "\nRebuild gitolite\n".yellow -Project.all.each(&:update_repository) -puts "OK".green diff --git a/db/fixtures/development/005_milestones.rb b/db/fixtures/development/005_milestones.rb deleted file mode 100644 index a77f619..0000000 --- a/db/fixtures/development/005_milestones.rb +++ /dev/null @@ -1,13 +0,0 @@ -Milestone.seed(:id, [ - { :id => 1, :project_id => 1, :title => 'v' + Faker::Address.zip_code }, - { :id => 2, :project_id => 1, :title => 'v' + Faker::Address.zip_code }, - { :id => 3, :project_id => 1, :title => 'v' + Faker::Address.zip_code }, - { :id => 4, :project_id => 2, :title => 'v' + Faker::Address.zip_code }, - { :id => 5, :project_id => 2, :title => 'v' + Faker::Address.zip_code }, - - { :id => 6, :project_id => 2, :title => 'v' + Faker::Address.zip_code }, - { :id => 7, :project_id => 2, :title => 'v' + Faker::Address.zip_code }, - { :id => 8, :project_id => 3, :title => 'v' + Faker::Address.zip_code }, - { :id => 9, :project_id => 3, :title => 'v' + Faker::Address.zip_code }, - { :id => 11, :project_id => 3, :title => 'v' + Faker::Address.zip_code }, -]) diff --git a/db/fixtures/development/006_wall.rb b/db/fixtures/development/006_wall.rb deleted file mode 100644 index c4e304c..0000000 --- a/db/fixtures/development/006_wall.rb +++ /dev/null @@ -1,21 +0,0 @@ -Gitlab::Seeder.quiet do - (1..300).each do |i| - # Random Project - project = Project.all.sample - - # Random user - user = project.users.sample - - next unless user - - user_id = user.id - - Note.seed(:id, [{ - id: i, - project_id: project.id, - author_id: user_id, - note: Faker::Lorem.sentence(6) - }]) - print('.') - end -end diff --git a/db/fixtures/development/007_issues.rb b/db/fixtures/development/007_issues.rb deleted file mode 100644 index 8978db4..0000000 --- a/db/fixtures/development/007_issues.rb +++ /dev/null @@ -1,25 +0,0 @@ -Gitlab::Seeder.quiet do - (1..300).each do |i| - # Random Project - project = Project.all.sample - - # Random user - user = project.users.sample - - next unless user - - user_id = user.id - IssueObserver.current_user = user - - Issue.seed(:id, [{ - id: i, - project_id: project.id, - author_id: user_id, - assignee_id: user_id, - closed: [true, false].sample, - milestone: project.milestones.sample, - title: Faker::Lorem.sentence(6) - }]) - print('.') - end -end diff --git a/db/fixtures/development/008_merge_requests.rb b/db/fixtures/development/008_merge_requests.rb deleted file mode 100644 index 9904b4a..0000000 --- a/db/fixtures/development/008_merge_requests.rb +++ /dev/null @@ -1,26 +0,0 @@ -Gitlab::Seeder.quiet do - (1..300).each do |i| - # Random Project - project = Project.all.sample - - # Random user - user = project.users.sample - - next unless user - - user_id = user.id - MergeRequestObserver.current_user = user - MergeRequest.seed(:id, [{ - id: i, - source_branch: 'master', - target_branch: 'feature', - project_id: project.id, - author_id: user_id, - assignee_id: user_id, - closed: [true, false].sample, - milestone: project.milestones.sample, - title: Faker::Lorem.sentence(6) - }]) - print('.') - end -end diff --git a/db/fixtures/development/009_source_code.rb b/db/fixtures/development/009_source_code.rb deleted file mode 100644 index a64b905..0000000 --- a/db/fixtures/development/009_source_code.rb +++ /dev/null @@ -1,31 +0,0 @@ -root = Gitlab.config.gitolite.repos_path - -projects = [ - { path: 'underscore.git', git: 'https://github.com/documentcloud/underscore.git' }, - { path: 'diaspora.git', git: 'https://github.com/diaspora/diaspora.git' }, - { path: 'brightbox/brightbox-cli.git', git: 'https://github.com/brightbox/brightbox-cli.git' }, - { path: 'brightbox/puppet.git', git: 'https://github.com/brightbox/puppet.git' }, - { path: 'gitlab/gitlabhq.git', git: 'https://github.com/gitlabhq/gitlabhq.git' }, - { path: 'gitlab/gitlab-ci.git', git: 'https://github.com/gitlabhq/gitlab-ci.git' }, - { path: 'gitlab/gitlab-recipes.git', git: 'https://github.com/gitlabhq/gitlab-recipes.git' }, -] - -projects.each do |project| - project_path = File.join(root, project[:path]) - - next if File.exists?(project_path) - - cmds = [ - "cd #{root} && sudo -u git -H git clone --bare #{project[:git]} ./#{project[:path]}", - "sudo ln -s ./lib/hooks/post-receive #{project_path}/hooks/post-receive", - "sudo chown git:git -R #{project_path}", - "sudo chmod 770 -R #{project_path}", - ] - - cmds.each do |cmd| - puts cmd.yellow - `#{cmd}` - end -end - -puts "OK".green diff --git a/db/fixtures/development/010_keys.rb b/db/fixtures/development/010_keys.rb deleted file mode 100644 index 8e4724c..0000000 --- a/db/fixtures/development/010_keys.rb +++ /dev/null @@ -1,14 +0,0 @@ - -Gitlab::Seeder.quiet do - User.first(30).each_with_index do |user, i| - Key.seed(:id, [ - { - id: i, - title: "Sample key #{i}", - key: "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt#{i + 100}6k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=", - user_id: user.id, - } - ]) - puts "SSH KEY ##{i} added.".green - end -end diff --git a/db/fixtures/development/01_admin.rb b/db/fixtures/development/01_admin.rb new file mode 100644 index 0000000..fbe41e4 --- /dev/null +++ b/db/fixtures/development/01_admin.rb @@ -0,0 +1,11 @@ +User.seed(:id, [ + { + id: 1, + name: "Administrator", + email: "admin@local.host", + username: 'root', + password: "5iveL!fe", + password_confirmation: "5iveL!fe", + admin: true, + } +]) diff --git a/db/fixtures/development/02_source_code.rb b/db/fixtures/development/02_source_code.rb new file mode 100644 index 0000000..4a9e5d0 --- /dev/null +++ b/db/fixtures/development/02_source_code.rb @@ -0,0 +1,29 @@ +root = Gitlab.config.gitolite.repos_path + +projects = [ + { path: 'underscore.git', git: 'https://github.com/documentcloud/underscore.git' }, + { path: 'diaspora.git', git: 'https://github.com/diaspora/diaspora.git' }, + { path: 'brightbox/brightbox-cli.git', git: 'https://github.com/brightbox/brightbox-cli.git' }, + { path: 'brightbox/puppet.git', git: 'https://github.com/brightbox/puppet.git' }, + { path: 'gitlab/gitlabhq.git', git: 'https://github.com/gitlabhq/gitlabhq.git' }, + { path: 'gitlab/gitlab-ci.git', git: 'https://github.com/gitlabhq/gitlab-ci.git' }, + { path: 'gitlab/gitlab-recipes.git', git: 'https://github.com/gitlabhq/gitlab-recipes.git' }, +] + +projects.each do |project| + project_path = File.join(root, project[:path]) + + if File.exists?(project_path) + print '-' + next + end + + if system("/home/git/gitlab-shell/bin/gitlab-projects import-project #{project[:path]} #{project[:git]}") + print '.' + else + print 'F' + end +end + +puts "OK".green + diff --git a/db/fixtures/development/03_group.rb b/db/fixtures/development/03_group.rb new file mode 100644 index 0000000..01174a4 --- /dev/null +++ b/db/fixtures/development/03_group.rb @@ -0,0 +1,5 @@ +Group.seed(:id, [ + { id: 99, name: "GitLab", path: 'gitlab', owner_id: 1 }, + { id: 100, name: "Brightbox", path: 'brightbox', owner_id: 1 }, + { id: 101, name: "KDE", path: 'kde', owner_id: 1 }, +]) diff --git a/db/fixtures/development/04_project.rb b/db/fixtures/development/04_project.rb new file mode 100644 index 0000000..9904c48 --- /dev/null +++ b/db/fixtures/development/04_project.rb @@ -0,0 +1,20 @@ +Project.seed(:id, [ + + # Global + { id: 1, name: "Underscore.js", path: "underscore", creator_id: 1 }, + { id: 2, name: "Diaspora", path: "diaspora", creator_id: 1 }, + + # Brightbox + { id: 3, namespace_id: 100, name: "Brightbox CLI", path: "brightbox-cli", creator_id: 1 }, + { id: 4, namespace_id: 100, name: "Puppet", path: "puppet", creator_id: 1 }, + + # KDE + { id: 5, namespace_id: 101, name: "kdebase", path: "kdebase", creator_id: 1}, + { id: 6, namespace_id: 101, name: "kdelibs", path: "kdelibs", creator_id: 1}, + { id: 7, namespace_id: 101, name: "amarok", path: "amarok", creator_id: 1}, + + # GitLab + { id: 8, namespace_id: 99, name: "gitlabhq", path: "gitlabhq", creator_id: 1}, + { id: 9, namespace_id: 99, name: "gitlab-ci", path: "gitlab-ci", creator_id: 1}, + { id: 10, namespace_id: 99, name: "gitlab-recipes", path: "gitlab-recipes", creator_id: 1}, +]) diff --git a/db/fixtures/development/05_users.rb b/db/fixtures/development/05_users.rb new file mode 100644 index 0000000..abcb025 --- /dev/null +++ b/db/fixtures/development/05_users.rb @@ -0,0 +1,15 @@ +Gitlab::Seeder.quiet do + (2..300).each do |i| + begin + User.seed(:id, [{ + id: i, + username: Faker::Internet.user_name, + name: Faker::Name.name, + email: Faker::Internet.email, + }]) + print '.' + rescue ActiveRecord::RecordNotSaved + print 'F' + end + end +end diff --git a/db/fixtures/development/06_teams.rb b/db/fixtures/development/06_teams.rb new file mode 100644 index 0000000..9fbf21a --- /dev/null +++ b/db/fixtures/development/06_teams.rb @@ -0,0 +1,22 @@ +Gitlab::Seeder.quiet do + + (1..300).each do |i| + # Random Project + project = Project.scoped.sample + + # Random user + user = User.not_in_project(project).sample + + next unless user + + UsersProject.seed(:id, [{ + id: i, + project_id: project.id, + user_id: user.id, + project_access: UsersProject.access_roles.values.sample + }]) + + print('.') + end +end +puts "OK".green diff --git a/db/fixtures/development/07_milestones.rb b/db/fixtures/development/07_milestones.rb new file mode 100644 index 0000000..a77f619 --- /dev/null +++ b/db/fixtures/development/07_milestones.rb @@ -0,0 +1,13 @@ +Milestone.seed(:id, [ + { :id => 1, :project_id => 1, :title => 'v' + Faker::Address.zip_code }, + { :id => 2, :project_id => 1, :title => 'v' + Faker::Address.zip_code }, + { :id => 3, :project_id => 1, :title => 'v' + Faker::Address.zip_code }, + { :id => 4, :project_id => 2, :title => 'v' + Faker::Address.zip_code }, + { :id => 5, :project_id => 2, :title => 'v' + Faker::Address.zip_code }, + + { :id => 6, :project_id => 2, :title => 'v' + Faker::Address.zip_code }, + { :id => 7, :project_id => 2, :title => 'v' + Faker::Address.zip_code }, + { :id => 8, :project_id => 3, :title => 'v' + Faker::Address.zip_code }, + { :id => 9, :project_id => 3, :title => 'v' + Faker::Address.zip_code }, + { :id => 11, :project_id => 3, :title => 'v' + Faker::Address.zip_code }, +]) diff --git a/db/fixtures/development/08_wall.rb b/db/fixtures/development/08_wall.rb new file mode 100644 index 0000000..c4e304c --- /dev/null +++ b/db/fixtures/development/08_wall.rb @@ -0,0 +1,21 @@ +Gitlab::Seeder.quiet do + (1..300).each do |i| + # Random Project + project = Project.all.sample + + # Random user + user = project.users.sample + + next unless user + + user_id = user.id + + Note.seed(:id, [{ + id: i, + project_id: project.id, + author_id: user_id, + note: Faker::Lorem.sentence(6) + }]) + print('.') + end +end diff --git a/db/fixtures/development/09_issues.rb b/db/fixtures/development/09_issues.rb new file mode 100644 index 0000000..8978db4 --- /dev/null +++ b/db/fixtures/development/09_issues.rb @@ -0,0 +1,25 @@ +Gitlab::Seeder.quiet do + (1..300).each do |i| + # Random Project + project = Project.all.sample + + # Random user + user = project.users.sample + + next unless user + + user_id = user.id + IssueObserver.current_user = user + + Issue.seed(:id, [{ + id: i, + project_id: project.id, + author_id: user_id, + assignee_id: user_id, + closed: [true, false].sample, + milestone: project.milestones.sample, + title: Faker::Lorem.sentence(6) + }]) + print('.') + end +end diff --git a/db/fixtures/development/10_merge_requests.rb b/db/fixtures/development/10_merge_requests.rb new file mode 100644 index 0000000..9904b4a --- /dev/null +++ b/db/fixtures/development/10_merge_requests.rb @@ -0,0 +1,26 @@ +Gitlab::Seeder.quiet do + (1..300).each do |i| + # Random Project + project = Project.all.sample + + # Random user + user = project.users.sample + + next unless user + + user_id = user.id + MergeRequestObserver.current_user = user + MergeRequest.seed(:id, [{ + id: i, + source_branch: 'master', + target_branch: 'feature', + project_id: project.id, + author_id: user_id, + assignee_id: user_id, + closed: [true, false].sample, + milestone: project.milestones.sample, + title: Faker::Lorem.sentence(6) + }]) + print('.') + end +end diff --git a/db/fixtures/development/11_keys.rb b/db/fixtures/development/11_keys.rb new file mode 100644 index 0000000..8e4724c --- /dev/null +++ b/db/fixtures/development/11_keys.rb @@ -0,0 +1,14 @@ + +Gitlab::Seeder.quiet do + User.first(30).each_with_index do |user, i| + Key.seed(:id, [ + { + id: i, + title: "Sample key #{i}", + key: "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt#{i + 100}6k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=", + user_id: user.id, + } + ]) + puts "SSH KEY ##{i} added.".green + end +end -- libgit2 0.21.2