diff options
author | Fabrice Bellingard <bellingard@gmail.com> | 2011-05-04 16:53:02 +0200 |
---|---|---|
committer | Fabrice Bellingard <bellingard@gmail.com> | 2011-05-04 16:53:02 +0200 |
commit | 1ae9da926fecb5e2eac4bb9f2f21c60db30320b4 (patch) | |
tree | 6eaa5ee7c401c52a75db7fa06cbdf590b2cac186 /sonar-server | |
parent | 1d3bedbab5cc4c5051db2b1781d43d1a7b68395f (diff) | |
download | sonarqube-1ae9da926fecb5e2eac4bb9f2f21c60db30320b4.tar.gz sonarqube-1ae9da926fecb5e2eac4bb9f2f21c60db30320b4.zip |
SONAR-2381, SONAR-2382 Web services return comment in HTML by default
Available for the Violation and Review WS:
- parameter 'output' on the request
- if set to 'html', comments are returned in HTML
- otherwise comments are returned as raw text
- Java WS client updated consequently
Diffstat (limited to 'sonar-server')
4 files changed, 23 insertions, 16 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/reviews_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/reviews_controller.rb index ad85564b11b..b178a345f5c 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/reviews_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/reviews_controller.rb @@ -23,11 +23,12 @@ require 'json' class Api::ReviewsController < Api::ApiController def index + convert_markdown=(params[:output]=='html') reviews=select_authorized(:user, Review.search(params), :project) respond_to do |format| - format.json { render :json => jsonp(Review.reviews_to_json(reviews)) } - format.xml {render :xml => Review.reviews_to_xml(reviews)} + format.json { render :json => jsonp(Review.reviews_to_json(reviews, convert_markdown)) } + format.xml {render :xml => Review.reviews_to_xml(reviews, convert_markdown)} format.text { render :text => text_not_supported } end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/violations_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/violations_controller.rb index 55a8198579a..a22223d549d 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/violations_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/violations_controller.rb @@ -93,16 +93,18 @@ class Api::ViolationsController < Api::ResourceRestController def rest_to_json(rule_failures) include_review=(params['include_review']=='true') - JSON(rule_failures.collect{|rule_failure| rule_failure.to_json(include_review)}) + convert_markdown=(params[:output]=='html') + JSON(rule_failures.collect{|rule_failure| rule_failure.to_json(include_review, convert_markdown)}) end def rest_to_xml(rule_failures) include_review=(params['include_review']=='true') + convert_markdown=(params[:output]=='html') xml = Builder::XmlMarkup.new(:indent => 0) xml.instruct! xml.violations do rule_failures.each do |rule_failure| - rule_failure.to_xml(xml, include_review) + rule_failure.to_xml(xml, include_review, convert_markdown) end end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb index 3a45ff5b0ed..6d5af841492 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb @@ -128,17 +128,17 @@ class Review < ActiveRecord::Base Review.find(:all, :include => [ 'review_comments' ], :order => 'created_at DESC', :conditions => [conditions.join(' AND '), values], :limit => 200) end - def self.reviews_to_xml(reviews) + def self.reviews_to_xml(reviews, convert_markdown=false) xml = Builder::XmlMarkup.new(:indent => 0) xml.instruct! xml.reviews do reviews.each do |review| - review.to_xml(xml) + review.to_xml(xml, convert_markdown) end end end - def to_xml(xml) + def to_xml(xml, convert_markdown=false) xml.review do xml.id(id.to_i) xml.createdAt(Api::Utils.format_datetime(created_at)) @@ -156,18 +156,22 @@ class Review < ActiveRecord::Base xml.comment do xml.author(comment.user.login) xml.updatedAt(Api::Utils.format_datetime(comment.updated_at)) - xml.text(comment.html_text) + if convert_markdown + xml.text(comment.html_text) + else + xml.text(comment.review_text) + end end end end end end - def self.reviews_to_json(reviews) - JSON(reviews.collect{|review| review.to_json()}) + def self.reviews_to_json(reviews, convert_markdown=false) + JSON(reviews.collect{|review| review.to_json(convert_markdown)}) end - def to_json + def to_json(convert_markdown=false) json = {} json['id'] = id.to_i json['createdAt'] = Api::Utils.format_datetime(created_at) @@ -185,7 +189,7 @@ class Review < ActiveRecord::Base comments << { 'author' => comment.user.login, 'updatedAt' => Api::Utils.format_datetime(comment.updated_at), - 'text' => comment.html_text + 'text' => convert_markdown ? comment.html_text : comment.review_text } end json['comments'] = comments diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb index 30615035a46..9842e8dfbb7 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb @@ -44,7 +44,7 @@ class RuleFailure < ActiveRecord::Base end end - def to_json(include_review=false) + def to_json(include_review=false, convert_markdown=false) json = {} json['message'] = message json['line'] = line if line && line>=1 @@ -64,11 +64,11 @@ class RuleFailure < ActiveRecord::Base :qualifier => snapshot.project.qualifier, :language => snapshot.project.language } - json['review'] = review.to_json if include_review && review + json['review'] = review.to_json(convert_markdown) if include_review && review json end - def to_xml(xml=Builder::XmlMarkup.new(:indent => 0), include_review=false) + def to_xml(xml=Builder::XmlMarkup.new(:indent => 0), include_review=false, convert_markdown=false) xml.violation do xml.message(message) xml.line(line) if line && line>=1 @@ -88,7 +88,7 @@ class RuleFailure < ActiveRecord::Base xml.qualifier(snapshot.project.qualifier) xml.language(snapshot.project.language) end - review.to_xml(xml) if include_review && review + review.to_xml(xml, convert_markdown) if include_review && review end end |