aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabrice Bellingard <bellingard@gmail.com>2011-04-21 18:39:08 +0200
committerFabrice Bellingard <bellingard@gmail.com>2011-04-21 18:42:01 +0200
commit89a316ece8d0309596579dfb510c210fc022bc00 (patch)
treed6e81bd4999cf3551d5063372df476e51eaef5c0
parente8bf534ec680e583b0e7683c92f1be31ab66a74e (diff)
downloadsonarqube-89a316ece8d0309596579dfb510c210fc022bc00.tar.gz
sonarqube-89a316ece8d0309596579dfb510c210fc022bc00.zip
SONAR-2381 The "violations" web service API must return violations
decorated with review Ruby controller updated, need now to add the WS client part of it
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/api/reviews_controller.rb63
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/review.rb27
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb2
3 files changed, 92 insertions, 0 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
new file mode 100644
index 00000000000..d3d329a8afb
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/reviews_controller.rb
@@ -0,0 +1,63 @@
+#
+# Sonar, entreprise quality control tool.
+# Copyright (C) 2008-2011 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# Sonar is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# Sonar is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with Sonar; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+#
+
+require "json"
+
+class Api::ReviewsController < Api::ApiController
+
+ def index
+ @reviews = []
+ @reviews << Review.find ( params[:id] )
+
+ respond_to do |format|
+ format.json { render :json => jsonp(to_json) }
+ format.xml {render :xml => to_xml}
+ format.text { render :text => text_not_supported }
+ end
+ end
+
+ def to_xml
+ xml = Builder::XmlMarkup.new(:indent => 0)
+ xml.instruct!
+
+ xml.reviews do
+ @reviews.each do |review|
+ xml.review do
+ xml.id(review.id)
+ xml.updatedAt(review.updated_at)
+ xml.user(review.user.login)
+ xml.assignee(review.assignee.login)
+ xml.title(review.title)
+ xml.type(review.review_type)
+ xml.status(review.status)
+ xml.severity(review.severity)
+ xml.resourceLine(review.resource_line)
+
+ # Continue here with resource + violation + comments
+ end
+ end
+ end
+ end
+
+ def to_json
+ JSON(@reviews.collect{|review| review.to_hash_json(true)})
+ end
+
+end \ No newline at end of file
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 3849b2ec04b..4d5b6b5e443 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
@@ -61,4 +61,31 @@ class Review < ActiveRecord::Base
self.project=self.resource.project
end
end
+
+ def to_hash_json ( extended )
+ json = {}
+ json['id'] = id
+ json['updatedAt'] = updated_at
+ json['author'] = user.login
+ json['assignee'] = assignee.login if assignee
+ json['title'] = title
+ json['type'] = review_type
+ json['status'] = status
+ json['severity'] = severity
+ comments = []
+ review_comments.each do |comment|
+ comments << {
+ 'author' => comment.user.login,
+ 'updatedAt' => comment.updated_at,
+ 'comment' => comment.review_text
+ }
+ end
+ json['comments'] = comments
+ if ( extended )
+ json['line'] = resource_line if resource_line
+ json['resource'] = resource.kee if resource
+ end
+ json
+ end
+
end
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 cef150fef10..b284b305bcb 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
@@ -53,6 +53,8 @@ class RuleFailure < ActiveRecord::Base
:qualifier => snapshot.project.qualifier,
:language => snapshot.project.language
}
+ open_review = get_open_review
+ json['review'] = open_review.to_hash_json ( false ) if open_review
json
end