Skip to content

Commit

Permalink
[api] refactor addchannels to prepare handling based on modes
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianschroeter committed Jul 10, 2015
1 parent 25c781b commit c95f56a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
7 changes: 4 additions & 3 deletions src/api/app/models/channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ def branch_channel_package_into_project(project)
tpkg.branch_from(cp.project.name, cp.name)
tpkg.sources_changed

add_channel_repos_to_project(tpkg)
tpkg
end

def add_channel_repos_to_project(tpkg)
def add_channel_repos_to_project(tpkg, mode=nil)
cp = self.package

if self.channel_targets.empty?
Expand All @@ -158,13 +158,14 @@ def add_channel_repos_to_project(tpkg)

# defined in channel
self.channel_targets.each do |ct|
next if mode==:skip_disabled and ct.disabled
repo_name = ct.repository.extended_name
# add repositories
unless cp.project.repositories.find_by_name(repo_name)
tpkg.project.add_repository_with_targets(repo_name, ct.repository, [ct.repository])
end
# enable package
tpkg.enable_for_repository repo_name unless ct.disabled
tpkg.enable_for_repository repo_name unless ct.disabled or mode==:enable_all
end
end
end
7 changes: 4 additions & 3 deletions src/api/app/models/channel_binary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ def self.find_by_project_and_package(project, package)
end

def create_channel_package_into(project)

channel = self.channel_binary_list.channel

# does it exist already? then just skip it
return if Package.exists_by_project_and_name(project.name, channel.name, follow_project_links: false, allow_remote_packages: false)
return nil if Package.exists_by_project_and_name(project.name, channel.name, follow_project_links: false, allow_remote_packages: false)

# create a channel package beside my package
channel.branch_channel_package_into_project(project)
# create a channel package beside my package and return that
return channel.branch_channel_package_into_project(project)
end

end
12 changes: 9 additions & 3 deletions src/api/app/models/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,9 @@ def is_local_link?
return li['project'] == self.project.name
end

def add_channels
def add_channels(mode=nil)
raise InvalidParameterError unless [nil, :add_disabled, :skip_disabled, :enable_all].include? mode

opkg = self.origin_container
# remote or broken link?
return if opkg.nil?
Expand All @@ -810,7 +812,9 @@ def add_channels

# main package
ChannelBinary.find_by_project_and_package(project_name, opkg.name).each do |cb|
cb.create_channel_package_into(self.project)
cpkg = cb.create_channel_package_into(self.project)
next unless cpkg
cpkg.channels.first.add_channel_repos_to_project(cpkg, mode)
end
# and all possible existing local links
if opkg.project.is_maintenance_release? and opkg.is_link?
Expand All @@ -824,7 +828,9 @@ def add_channels
# strip incident suffix in update release projects
name.gsub!(/\.[^\.]*$/,'') if opkg.project.is_maintenance_release?
ChannelBinary.find_by_project_and_package(project_name, name).each do |cb|
cb.create_channel_package_into(self.project)
cpkg = cb.create_channel_package_into(self.project)
next unless cpkg
cpkg.channels.first.add_channel_repos_to_project(cpkg, mode)
end
end
self.project.store
Expand Down

0 comments on commit c95f56a

Please sign in to comment.