Skip to content

Commit

Permalink
[webui][ci] Check multiple package_groups
Browse files Browse the repository at this point in the history
Is not allowed to have multiple `package_groups` with the same attributes.
  • Loading branch information
David Kang committed Oct 5, 2017
1 parent 22640e2 commit 3707ccb
Show file tree
Hide file tree
Showing 12 changed files with 1,647 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/api/app/models/kiwi/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class Kiwi::Image < ApplicationRecord
#### Validations macros
validates :name, presence: true
validate :check_use_project_repositories
validate :check_package_groups
validate :check_package_group_type_image
accepts_nested_attributes_for :repositories, allow_destroy: true
accepts_nested_attributes_for :package_groups, allow_destroy: true
accepts_nested_attributes_for :kiwi_packages, allow_destroy: true
Expand Down Expand Up @@ -133,7 +135,7 @@ def outdated?
end

def default_package_group
package_groups.type_image
package_groups.type_image.first || package_groups.create(kiwi_type: :image, pattern_type: 'onlyRequired')
end

def self.find_binaries_by_name(query, project, repositories, options = {})
Expand Down Expand Up @@ -170,6 +172,19 @@ def check_use_project_repositories
errors.add(:base,
"A repository with source_path=\"obsrepositories:/\" has been set. If you want to use it, please remove the other repositories.")
end

def check_package_group_type_image
return if package_groups.select(&:kiwi_type_image?).size <= 2

errors.add(:base, "Having more than 2 package groups with type='image' is not allowed.")
end

def check_package_groups
return if package_groups.group_by { |package_group| [package_group.kiwi_type, package_group.pattern_type] }
.select { |_key, value| value.count > 1 }.keys.empty?

errors.add(:base, "Multiple package groups with same attributes is not allowed.")
end
end

# == Schema Information
Expand Down
4 changes: 4 additions & 0 deletions src/api/app/models/kiwi/package_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def to_xml

builder.to_xml save_with: Nokogiri::XML::Node::SaveOptions::NO_DECLARATION | Nokogiri::XML::Node::SaveOptions::FORMAT
end

def kiwi_type_image?
kiwi_type == 'image'
end
end

# == Schema Information
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3707ccb

Please sign in to comment.