Skip to content

Commit

Permalink
[api] Merge origin_container and local_origin_container
Browse files Browse the repository at this point in the history
Both methods share a lot of code
  • Loading branch information
bgeuken committed Jul 7, 2016
1 parent fe60bf5 commit 32ccf33
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/api/app/helpers/maintenance_helper.rb
Expand Up @@ -307,7 +307,7 @@ def import_channel(channel, pkg, targetRepo = nil)
end

def instantiate_container(project, opackage, opts = {})
opkg = opackage.local_origin_container
opkg = opackage.origin_container
pkg_name = opkg.name
if opkg.is_a? Package and opkg.project.is_maintenance_release?
# strip incident suffix
Expand Down
Expand Up @@ -133,7 +133,7 @@ def set_acceptinfo(ai)
basePackageName = self.target_package.gsub(/\.[^\.]*$/, '')
pkg = Package.find_by_project_and_name( self.target_project, basePackageName )
if pkg
opkg = pkg.local_origin_container
opkg = pkg.origin_container
if opkg.name != self.target_package or opkg.project.name != self.target_project
ai['oproject'] = opkg.project.name
ai['opackage'] = opkg.name
Expand Down
40 changes: 12 additions & 28 deletions src/api/app/models/package.rb
Expand Up @@ -862,8 +862,9 @@ def build_result(repository, view = [])
Buildresult.find(project: self.project, package: self, repository: repository, view: view)
end

# first package in link chain outside of my project
def origin_container
# local mode (default): last package in link chain in my project
# no local mode: first package in link chain outside of my project
def origin_container(options = { local: true })
# no link, so I am origin
return self unless self.dir_hash

Expand All @@ -872,39 +873,22 @@ def origin_container
li = self.dir_hash['linkinfo']
return self unless li

# from external project, so it is my origin
prj = Project.get_by_name(li['project'])
pkg = prj.find_package(li['package'])
return pkg if self.project != prj

# broken or remote link, aborting
return nil if pkg.nil?

# local link, go one step deeper
return pkg.origin_container
end

# last package in link chain in my project
def local_origin_container
# no link, so I am origin
return self unless self.dir_hash

# link target package name is more important, since local name could be
# extended. for example in maintenance incident projects.
li = self.dir_hash['linkinfo']
return self unless li

# links to external project, so I am origin
return self if li['project'] != self.project.name
if options[:local]
# links to external project, so I am origin
return self if li['project'] != self.project.name
end

# local link, go one step deeper
prj = Project.get_by_name(li['project'])
pkg = prj.find_package(li['package'])
unless options[:local]
return pkg if self.project != prj
end

# broken or remote link, aborting
return nil if pkg.nil?

return pkg.local_origin_container
return pkg.origin_container(options)
end

def is_local_link?
Expand All @@ -927,7 +911,7 @@ def add_channels(mode = :add_disabled)
raise InvalidParameterError unless [:add_disabled, :skip_disabled, :enable_all].include? mode
return if self.is_channel?

opkg = self.origin_container
opkg = self.origin_container(local: false)
# remote or broken link?
return if opkg.nil?

Expand Down

0 comments on commit 32ccf33

Please sign in to comment.