Skip to content

Commit

Permalink
[api] support multiple target repos by one channel
Browse files Browse the repository at this point in the history
But enforce same updateinfo id when one target repo is defined in multiple channels
  • Loading branch information
adrianschroeter committed Apr 15, 2016
1 parent d0b3bad commit 3a55349
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
12 changes: 10 additions & 2 deletions src/api/app/helpers/maintenance_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class MissingAction < APIException
setup 400, 'The request contains no actions. Submit requests without source changes may have skipped!'
end

class MultipleUpdateInfoTemplate < APIException; end

def _release_product(sourcePackage, targetProject, action)
productPackage = Package.find_by_project_and_name sourcePackage.project.name, "_product"
# create package container, if missing
Expand Down Expand Up @@ -242,8 +244,14 @@ def get_updateinfo_id(sourcePackage, targetRepo)
projectFilter = prj.maintained_projects.map{|mp| mp.project}
end
# prefer a channel in the source project to avoid double hits exceptions
ct = ChannelTarget.find_by_repo(targetRepo, [sourcePackage.project]) || ChannelTarget.find_by_repo(targetRepo, projectFilter)
id_template=ct.id_template if ct and ct.id_template
cts = ChannelTarget.find_by_repo(targetRepo, [sourcePackage.project])
cts = ChannelTarget.find_by_repo(targetRepo, projectFilter) unless cts.any?
first_ct = cts.first
unless cts.all?{|c| c.id_template == first_ct.id_template}
msg = cts.map{|cti| "#{cti.channel.package.project.name}/#{cti.channel.package.name}"}.join(", ")
raise MultipleUpdateInfoTemplate.new "Multiple channel targets found in #{msg} for repository #{targetRepo.project.name}/#{targetRepo.name}"
end
id_template = cts.first.id_template if cts.first and cts.first.id_template

uID = mi.getUpdateinfoId(id_template, patchName)
return uID
Expand Down
2 changes: 0 additions & 2 deletions src/api/app/models/bs_request_action_maintenance_release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ def sanity_check!
"on position #{i}: #{prj.name} / #{repo.name}"
end
end
# find broken channel targets
ChannelTarget.find_by_repo(rt.target_repository, [prj])
end
end
end
Expand Down
12 changes: 1 addition & 11 deletions src/api/app/models/channel_target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ class ChannelTarget < ActiveRecord::Base
belongs_to :repository
has_one :project, through: :repository

class MultipleChannelTargets < APIException; end

def self._sync_keys
[ :project, :repository ]
end
Expand All @@ -17,15 +15,7 @@ def self.find_by_repo(repo, projectFilter = nil)
else
ct = ChannelTarget.joins(:channel => :package).distinct.where("repository_id = ? AND project_id IN (?)", repo, projectFilter.map{|p| p.id})
end
return nil if ct.length < 1

if ct.length > 1
msg=""
ct.each do |cti|
msg << "#{cti.channel.package.project.name}/#{cti.channel.package.name}, "
end
raise MultipleChannelTargets, "Multiple channel targets found in #{msg} for repository #{repo.project.name}/#{repo.name}"
end
return ct.first
ct
end
end
4 changes: 2 additions & 2 deletions src/api/app/models/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ def linking_repositories
def is_local_channel?
# is any our path elements the target of a channel package in this project?
self.path_elements.includes(:link).each do |pe|
return true if ChannelTarget.find_by_repo(pe.link, [self.project])
return true if ChannelTarget.find_by_repo(pe.link, [self.project]).any?
end
return true if ChannelTarget.find_by_repo(self, [self.project])
return true if ChannelTarget.find_by_repo(self, [self.project]).any?
false
end

Expand Down

0 comments on commit 3a55349

Please sign in to comment.