Add latest changes from gitlab-org/gitlab@master

This commit is contained in:
GitLab Bot 2021-01-07 06:10:18 +00:00
parent 7a2edf5d86
commit 2475461aa2
4 changed files with 147 additions and 3 deletions

View file

@ -69,7 +69,7 @@ const removeFlashClickListener = (flashEl, fadeTransition) => {
* @param {String} message Flash message text
* @param {String} type Type of Flash, it can be `notice`, `success`, `warning` or `alert` (default)
* @param {Object} parent Reference to parent element under which Flash needs to appear
* @param {Object} actonConfig Map of config to show action on banner
* @param {Object} actionConfig Map of config to show action on banner
* @param {String} href URL to which action config should point to (default: '#')
* @param {String} title Title of action
* @param {Function} clickHandler Method to call when action is clicked on
@ -119,7 +119,7 @@ const deprecatedCreateFlash = function deprecatedCreateFlash(
* @param {String} options.message Flash message text
* @param {String} options.type Type of Flash, it can be `notice`, `success`, `warning` or `alert` (default)
* @param {Object} options.parent Reference to parent element under which Flash needs to appear
* @param {Object} options.actonConfig Map of config to show action on banner
* @param {Object} options.actionConfig Map of config to show action on banner
* @param {String} href URL to which action config should point to (default: '#')
* @param {String} title Title of action
* @param {Function} clickHandler Method to call when action is clicked on

View file

@ -0,0 +1,85 @@
# frozen_string_literal: true
module Packages
module Debian
class ExtractMetadataService
include Gitlab::Utils::StrongMemoize
ExtractionError = Class.new(StandardError)
def initialize(package_file)
@package_file = package_file
end
def execute
raise ExtractionError.new('invalid package file') unless valid_package_file?
extract_metadata
end
private
attr_reader :package_file
def valid_package_file?
package_file &&
package_file.package&.debian? &&
package_file.file.size > 0 # rubocop:disable Style/ZeroLengthPredicate
end
def file_type_basic
%i[dsc deb udeb buildinfo changes].each do |format|
return format if package_file.file_name.end_with?(".#{format}")
end
nil
end
def file_type_source
# https://manpages.debian.org/buster/dpkg-dev/dpkg-source.1.en.html
%i[gzip bzip2 lzma xz].each do |format|
return :source if package_file.file_name.end_with?(".tar.#{format}")
end
nil
end
def file_type
strong_memoize(:file_type) do
file_type_basic || file_type_source || :unknown
end
end
def file_type_debian?
file_type == :deb || file_type == :udeb
end
def file_type_meta?
file_type == :dsc || file_type == :buildinfo || file_type == :changes
end
def extracted_fields
if file_type_debian?
package_file.file.use_file do |file_path|
::Packages::Debian::ExtractDebMetadataService.new(file_path).execute
end
elsif file_type_meta?
package_file.file.use_file do |file_path|
::Packages::Debian::ParseDebian822Service.new(File.read(file_path)).execute.each_value.first
end
end
end
def extract_metadata
fields = extracted_fields
architecture = fields.delete(:Architecture) if file_type_debian?
{
file_type: file_type,
architecture: architecture,
fields: fields
}
end
end
end
end

View file

@ -32,7 +32,7 @@ module QA
def enabled?(key, **scopes)
feature = JSON.parse(get_features).find { |flag| flag['name'] == key.to_s }
feature && feature['state'] == 'on' || feature['state'] == 'conditional' && scopes.present? && enabled_scope?(feature['gates'], scopes)
feature && (feature['state'] == 'on' || feature['state'] == 'conditional' && scopes.present? && enabled_scope?(feature['gates'], scopes))
end
private

View file

@ -0,0 +1,59 @@
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Packages::Debian::ExtractMetadataService do
let(:service) { described_class.new(package_file) }
subject { service.execute }
RSpec.shared_context 'Debian ExtractMetadata Service' do |trait|
let(:package_file) { create(:debian_package_file, trait) }
end
RSpec.shared_examples 'Test Debian ExtractMetadata Service' do |expected_file_type, expected_architecture, expected_fields|
it "returns file_type #{expected_file_type.inspect}" do
expect(subject[:file_type]).to eq(expected_file_type)
end
it "returns architecture #{expected_architecture.inspect}" do
expect(subject[:architecture]).to eq(expected_architecture)
end
it "returns fields #{expected_fields.nil? ? '' : 'including '}#{expected_fields.inspect}" do
if expected_fields.nil?
expect(subject[:fields]).to be_nil
else
expect(subject[:fields]).to include(**expected_fields)
end
end
end
using RSpec::Parameterized::TableSyntax
where(:case_name, :trait, :expected_file_type, :expected_architecture, :expected_fields) do
'with invalid' | :invalid | :unknown | nil | nil
'with source' | :source | :source | nil | nil
'with dsc' | :dsc | :dsc | nil | { 'Binary': 'sample-dev, libsample0, sample-udeb' }
'with deb' | :deb | :deb | 'amd64' | { 'Multi-Arch': 'same' }
'with udeb' | :udeb | :udeb | 'amd64' | { 'Package': 'sample-udeb' }
'with buildinfo' | :buildinfo | :buildinfo | nil | { 'Architecture': 'amd64 source', 'Build-Architecture': 'amd64' }
'with changes' | :changes | :changes | nil | { 'Architecture': 'source amd64', 'Binary': 'libsample0 sample-dev sample-udeb' }
end
with_them do
include_context 'Debian ExtractMetadata Service', params[:trait] do
it_behaves_like 'Test Debian ExtractMetadata Service',
params[:expected_file_type],
params[:expected_architecture],
params[:expected_fields]
end
end
context 'with invalid package file' do
let(:package_file) { create(:conan_package_file) }
it 'raise error' do
expect { subject }.to raise_error(described_class::ExtractionError, 'invalid package file')
end
end
end