Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
6185d12c
Commit
6185d12c
authored
Jun 01, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add missing specs
parent
e61f38d7
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
132 additions
and
57 deletions
+132
-57
app/controllers/projects/artifacts_controller.rb
app/controllers/projects/artifacts_controller.rb
+1
-1
app/controllers/uploads_controller.rb
app/controllers/uploads_controller.rb
+1
-1
app/uploaders/artifact_uploader.rb
app/uploaders/artifact_uploader.rb
+4
-0
app/uploaders/gitlab_uploader.rb
app/uploaders/gitlab_uploader.rb
+2
-6
app/uploaders/records_uploads.rb
app/uploaders/records_uploads.rb
+2
-2
db/post_migrate/20170523083112_migrate_old_artifacts.rb
db/post_migrate/20170523083112_migrate_old_artifacts.rb
+5
-5
lib/api/helpers.rb
lib/api/helpers.rb
+10
-0
lib/api/jobs.rb
lib/api/jobs.rb
+0
-10
lib/api/runner.rb
lib/api/runner.rb
+1
-10
lib/api/v3/builds.rb
lib/api/v3/builds.rb
+0
-10
lib/ci/api/builds.rb
lib/ci/api/builds.rb
+4
-4
spec/migrations/migrate_old_artifacts_spec.rb
spec/migrations/migrate_old_artifacts_spec.rb
+8
-8
spec/uploaders/artifact_uploader_spec.rb
spec/uploaders/artifact_uploader_spec.rb
+38
-0
spec/uploaders/gitlab_uploader_spec.rb
spec/uploaders/gitlab_uploader_spec.rb
+56
-0
No files found.
app/controllers/projects/artifacts_controller.rb
View file @
6185d12c
...
@@ -10,7 +10,7 @@ class Projects::ArtifactsController < Projects::ApplicationController
...
@@ -10,7 +10,7 @@ class Projects::ArtifactsController < Projects::ApplicationController
before_action
:set_path_and_entry
,
only:
[
:file
,
:raw
]
before_action
:set_path_and_entry
,
only:
[
:file
,
:raw
]
def
download
def
download
if
artifacts_file
.
local_fil
e?
if
artifacts_file
.
file_storag
e?
send_file
artifacts_file
.
path
,
disposition:
'attachment'
send_file
artifacts_file
.
path
,
disposition:
'attachment'
else
else
redirect_to
artifacts_file
.
url
redirect_to
artifacts_file
.
url
...
...
app/controllers/uploads_controller.rb
View file @
6185d12c
...
@@ -80,7 +80,7 @@ class UploadsController < ApplicationController
...
@@ -80,7 +80,7 @@ class UploadsController < ApplicationController
else
else
@uploader
=
@model
.
send
(
upload_mount
)
@uploader
=
@model
.
send
(
upload_mount
)
redirect_to
@uploader
.
url
unless
@uploader
.
local
_storage?
redirect_to
@uploader
.
url
unless
@uploader
.
file
_storage?
end
end
@uploader
@uploader
...
...
app/uploaders/artifact_uploader.rb
View file @
6185d12c
...
@@ -7,6 +7,10 @@ class ArtifactUploader < GitlabUploader
...
@@ -7,6 +7,10 @@ class ArtifactUploader < GitlabUploader
Gitlab
.
config
.
artifacts
.
path
Gitlab
.
config
.
artifacts
.
path
end
end
def
self
.
artifacts_upload_path
File
.
join
(
self
.
local_artifacts_store
,
'tmp/uploads/'
)
end
def
initialize
(
job
,
field
)
def
initialize
(
job
,
field
)
@job
,
@field
=
job
,
field
@job
,
@field
=
job
,
field
end
end
...
...
app/uploaders/gitlab_uploader.rb
View file @
6185d12c
...
@@ -9,15 +9,11 @@ class GitlabUploader < CarrierWave::Uploader::Base
...
@@ -9,15 +9,11 @@ class GitlabUploader < CarrierWave::Uploader::Base
delegate
:base_dir
,
to: :class
delegate
:base_dir
,
to: :class
def
local_file?
def
file_storage?
local_storage?
&&
file
&
.
is_a?
(
CarrierWave
::
SanitizedFile
)
end
def
local_storage?
storage
.
is_a?
(
CarrierWave
::
Storage
::
File
)
storage
.
is_a?
(
CarrierWave
::
Storage
::
File
)
end
end
def
local
_cache_storage?
def
file
_cache_storage?
cache_storage
.
is_a?
(
CarrierWave
::
Storage
::
File
)
cache_storage
.
is_a?
(
CarrierWave
::
Storage
::
File
)
end
end
...
...
app/uploaders/records_uploads.rb
View file @
6185d12c
...
@@ -16,7 +16,7 @@ module RecordsUploads
...
@@ -16,7 +16,7 @@ module RecordsUploads
#
#
# Called `after :store`
# Called `after :store`
def
record_upload
(
_tempfile
)
def
record_upload
(
_tempfile
)
return
unless
local_fil
e?
return
unless
file_storag
e?
return
unless
file
.
exists?
return
unless
file
.
exists?
Upload
.
record
(
self
)
Upload
.
record
(
self
)
...
@@ -26,7 +26,7 @@ module RecordsUploads
...
@@ -26,7 +26,7 @@ module RecordsUploads
#
#
# Called `before :remove`
# Called `before :remove`
def
destroy_upload
(
*
args
)
def
destroy_upload
(
*
args
)
return
unless
local_fil
e?
return
unless
file_storag
e?
return
unless
file
return
unless
file
Upload
.
remove_path
(
relative_path
)
Upload
.
remove_path
(
relative_path
)
...
...
db/post_migrate/20170523083112_migrate_old_artifacts.rb
View file @
6185d12c
...
@@ -22,7 +22,7 @@ class MigrateOldArtifacts < ActiveRecord::Migration
...
@@ -22,7 +22,7 @@ class MigrateOldArtifacts < ActiveRecord::Migration
def
builds_with_artifacts
def
builds_with_artifacts
Build
.
with_artifacts
Build
.
with_artifacts
.
joins
(
'JOIN projects ON projects.id = ci_builds.project_id'
)
.
joins
(
'JOIN projects ON projects.id = ci_builds.project_id'
)
.
where
(
'ci_builds.id < ?'
,
min_id
||
0
)
.
where
(
'ci_builds.id < ?'
,
min_id
)
.
where
(
'projects.ci_id IS NOT NULL'
)
.
where
(
'projects.ci_id IS NOT NULL'
)
.
select
(
'id'
,
'created_at'
,
'project_id'
,
'projects.ci_id AS ci_id'
)
.
select
(
'id'
,
'created_at'
,
'project_id'
,
'projects.ci_id AS ci_id'
)
end
end
...
@@ -30,18 +30,18 @@ class MigrateOldArtifacts < ActiveRecord::Migration
...
@@ -30,18 +30,18 @@ class MigrateOldArtifacts < ActiveRecord::Migration
def
min_id
def
min_id
Build
.
joins
(
'JOIN projects ON projects.id = ci_builds.project_id'
)
Build
.
joins
(
'JOIN projects ON projects.id = ci_builds.project_id'
)
.
where
(
'projects.ci_id IS NULL'
)
.
where
(
'projects.ci_id IS NULL'
)
.
pluck
(
'
min(ci_builds.id
)'
)
.
pluck
(
'
coalesce(min(ci_builds.id), 0
)'
)
.
first
.
first
end
end
class
Build
<
ActiveRecord
::
Base
class
Build
<
ActiveRecord
::
Base
self
.
table_name
=
'ci_builds'
self
.
table_name
=
'ci_builds'
scope
:with_artifacts
,
->
()
{
where
.
not
(
artifacts_file:
[
nil
,
''
])
}
scope
:with_artifacts
,
->
{
where
.
not
(
artifacts_file:
[
nil
,
''
])
}
def
migrate_artifacts!
def
migrate_artifacts!
return
unless
File
.
exist
s
?
(
source_artifacts_path
)
return
unless
File
.
exist?
(
source_artifacts_path
)
return
if
File
.
exist
s
?
(
target_artifacts_path
)
return
if
File
.
exist?
(
target_artifacts_path
)
ensure_target_path
ensure_target_path
...
...
lib/api/helpers.rb
View file @
6185d12c
...
@@ -311,6 +311,16 @@ module API
...
@@ -311,6 +311,16 @@ module API
end
end
end
end
def
present_artifacts!
(
artifacts_file
)
return
not_found!
unless
artifacts_file
.
exists?
if
artifacts_file
.
file_storage?
present_file!
(
artifacts_file
.
path
,
artifacts_file
.
filename
)
else
redirect_to
(
artifacts_file
.
url
)
end
end
private
private
def
private_token
def
private_token
...
...
lib/api/jobs.rb
View file @
6185d12c
...
@@ -224,16 +224,6 @@ module API
...
@@ -224,16 +224,6 @@ module API
find_build
(
id
)
||
not_found!
find_build
(
id
)
||
not_found!
end
end
def
present_artifacts!
(
artifacts_file
)
if
!
artifacts_file
.
local_file?
redirect_to
(
build
.
artifacts_file
.
url
)
elsif
artifacts_file
.
exists?
present_file!
(
artifacts_file
.
path
,
artifacts_file
.
filename
)
else
not_found!
end
end
def
filter_builds
(
builds
,
scope
)
def
filter_builds
(
builds
,
scope
)
return
builds
if
scope
.
nil?
||
scope
.
empty?
return
builds
if
scope
.
nil?
||
scope
.
empty?
...
...
lib/api/runner.rb
View file @
6185d12c
...
@@ -241,16 +241,7 @@ module API
...
@@ -241,16 +241,7 @@ module API
get
'/:id/artifacts'
do
get
'/:id/artifacts'
do
job
=
authenticate_job!
job
=
authenticate_job!
artifacts_file
=
job
.
artifacts_file
present_artifacts!
(
job
.
artifacts_file
)
unless
artifacts_file
.
local_file?
return
redirect_to
job
.
artifacts_file
.
url
end
unless
artifacts_file
.
exists?
not_found!
end
present_file!
(
artifacts_file
.
path
,
artifacts_file
.
filename
)
end
end
end
end
end
end
...
...
lib/api/v3/builds.rb
View file @
6185d12c
...
@@ -225,16 +225,6 @@ module API
...
@@ -225,16 +225,6 @@ module API
find_build
(
id
)
||
not_found!
find_build
(
id
)
||
not_found!
end
end
def
present_artifacts!
(
artifacts_file
)
if
!
artifacts_file
.
local_file?
redirect_to
(
build
.
artifacts_file
.
url
)
elsif
artifacts_file
.
exists?
present_file!
(
artifacts_file
.
path
,
artifacts_file
.
filename
)
else
not_found!
end
end
def
filter_builds
(
builds
,
scope
)
def
filter_builds
(
builds
,
scope
)
return
builds
if
scope
.
nil?
||
scope
.
empty?
return
builds
if
scope
.
nil?
||
scope
.
empty?
...
...
lib/ci/api/builds.rb
View file @
6185d12c
...
@@ -187,14 +187,14 @@ module Ci
...
@@ -187,14 +187,14 @@ module Ci
build
=
authenticate_build!
build
=
authenticate_build!
artifacts_file
=
build
.
artifacts_file
artifacts_file
=
build
.
artifacts_file
unless
artifacts_file
.
local_file?
return
redirect_to
build
.
artifacts_file
.
url
end
unless
artifacts_file
.
exists?
unless
artifacts_file
.
exists?
not_found!
not_found!
end
end
unless
artifacts_file
.
file_storage?
return
redirect_to
build
.
artifacts_file
.
url
end
present_file!
(
artifacts_file
.
path
,
artifacts_file
.
filename
)
present_file!
(
artifacts_file
.
path
,
artifacts_file
.
filename
)
end
end
...
...
spec/migrations/migrate_old_artifacts_spec.rb
View file @
6185d12c
...
@@ -93,17 +93,17 @@ describe MigrateOldArtifacts do
...
@@ -93,17 +93,17 @@ describe MigrateOldArtifacts do
FileUtils
.
mkdir_p
(
legacy_path
(
build
))
FileUtils
.
mkdir_p
(
legacy_path
(
build
))
FileUtils
.
copy
(
FileUtils
.
copy
(
Rails
.
root
.
join
(
'spec/fixtures/ci_build_artifacts.zip'
),
Rails
.
root
.
join
(
'spec/fixtures/ci_build_artifacts.zip'
),
File
.
join
(
legacy_path
(
build
),
"ci_build_artifacts.zip"
)
File
.
join
(
legacy_path
(
build
),
"ci_build_artifacts.zip"
)
)
)
FileUtils
.
copy
(
FileUtils
.
copy
(
Rails
.
root
.
join
(
'spec/fixtures/ci_build_artifacts_metadata.gz'
),
Rails
.
root
.
join
(
'spec/fixtures/ci_build_artifacts_metadata.gz'
),
File
.
join
(
legacy_path
(
build
),
"ci_build_artifacts_metadata.gz"
)
File
.
join
(
legacy_path
(
build
),
"ci_build_artifacts_metadata.gz"
)
)
)
build
.
update_columns
(
build
.
update_columns
(
artifacts_file:
'ci_build_artifacts.zip'
,
artifacts_file:
'ci_build_artifacts.zip'
,
artifacts_metadata:
'ci_build_artifacts_metadata.gz'
,
artifacts_metadata:
'ci_build_artifacts_metadata.gz'
)
)
build
.
reload
build
.
reload
end
end
...
...
spec/uploaders/artifact_uploader_spec.rb
0 → 100644
View file @
6185d12c
require
'rails_helper'
describe
ArtifactUploader
do
let
(
:job
)
{
create
(
:ci_build
)
}
let
(
:uploader
)
{
described_class
.
new
(
job
,
:artifacts_file
)
}
let
(
:path
)
{
Gitlab
.
config
.
artifacts
.
path
}
describe
'.local_artifacts_store'
do
subject
{
described_class
.
local_artifacts_store
}
it
"delegate to artifacts path"
do
expect
(
Gitlab
.
config
.
artifacts
).
to
receive
(
:path
)
subject
end
end
describe
'.artifacts_upload_path'
do
subject
{
described_class
.
artifacts_upload_path
}
it
{
is_expected
.
to
start_with
(
path
)
}
it
{
is_expected
.
to
end_with
(
'tmp/uploads/'
)
}
end
describe
'#store_dir'
do
subject
{
uploader
.
store_dir
}
it
{
is_expected
.
to
start_with
(
path
)
}
it
{
is_expected
.
to
end_with
(
"
#{
job
.
project_id
}
/
#{
job
.
id
}
"
)
}
end
describe
'#cache_dir'
do
subject
{
uploader
.
cache_dir
}
it
{
is_expected
.
to
start_with
(
path
)
}
it
{
is_expected
.
to
end_with
(
'tmp/cache'
)
}
end
end
spec/uploaders/gitlab_uploader_spec.rb
0 → 100644
View file @
6185d12c
require
'rails_helper'
require
'carrierwave/storage/fog'
describe
GitlabUploader
do
let
(
:uploader_class
)
{
Class
.
new
(
described_class
)
}
subject
{
uploader_class
.
new
}
describe
'#file_storage?'
do
context
'when file storage is used'
do
before
do
uploader_class
.
storage
(
:file
)
end
it
{
is_expected
.
to
be_file_storage
}
end
context
'when is remote storage'
do
before
do
uploader_class
.
storage
(
:fog
)
end
it
{
is_expected
.
not_to
be_file_storage
}
end
end
describe
'#file_cache_storage?'
do
context
'when file storage is used'
do
before
do
uploader_class
.
cache_storage
(
:file
)
end
it
{
is_expected
.
to
be_file_cache_storage
}
end
context
'when is remote storage'
do
before
do
uploader_class
.
cache_storage
(
:fog
)
end
it
{
is_expected
.
not_to
be_file_cache_storage
}
end
end
describe
'#move_to_cache'
do
it
'is true'
do
expect
(
subject
.
move_to_cache
).
to
eq
(
true
)
end
end
describe
'#move_to_store'
do
it
'is true'
do
expect
(
subject
.
move_to_store
).
to
eq
(
true
)
end
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