Skip to content

Commit

Permalink
[api] support lastsuccess on /build/$prj/_results
Browse files Browse the repository at this point in the history
This code may move later to the backend, so we high-jack a backend route
to do API code

If lastsuccess is given, it expects a package to check if it build against
a pathproject with a specific md5sum
  • Loading branch information
coolo committed Apr 16, 2013
1 parent 84e1026 commit ae15e3b
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/api/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def pass_to_backend( path = nil )
rescue_from APIException do |exception|
logger.debug "#{exception.class.name} #{exception.message}"
message = exception.message
if message.blank?
if message.blank? || message == exception.class.name
message = exception.default_message
end
render_error message: message, status: exception.status, errorcode: exception.errorcode
Expand Down
36 changes: 32 additions & 4 deletions src/api/app/controllers/build_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,21 +238,49 @@ def logfile
# for permission check
pkg = Package.get_by_project_and_name params[:project], params[:package], use_source: true, follow_project_links: true

if pkg.class == Package and pkg.project.disabled_for?('binarydownload', params[:repository], params[:arch]) and not @http_user.can_download_binaries?(pkg.project)
render_error :status => 403, :errorcode => "download_binary_no_permission",
:message => "No permission to download binaries from package #{params[:package]}, project #{params[:project]}"
if pkg.class == Package and pkg.project.disabled_for?('binarydownload', params[:repository], params[:arch]) and
not @http_user.can_download_binaries?(pkg.project)
render_error status: 403, errorcode: "download_binary_no_permission",
message: "No permission to download binaries from package #{params[:package]}, project #{params[:project]}"
return
end

pass_to_backend
end


def result
valid_http_methods :get
required_parameters :project
# for permission check
Project.get_by_name params[:project]

if params.has_key? :lastsuccess
required_parameters :package

outputxml = "<status>\n"
pkg = Package.get_by_project_and_name params[:project], params[:package],
use_source: false, follow_project_links: false

# might be nil
tprj = Project.find_by_name params[:pathproject]
result = pkg.buildstatus(target_project: tprj, srcmd5: params[:srcmd5])
result.each do |repo, status|
outputxml << " <repository name='#{repo}'>\n"
status.each do |arch, archstat|
outputxml << " <arch arch='#{arch}' result='#{archstat[:result]}'"
outputxml << " missing='#{archstat[:missing]}'" if archstat[:missing]
outputxml << "/> \n"
end
outputxml << " </repository>\n"

end
outputxml << "</status>\n"
render text: outputxml
return
end

pass_to_backend
end

end
end
11 changes: 8 additions & 3 deletions src/api/app/models/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ def valid_name
end

class NoRepositoriesFound < APIException
setup "No repositories build against target", 404
setup 404, "No repositories build against target"
end

class FailedToRetrieveBuildInfo < APIException
Expand All @@ -1018,7 +1018,12 @@ def buildstatus(opts)
csrcmd5 = nil
end

tocheck_repos = self.project.repositories_linking_project(tproj, ActiveXML.transport)
if tproj
tocheck_repos = self.project.repositories_linking_project(tproj, ActiveXML.transport)
else
tocheck_repos = self.project.repositories
end

raise NoRepositoriesFound.new if tocheck_repos.empty?

output = {}
Expand Down Expand Up @@ -1135,4 +1140,4 @@ def buildstatus(opts)
output
end

end
end
8 changes: 4 additions & 4 deletions src/api/lib/api_exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ class APIException < Exception
def self.abstract_class?
true
end

class << self
@errorcode = nil
@status = 400
@default_message = nil

def setup(setvalue, status = nil, message = nil)
def setup(setvalue, _status = nil, message = nil)
if setvalue.is_a? String
@errorcode = setvalue
@status = status || 400
@status = _status || 400
@default_message = message
else # support having the status first
@status = setvalue
@default_message = status
@default_message = _status
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions src/api/test/functional/build_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ def test_result
get "/build/home:Iggy/_result"
assert_response :success
assert_xml_tag :tag => "resultlist", :children => { :count => 2 }

get "/build/home:Iggy/_result?lastsuccess&pathproject=kde4&package=TestPack"
assert_response 404
assert_xml_tag(:tag => "status", :attributes => { :code => 'no_repositories_found' })
end

def test_read_access_hidden_result_prj
Expand Down
5 changes: 2 additions & 3 deletions src/api/test/functional/status_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ def test_project_status

def test_bsrequest
get "/status/bsrequest?id=997"
assert_match(%r{<status id='997' code='error'>Can't find project NotExisitingk</status>}, @response.body)
assert_response :success

assert_xml_tag(:tag => "status", :attributes => {:code => 'not_found'})
assert_response 404
end

def test_history
Expand Down
3 changes: 2 additions & 1 deletion src/api/test/unit/code_quality_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def test_static_ruby_syntax
lines = File.open(ruby_file).read
begin
io.write(lines)
io.write("\n")
rescue Errno::EPIPE
end
end
Expand All @@ -33,7 +34,7 @@ def test_static_ruby_syntax
line = tmpfile.read
tmpfile.close
return if line.empty?
puts "ruby -cv gave output: testing syntax of each ruby file..."
puts "ruby -cv gave output: testing syntax of each ruby file... #{line}"
@ruby_files.each do |ruby_file|
IO.popen("ruby -cv #{ruby_file} 2>&1 > /dev/null | grep #{Rails.root}") do |io|
line = io.read
Expand Down

0 comments on commit ae15e3b

Please sign in to comment.