Commit 37c42f87 authored by Dylan Griffith's avatar Dylan Griffith

Merge branch '10io-fix-instance-vars-access-in-nuget-services' into 'master'

Fix instance variables access to several nuget services

See merge request gitlab-org/gitlab!25602
parents 58b1f41a b9888626
...@@ -6,8 +6,6 @@ module Packages ...@@ -6,8 +6,6 @@ module Packages
include API::Helpers::Packages::Nuget::MetadataPresenterHelpers include API::Helpers::Packages::Nuget::MetadataPresenterHelpers
include Gitlab::Utils::StrongMemoize include Gitlab::Utils::StrongMemoize
attr_reader :packages
COUNT = 1.freeze COUNT = 1.freeze
def initialize(packages) def initialize(packages)
...@@ -56,7 +54,7 @@ module Packages ...@@ -56,7 +54,7 @@ module Packages
def sorted_versions def sorted_versions
strong_memoize(:sorted_versions) do strong_memoize(:sorted_versions) do
versions = packages.map(&:version).compact versions = @packages.map(&:version).compact
VersionSorter.sort(versions) VersionSorter.sort(versions)
end end
end end
......
...@@ -3,8 +3,6 @@ ...@@ -3,8 +3,6 @@
module Packages module Packages
module Nuget module Nuget
class PackagesVersionsPresenter class PackagesVersionsPresenter
attr_reader :packages
def initialize(packages) def initialize(packages)
@packages = packages @packages = packages
end end
......
...@@ -5,8 +5,6 @@ module Packages ...@@ -5,8 +5,6 @@ module Packages
class ServiceIndexPresenter class ServiceIndexPresenter
include API::Helpers::RelatedResourcesHelpers include API::Helpers::RelatedResourcesHelpers
attr_reader :project
SERVICE_VERSIONS = { SERVICE_VERSIONS = {
download: %w[PackageBaseAddress/3.0.0], download: %w[PackageBaseAddress/3.0.0],
search: %w[SearchQueryService SearchQueryService/3.0.0-beta SearchQueryService/3.0.0-rc], search: %w[SearchQueryService SearchQueryService/3.0.0-beta SearchQueryService/3.0.0-rc],
...@@ -52,13 +50,13 @@ module Packages ...@@ -52,13 +50,13 @@ module Packages
end end
def build_service_url(service_type) def build_service_url(service_type)
base_path = api_v4_projects_packages_nuget_path(id: project.id) base_path = api_v4_projects_packages_nuget_path(id: @project.id)
full_path = case service_type full_path = case service_type
when :download when :download
api_v4_projects_packages_nuget_download_package_name_package_version_package_filename_path( api_v4_projects_packages_nuget_download_package_name_package_version_package_filename_path(
{ {
id: project.id, id: @project.id,
package_name: nil, package_name: nil,
package_version: nil, package_version: nil,
package_filename: nil package_filename: nil
...@@ -70,7 +68,7 @@ module Packages ...@@ -70,7 +68,7 @@ module Packages
when :metadata when :metadata
api_v4_projects_packages_nuget_metadata_package_name_package_version_path( api_v4_projects_packages_nuget_metadata_package_name_package_version_path(
{ {
id: project.id, id: @project.id,
package_name: nil, package_name: nil,
package_version: nil package_version: nil
}, },
......
...@@ -7,8 +7,6 @@ module Packages ...@@ -7,8 +7,6 @@ module Packages
ExtractionError = Class.new(StandardError) ExtractionError = Class.new(StandardError)
attr_reader :package_file_id
XPATHS = { XPATHS = {
package_name: '//xmlns:package/xmlns:metadata/xmlns:id', package_name: '//xmlns:package/xmlns:metadata/xmlns:id',
package_version: '//xmlns:package/xmlns:metadata/xmlns:version' package_version: '//xmlns:package/xmlns:metadata/xmlns:version'
...@@ -30,7 +28,7 @@ module Packages ...@@ -30,7 +28,7 @@ module Packages
def package_file def package_file
strong_memoize(:package_file) do strong_memoize(:package_file) do
::Packages::PackageFile.find_by_id(package_file_id) ::Packages::PackageFile.find_by_id(@package_file_id)
end end
end end
......
...@@ -7,8 +7,6 @@ module Packages ...@@ -7,8 +7,6 @@ module Packages
InvalidMetadataError = Class.new(StandardError) InvalidMetadataError = Class.new(StandardError)
attr_reader :package_file
def initialize(package_file) def initialize(package_file)
@package_file = package_file @package_file = package_file
end end
...@@ -16,10 +14,10 @@ module Packages ...@@ -16,10 +14,10 @@ module Packages
def execute def execute
raise InvalidMetadataError.new('package name and/or package version not found in metadata') unless valid_metadata? raise InvalidMetadataError.new('package name and/or package version not found in metadata') unless valid_metadata?
package_file.transaction do @package_file.transaction do
package_file.update!( @package_file.update!(
file_name: package_filename, file_name: package_filename,
file: package_file.file file: @package_file.file
) )
if existing_package_id if existing_package_id
...@@ -37,15 +35,15 @@ module Packages ...@@ -37,15 +35,15 @@ module Packages
end end
def link_to_existing_package def link_to_existing_package
package_to_destroy = package_file.package package_to_destroy = @package_file.package
package_file.update!(package_id: existing_package_id) @package_file.update!(package_id: existing_package_id)
package_to_destroy.destroy! package_to_destroy.destroy!
end end
def update_linked_package def update_linked_package
return unless package_name && package_version return unless package_name && package_version
package_file.package.update!( @package_file.package.update!(
name: package_name, name: package_name,
version: package_version version: package_version
) )
...@@ -53,12 +51,12 @@ module Packages ...@@ -53,12 +51,12 @@ module Packages
def existing_package_id def existing_package_id
strong_memoize(:existing_package_id) do strong_memoize(:existing_package_id) do
package_file.project.packages @package_file.project.packages
.nuget .nuget
.with_name(package_name) .with_name(package_name)
.with_version(package_version) .with_version(package_version)
.pluck_primary_key .pluck_primary_key
.first .first
end end
end end
...@@ -72,7 +70,7 @@ module Packages ...@@ -72,7 +70,7 @@ module Packages
def metadata def metadata
strong_memoize(:metadata) do strong_memoize(:metadata) do
::Packages::Nuget::MetadataExtractionService.new(package_file.id).execute ::Packages::Nuget::MetadataExtractionService.new(@package_file.id).execute
end end
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