Commit ec6b44ae authored by Sean McGivern's avatar Sean McGivern

Merge branch 'improve-conan-packages-code-quality' into 'master'

Improve conan packages code quality

See merge request gitlab-org/gitlab!24647
parents 34273fdc 75f80036
...@@ -391,15 +391,31 @@ module API ...@@ -391,15 +391,31 @@ module API
present_carrierwave_file!(package_file.file) present_carrierwave_file!(package_file.file)
end end
def find_or_create_package
package || ::Packages::Conan::CreatePackageService.new(project, current_user, params).execute
end
def track_push_package_event
if params[:file_name] == ::Packages::ConanFileMetadatum::PACKAGE_BINARY && params['file.size'].positive?
track_event('push_package')
end
end
def create_package_file_with_type(file_type, current_package)
unless params['file.size'] == 0
# conan sends two upload requests, the first has no file, so we skip record creation if file.size == 0
::Packages::Conan::CreatePackageFileService.new(current_package, uploaded_package_file, params.merge(conan_file_type: file_type)).execute
end
end
def upload_package_file(file_type) def upload_package_file(file_type)
authorize_upload!(project) authorize_upload!(project)
current_package = package || ::Packages::Conan::CreatePackageService.new(project, current_user, params).execute current_package = find_or_create_package
track_event('push_package') if params[:file_name] == ::Packages::ConanFileMetadatum::PACKAGE_BINARY && params['file.size'].positive? track_push_package_event
# conan sends two upload requests, the first has no file, so we skip record creation if file.size == 0 create_package_file_with_type(file_type, current_package)
::Packages::Conan::CreatePackageFileService.new(current_package, uploaded_package_file, params.merge(conan_file_type: file_type)).execute unless params['file.size'] == 0
rescue ObjectStorage::RemoteStoreError => e rescue ObjectStorage::RemoteStoreError => e
Gitlab::ErrorTracking.track_exception(e, file_name: params[:file_name], project_id: project.id) Gitlab::ErrorTracking.track_exception(e, file_name: params[:file_name], project_id: project.id)
...@@ -416,9 +432,7 @@ module API ...@@ -416,9 +432,7 @@ module API
def find_user_from_job_token def find_user_from_job_token
return unless route_authentication_setting[:job_token_allowed] return unless route_authentication_setting[:job_token_allowed]
job = find_job_from_token job = find_job_from_token || raise(::Gitlab::Auth::UnauthorizedError)
raise ::Gitlab::Auth::UnauthorizedError unless job
job.user job.user
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment