Skip to content

Commit

Permalink
[api] add importchannel function
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianschroeter committed Mar 26, 2014
1 parent 42cce39 commit c801621
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
13 changes: 13 additions & 0 deletions docs/api/api/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,19 @@ Parameters:
XmlResult: status


POST /source/<project>/<package>?cmd=importchannel

Import a kiwi channel file for OBS. Project names will be set
to update projects if defined.

Parameters:

target_project: optional target repository to set
target_repository: optional target repository to set

XmlResult: status


POST /source/<project>/<package>?deleteuploadrev

Removes all changes made to the upload revision and reverts to last revision
Expand Down
12 changes: 11 additions & 1 deletion src/api/app/controllers/source_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def package_command
# valid post commands
valid_commands=%w(diff branch servicediff linkdiff showlinked copy remove_flag set_flag rebuild undelete
wipe runservice commit commitfilelist createSpecFileTemplate deleteuploadrev linktobranch
updatepatchinfo getprojectservices unlock release)
updatepatchinfo getprojectservices unlock release importchannel)

@command = params[:cmd]
raise IllegalRequest.new 'invalid_command' unless valid_commands.include?(@command)
Expand Down Expand Up @@ -1270,6 +1270,16 @@ def package_command_updatepatchinfo
render_ok
end

# POST /source/<project>/<package>?cmd=importchannel
def package_command_importchannel
repo=nil
repo=Repository.find_by_project_and_repo_name(params[:target_project], params[:target_repository]) if params[:target_project]

import_channel(request.raw_post, @package, repo)

render_ok
end

class NotLocked < APIException; end

# unlock a package
Expand Down
28 changes: 28 additions & 0 deletions src/api/app/helpers/maintenance_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,32 @@ def create_package_container_if_missing(sourcePackage, targetPackageName, target
tpkg
end

def import_channel(channel, pkg, targetRepo=nil)
channel = REXML::Document.new(channel)

This comment has been minimized.

Copy link
@coolo

coolo Mar 26, 2014

Member

can you please not use rexml? we have xmlhash and activexml, we don't need a 3rd api ;(

if targetRepo
channel.elements['/channel'].add_element 'target', {
"project" => targetRepo.project.name,
"repository" => targetRepo.name
}
end

# replace all project definitions with update projects, if they are defined
[ '//binaries', '//binary' ].each do |bin|
channel.get_elements(bin).each do |b|
if attrib = b.attributes.get_attribute('project') and prj = Project.get_by_name(attrib.to_s)
if a = prj.find_attribute('OBS', 'UpdateProject') and a.values[0]
b.attributes["project"] = a.values[0]
end
end
end
end

query = { user: User.current ? User.current.login : '_nobody_' }
query[:comment] = "channel import function"
Suse::Backend.put_source(pkg.source_path('_channel', query), channel.to_s)

pkg.sources_changed
end

end
9 changes: 6 additions & 3 deletions src/api/test/functional/maintenance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -437,17 +437,20 @@ def test_mbranch_and_maintenance_per_package_request
# create channel package
put '/source/Channel/BaseDistro3/_meta', '<package project="Channel" name="BaseDistro3"><title/><description/></package>'
assert_response :success
put '/source/Channel/BaseDistro3/_channel', '<?xml version="1.0" encoding="UTF-8"?>
post '/source/Channel/BaseDistro3?cmd=importchannel&target_project=BaseDistro3Channel&target_repository=channel_repo', '<?xml version="1.0" encoding="UTF-8"?>
<channel>
<target project="BaseDistro3Channel" repository="channel_repo" />
<binaries project="BaseDistro3" repository="BaseDistro3_repo" arch="i586">
<binary name="package" package="pack2.linked" project="BaseDistro2.0" />
</binaries>
</channel>'
assert_response :success
get '/source/Channel/BaseDistro3/_channel'
assert_response :success
assert_xml_tag :tag => 'binary', :attributes => { :project => 'BaseDistro2.0', :package => 'pack2.linked'}
# it found the update project
assert_xml_tag :tag => 'binary', :attributes => { :project => 'BaseDistro2.0:LinkedUpdateProject', :package => 'pack2.linked'}
# target repo parameter worked
assert_xml_tag :tag => 'target', :attributes => { :project => 'BaseDistro3Channel', :repository => 'channel_repo'}

put '/source/Channel/BaseDistro3/_channel', '<?xml version="1.0" encoding="UTF-8"?>
<channel>
<target project="BaseDistro3Channel" repository="channel_repo" tag="UpdateInfoTag-" />
Expand Down

0 comments on commit c801621

Please sign in to comment.