Skip to content

Commit

Permalink
[api] create patchinfo on maintenance_incident accept, if source proj…
Browse files Browse the repository at this point in the history
…ect did not provide one
  • Loading branch information
adrianschroeter committed Jan 23, 2012
1 parent abfa2c9 commit 2729bef
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/api/app/controllers/request_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,7 @@ def command_changestate
# permission granted for the request at this point

# special command defining an incident to be merged
check_for_patchinfo = false
req.each_action do |action|
incident_project = nil
if action.value("type") == "maintenance_incident"
Expand All @@ -1316,6 +1317,7 @@ def command_changestate
unless incident_project
source = DbProject.get_by_name(action.source.project)
incident_project = create_new_maintenance_incident(tprj, source, req ).db_project
check_for_patchinfo = true
end
unless incident_project.name.start_with?(tprj.name)
render_error :status => 404, :errorcode => "multiple_maintenance_incidents",
Expand Down Expand Up @@ -1508,6 +1510,33 @@ def command_changestate
action.target.set_attribute("project", incident_project.name)
req.save

# create a patchinfo if missing and incident has just been created
if check_for_patchinfo
unless DbPackage.find_by_project_and_kind incident_project.name, "patchinfo"
patchinfo = DbPackage.new(:name => "patchinfo", :title => "Patchinfo", :description => "Collected packages for update")
incident_project.db_packages << patchinfo
patchinfo.add_flag("build", "enable", nil, nil)
patchinfo.store

# create patchinfo XML file
node = Builder::XmlMarkup.new(:indent=>2)
xml = node.patchinfo() do |n|
node.packager req.creator
node.category "recommended"
node.rating "low"
node.summary req.description
node.description req.description
end
data = ActiveXML::Base.new(node.target!)
# xml = update_patchinfo( data, pkg )
p={ :user => @http_user.login, :comment => "generated by request id #{req.id} accept call" }
patchinfo_path = "/source/#{CGI.escape(patchinfo.db_project.name)}/patchinfo/_patchinfo"
patchinfo_path << build_query_from_hash(p, [:user, :comment])
backend_put( patchinfo_path, data.dump_xml )
patchinfo.sources_changed
end
end

elsif action.value("type") == "maintenance_release"
pkg = DbPackage.get_by_project_and_name(action.source.project, action.source.package)
#FIXME2.5: support limiters to specified repositories
Expand Down
15 changes: 15 additions & 0 deletions src/api/app/models/db_package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,21 @@ def find_by_project_and_name( project, package )
return ret
end

def find_by_project_and_kind( project, kind )
sql =<<-END_SQL
SELECT pack.*
FROM db_packages pack
LEFT OUTER JOIN db_projects pro ON pack.db_project_id = pro.id
LEFT OUTER JOIN db_package_kinds kinds ON kinds.db_package_id = pack.id
WHERE pro.name = BINARY ? AND kinds.kind = BINARY ?
END_SQL

result = DbPackage.find_by_sql [sql, project.to_s, kind.to_s]
ret = result[0]
return nil unless DbPackage.check_access?(ret)
return ret
end

def find_by_attribute_type( attrib_type, package=nil )
# One sql statement is faster than a ruby loop
# attribute match in package or project
Expand Down
8 changes: 8 additions & 0 deletions src/api/test/functional/maintenance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def test_mbranch_and_maintenance_per_package_request
<sourceupdate>cleanup</sourceupdate>
</options>
</action>
<description>To fix my bug</description>
<state name="new" />
</request>'
assert_response :success
Expand Down Expand Up @@ -188,6 +189,7 @@ def test_mbranch_and_maintenance_per_package_request
</options>
</action>
<state name="new" />
<description>To fix my other bug</description>
</request>'
assert_response :success
assert_tag( :tag => "target", :attributes => { :project => "My:Maintenance" } )
Expand Down Expand Up @@ -223,6 +225,12 @@ def test_mbranch_and_maintenance_per_package_request
maintenanceNotNewProject=data.elements["/request/action/target"].attributes.get_attribute("project").to_s
assert_equal maintenanceProject, maintenanceNotNewProject

# no patchinfo was part in source project, got it created ?
get "/source/#{maintenanceProject}/patchinfo/_patchinfo"
assert_response :success
assert_tag :tag => 'packager', :content => "tom"
assert_tag :tag => 'description', :content => "To fix my bug"

#validate cleanup
get "/source/home:tom:branches:OBS_Maintained:pack2"
assert_response 404
Expand Down

0 comments on commit 2729bef

Please sign in to comment.