BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
a385d39f
Commit
a385d39f
authored
Dec 17, 2015
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve CI builds seeder
parent
7027bf40
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
22 deletions
+59
-22
14_builds.rb
db/fixtures/development/14_builds.rb
+59
-22
No files found.
db/fixtures/development/14_builds.rb
View file @
a385d39f
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment