Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2015-12-17 14:59:39 +0300
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-01-14 14:48:12 +0300
commita385d39ff1ef3cca8b98f75b99022f762fa5b5e5 (patch)
tree787f806e8594a68e68d9f0f8a76e7ce36375086d /db
parent7027bf40c6898a26557d7325356e5e8760a3ff40 (diff)
Improve CI builds seeder
Diffstat (limited to 'db')
-rw-r--r--db/fixtures/development/14_builds.rb81
1 files changed, 59 insertions, 22 deletions
diff --git a/db/fixtures/development/14_builds.rb b/db/fixtures/development/14_builds.rb
index f9b4482cbf9..2e15f30adbb 100644
--- a/db/fixtures/development/14_builds.rb
+++ b/db/fixtures/development/14_builds.rb
@@ -1,36 +1,73 @@
-Gitlab::Seeder.quiet do
- build_artifacts_path = Rails.root + 'spec/fixtures/ci_build_artifacts.tar.gz'
- build_artifacts_cache_file = build_artifacts_path.to_s.gsub('ci_', '')
+class Gitlab::Seeder::Builds
+ BUILD_STATUSES = %w(running pending success failed canceled)
- Project.all.sample(5).each do |project|
- commits = project.repository.commits('master', nil, 5)
- commits_sha = commits.map { |commit| commit.raw.id }
- ci_commits = commits_sha.map do |sha|
- project.ensure_ci_commit(sha)
- end
+ def initialize(project)
+ @project = project
+ end
+ def seed!
ci_commits.each do |ci_commit|
- attributes = { type: 'Ci::Build', name: 'test build', commands: "$ build command",
- stage: 'test', stage_idx: 1, ref: 'master',
- user_id: project.team.users.sample, gl_project_id: project.id,
- status: %w(running pending success failed canceled).sample,
- commit_id: ci_commit.id, created_at: Time.now, updated_at: Time.now }
+ build = Ci::Build.new(build_attributes_for(ci_commit))
- build = Ci::Build.new(attributes)
- build.artifacts_metadata = `tar tzf #{build_artifacts_path}`.split(/\n/)
-
- FileUtils.copy(build_artifacts_path, build_artifacts_cache_file)
- build.artifacts_file = artifacts_file = File.open(build_artifacts_cache_file, 'r')
+ FileUtils.copy(artifacts_path, artifacts_cache_file_path)
+ File.open(artifacts_cache_file_path, 'r') do |file|
+ build.artifacts_file = file
+ build.artifacts_metadata = artifacts_metadata
+ end
begin
build.save!
print '.'
rescue ActiveRecord::RecordInvalid
- puts build.error.messages.inspect
print 'F'
- ensure
- artifacts_file.close
end
end
end
+
+ def ci_commits
+ commits = @project.repository.commits('master', nil, 5)
+ commits_sha = commits.map { |commit| commit.raw.id }
+ commits_sha.map do |sha|
+ @project.ensure_ci_commit(sha)
+ end
+ rescue
+ []
+ end
+
+ def build_attributes_for(ci_commit)
+ { name: 'test build', commands: "$ build command",
+ stage: 'test', stage_idx: 1, ref: 'master',
+ user_id: build_user, gl_project_id: @project.id,
+ status: build_status, commit_id: ci_commit.id,
+ created_at: Time.now, updated_at: Time.now }
+ end
+
+ def build_user
+ @project.team.users.sample
+ end
+
+ def build_status
+ BUILD_STATUSES.sample
+ end
+
+ def artifacts_path
+ Rails.root + 'spec/fixtures/ci_build_artifacts.tar.gz'
+ end
+
+ def artifacts_cache_file_path
+ artifacts_path.to_s.gsub('ci_', "p#{@project.id}_")
+ end
+
+ def artifacts_metadata
+ return @artifacts_metadata if @artifacts_metadata
+ logs, _exit_status = Gitlab::Popen.popen(%W(tar tzf #{artifacts_path}))
+ @artifacts_metadata = logs.split(/\n/)
+ end
+end
+
+Gitlab::Seeder.quiet do
+ Project.all.sample(10).each do |project|
+ project_builds = Gitlab::Seeder::Builds.new(project)
+ project_builds.seed!
+ end
end