2020-07-28 23:09:34 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Packages
|
|
|
|
module Detail
|
|
|
|
class PackagePresenter
|
|
|
|
def initialize(package)
|
|
|
|
@package = package
|
|
|
|
end
|
|
|
|
|
|
|
|
def detail_view
|
2021-01-03 14:25:43 +05:30
|
|
|
name = @package.name
|
|
|
|
name = @package.conan_recipe if @package.conan?
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
package_detail = {
|
|
|
|
id: @package.id,
|
|
|
|
created_at: @package.created_at,
|
2021-01-03 14:25:43 +05:30
|
|
|
name: name,
|
2020-07-28 23:09:34 +05:30
|
|
|
package_files: @package.package_files.map { |pf| build_package_file_view(pf) },
|
|
|
|
package_type: @package.package_type,
|
2021-06-08 01:23:25 +05:30
|
|
|
status: @package.status,
|
2020-07-28 23:09:34 +05:30
|
|
|
project_id: @package.project_id,
|
|
|
|
tags: @package.tags.as_json,
|
|
|
|
updated_at: @package.updated_at,
|
|
|
|
version: @package.version
|
|
|
|
}
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
package_detail[:conan_package_name] = @package.name if @package.conan?
|
2020-07-28 23:09:34 +05:30
|
|
|
package_detail[:maven_metadatum] = @package.maven_metadatum if @package.maven_metadatum
|
|
|
|
package_detail[:nuget_metadatum] = @package.nuget_metadatum if @package.nuget_metadatum
|
2020-10-24 23:57:45 +05:30
|
|
|
package_detail[:composer_metadatum] = @package.composer_metadatum if @package.composer_metadatum
|
|
|
|
package_detail[:conan_metadatum] = @package.conan_metadatum if @package.conan_metadatum
|
2020-07-28 23:09:34 +05:30
|
|
|
package_detail[:dependency_links] = @package.dependency_links.map(&method(:build_dependency_links))
|
2021-01-29 00:20:46 +05:30
|
|
|
package_detail[:pipeline] = build_pipeline_info(@package.pipeline) if @package.pipeline
|
|
|
|
package_detail[:pipelines] = build_pipeline_infos(@package.pipelines) if @package.pipelines.present?
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
package_detail
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def build_package_file_view(package_file)
|
2021-01-29 00:20:46 +05:30
|
|
|
file_view = {
|
2020-07-28 23:09:34 +05:30
|
|
|
created_at: package_file.created_at,
|
|
|
|
download_path: package_file.download_path,
|
|
|
|
file_name: package_file.file_name,
|
2021-04-17 20:07:23 +05:30
|
|
|
size: package_file.size,
|
|
|
|
file_md5: package_file.file_md5,
|
|
|
|
file_sha1: package_file.file_sha1,
|
|
|
|
file_sha256: package_file.file_sha256
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
}
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
file_view[:pipelines] = build_pipeline_infos(package_file.pipelines) if package_file.pipelines.present?
|
|
|
|
|
|
|
|
file_view
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_pipeline_infos(pipeline_infos)
|
|
|
|
pipeline_infos.map { |pipeline_info| build_pipeline_info(pipeline_info) }
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def build_pipeline_info(pipeline_info)
|
|
|
|
{
|
|
|
|
created_at: pipeline_info.created_at,
|
|
|
|
id: pipeline_info.id,
|
|
|
|
sha: pipeline_info.sha,
|
|
|
|
ref: pipeline_info.ref,
|
|
|
|
user: build_user_info(pipeline_info.user),
|
|
|
|
project: {
|
|
|
|
name: pipeline_info.project.name,
|
2020-10-24 23:57:45 +05:30
|
|
|
web_url: pipeline_info.project.web_url,
|
|
|
|
pipeline_url: Gitlab::Routing.url_helpers.project_pipeline_url(pipeline_info.project, pipeline_info),
|
|
|
|
commit_url: Gitlab::Routing.url_helpers.project_commit_url(pipeline_info.project, pipeline_info.sha)
|
2020-07-28 23:09:34 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_user_info(user)
|
|
|
|
return unless user
|
|
|
|
|
|
|
|
{
|
|
|
|
avatar_url: user.avatar_url,
|
|
|
|
name: user.name
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_dependency_links(link)
|
|
|
|
{
|
|
|
|
name: link.dependency.name,
|
|
|
|
version_pattern: link.dependency.version_pattern,
|
|
|
|
target_framework: link.nuget_metadatum&.target_framework
|
|
|
|
}.compact
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|