aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorFabrice Bellingard <bellingard@gmail.com>2011-04-28 08:50:54 +0200
committerFabrice Bellingard <bellingard@gmail.com>2011-04-28 15:15:49 +0200
commitc3fabd05ae340704746d2b3be87b584bdd0da475 (patch)
treedab8469d0b567c7b34cd8a87498cbf974b173ad5 /sonar-server
parent50a43f7b9dab293b61fabe742252dca659f2e4ca (diff)
downloadsonarqube-c3fabd05ae340704746d2b3be87b584bdd0da475.tar.gz
sonarqube-c3fabd05ae340704746d2b3be87b584bdd0da475.zip
SONAR-2382 Create a new "reviews" web service API
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/api/reviews_controller.rb25
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb4
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/review.rb29
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_violation_false_positive_form.html.erb1
4 files changed, 47 insertions, 12 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 a8f050e6dfa..bcce88cc58c 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
@@ -46,17 +46,25 @@ class Api::ReviewsController < Api::ApiController
reviews.each do |review|
xml.review do
xml.id(review.id.to_i)
+ xml.createdAt(format_datetime(review.created_at))
xml.updatedAt(format_datetime(review.updated_at))
xml.user(review.user.login)
- xml.assignee(review.assignee.login)
+ xml.assignee(review.assignee.login) if review.assignee
xml.title(review.title)
xml.type(review.review_type)
xml.status(review.status)
xml.severity(review.severity)
xml.resource(review.resource.kee) if review.resource
- xml.line(review.resource_line) if review.resource_line
-
- # Continue here with resource + comments
+ xml.line(review.resource_line) if review.resource_line > 0
+ xml.comments do
+ review.review_comments.each do |comment|
+ xml.comment do
+ xml.author(comment.user.login)
+ xml.updatedAt(format_datetime(comment.updated_at))
+ xml.text(convert_markdown ? markdown_to_html(comment.review_text): comment.review_text)
+ end
+ end
+ end
end
end
end
@@ -69,24 +77,25 @@ class Api::ReviewsController < Api::ApiController
def review_to_json(review, html=false)
json = {}
json['id'] = review.id.to_i
- json['updatedAt'] = review.updated_at
+ json['createdAt'] = format_datetime(review.created_at)
+ json['updatedAt'] = format_datetime(review.updated_at)
json['author'] = review.user.login
json['assignee'] = review.assignee.login if review.assignee
json['title'] = review.title if review.title
json['type'] = review.review_type
json['status'] = review.status
json['severity'] = review.severity
+ json['resource'] = review.resource.kee if review.resource
+ json['line'] = review.resource_line if review.resource_line > 0
comments = []
review.review_comments.each do |comment|
comments << {
'author' => comment.user.login,
'updatedAt' => format_datetime(comment.updated_at),
- 'comment' => (html ? markdown_to_html(comment.review_text): comment.review_text)
+ 'text' => (html ? markdown_to_html(comment.review_text): comment.review_text)
}
end
json['comments'] = comments
- json['line'] = review.resource_line if review.resource_line
- json['resource'] = review.resource.kee if review.resource
json
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb
index abaa6e11c24..69848be04e1 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb
@@ -292,6 +292,10 @@ class ReviewsController < ApplicationController
conditions << "status in (:statuses)"
values[:statuses]=@statuses
end
+ unless @projects == [""]
+ conditions << "project_id in (:projects)"
+ values[:projects]=@projects
+ end
unless @severities == [""]
conditions << "severity in (:severities)"
values[:severities]=@severities
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 f6d7bdc0939..88deba8df15 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
@@ -50,9 +50,18 @@ class Review < ActiveRecord::Base
end
def self.search(options={})
- conditions=['review_type<>:not_type']
- values={:not_type => Review::TYPE_FALSE_POSITIVE}
-
+ conditions=[]
+ values={}
+
+ review_type = options['review_type']
+ if review_type
+ conditions << "review_type=:type"
+ values[:type] = review_type.upcase
+ else
+ conditions=['review_type<>:not_type']
+ values={:not_type => Review::TYPE_FALSE_POSITIVE}
+ end
+
ids=options['ids']
if options[:id]
conditions << "id=:id"
@@ -68,6 +77,18 @@ class Review < ActiveRecord::Base
values[:statuses]=statuses
end
+ projects=options['projects']
+ if projects && projects.size>0 && !projects[0].blank?
+ conditions << "project_id in (:projects)"
+ values[:projects]=projects
+ end
+
+ resources=options['resources']
+ if resources && resources.size>0 && !resources[0].blank?
+ conditions << "resource_id in (:resources)"
+ values[:resources]=resources
+ end
+
severities=options['severities']
if severities && severities.size>0 && !severities[0].blank?
conditions << "severity in (:severities)"
@@ -86,7 +107,7 @@ class Review < ActiveRecord::Base
values[:assignees]=User.logins_to_ids(assignees)
end
- Review.find(:all, :order => "created_at DESC", :conditions => [conditions.join(" AND "), values], :limit => 200)
+ Review.find(:all, :include => [ 'review_comments' ], :order => "created_at DESC", :conditions => [conditions.join(" AND "), values], :limit => 200)
end
private
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_violation_false_positive_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_violation_false_positive_form.html.erb
index f0e5574fd22..e78ea5e7dd8 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_violation_false_positive_form.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_violation_false_positive_form.html.erb
@@ -15,5 +15,6 @@
<h3><%= title -%></h3>
<textarea id="commentText<%= params[:id] -%>" rows="8" name="comment" style="width: 100%" onkeyup="if (this.value=='') $('submit_btn').disabled='true'; else $('submit_btn').disabled='';"></textarea>
<%= submit_to_remote "submit_btn", button, :url => { :action => 'violation_flag_as_false_positive' }, :html => { :id => "submit_btn", :disabled => "true" }, :update => 'vId'+params[:id] -%>
+ &nbsp;
<%= link_to_remote 'Cancel', :url => {:action => 'display_violation', :id => params[:id]}, :update => 'vId' + params[:id] -%>
</form>