Skip to content

Commit

Permalink
[api] fix release of package where source is remote or scmsync'd
Browse files Browse the repository at this point in the history
This creates a temporary package object which is not stored. We may
track remote package objects in future but for now this temporary
object seems to be the way to go.
  • Loading branch information
adrianschroeter committed Aug 14, 2024
1 parent 9b8ce27 commit d5dceb6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
9 changes: 9 additions & 0 deletions src/api/app/controllers/source_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,15 @@ def package_command_release
follow_project_scmsync_links: true)
multibuild_container = Package.multibuild_flavor(params[:package])

if pkg.nil?
prj = Project.get_by_name(params[:project])
pkg = prj.packages.new(name: Package.striping_multibuild_suffix(params[:package]))
meta = Xmlhash.parse(Backend::Api::Sources::Package.meta(prj.name, pkg.name))
pkg.read_from_xml(meta)
pkg.readonly!
# no pkg.store
end

# uniq timestring for all targets
time_now = Time.now.utc

Expand Down
16 changes: 6 additions & 10 deletions src/api/app/models/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -724,22 +724,13 @@ def update_from_xml(xmlhash, ignore_lock = nil)
check_write_access!(ignore_lock)

Package.transaction do
assign_attributes_from_from_xml(xmlhash)

assign_devel_package_from_xml(xmlhash)
read_from_xml(xmlhash)

# just for cycle detection
resolve_devel_package

update_relationships_from_xml(xmlhash)

#---begin enable / disable flags ---#
update_all_flags(xmlhash)

#--- update url ---#
self.url = xmlhash.value('url')
#--- end update url ---#

save!
end
end
Expand Down Expand Up @@ -769,6 +760,11 @@ def assign_devel_package_from_xml(xmlhash)
self.develpackage = devel_package
end

def read_from_xml(xmlhash)
assign_attributes_from_from_xml(xmlhash)
assign_devel_package_from_xml(xmlhash)
end

def store(opts = {})
# no write access check here, since this operation may will disable this permission ...
self.commit_opts = opts if opts
Expand Down
19 changes: 18 additions & 1 deletion src/api/app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1106,13 +1106,29 @@ def do_project_release(params)
User.find_by!(login: params[:user]).run_as do
comment = "Project release by #{User.session.login}"

# get current package list from backend
if scmsync.present? || links_to_remote?
directory = Backend::Api::Sources::Project.packages(name)
xml=Xmlhash.parse(directory)
xml.elements('entry').each do |e|
next if e['name'].include? ':'
meta = Xmlhash.parse(Backend::Api::Sources::Package.meta(name, e['name']))
pkg = packages.new(name: e['name'])
pkg.read_from_xml(meta)
pkg.readonly!
end
end

# uniq timestring for all targets
time_now = Time.now.utc

# ensure to process all of them at once
suspend_scheduler(comment)

packages.each do |pkg|
next if pkg.name == '_product' # will be handled via _product:*

pkg.project.repositories.each do |repo|
repositories.each do |repo|
repo.release_targets.each do |releasetarget|
# release source and binaries
# permission checking happens inside this function
Expand All @@ -1126,6 +1142,7 @@ def do_project_release(params)
end
end
end
resume_scheduler(comment)
end
end

Expand Down
6 changes: 5 additions & 1 deletion src/api/app/models/token/release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ class Token::Release < Token

def call(options)
set_triggered_at
return unless options[:package]

# uniq timestring for all targets
time_now = Time.now.utc

package_to_release = options[:package]
if package_to_release.is_a?(String)
package_to_release = options[:project].packages.new(name: Package.striping_multibuild_suffix(options[:package]))
meta = Xmlhash.parse(Backend::Api::Sources::Package.meta(options[:project].name, package_to_release.name))
package_to_release.read_from_xml(meta)
end
if options[:targetproject].present? && options[:targetrepository].present? && options[:filter_source_repository].present?
source_repository = Repository.find_by_project_and_name(options[:project].name, options[:filter_source_repository])
target_repository = Repository.find_by_project_and_name(options[:targetproject], options[:targetrepository])
Expand Down

0 comments on commit d5dceb6

Please sign in to comment.