diff options
4 files changed, 60 insertions, 27 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 a18a26f72bc..b75d8a1048b 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 @@ -27,6 +27,20 @@ class Api::ReviewsController < Api::ApiController verify :method => :post, :only => [ :create ] #verify :method => :delete, :only => [ :destroy ] + # + # --- Search reviews --- + # Since 2.8 + # + # GET /api/reviews + # Optional parameters : + # - 'statuses' + # - 'resolutions' (since 2.9) + # - 'severities' + # - 'projects' + # - 'resources' + # - 'authors' + # - 'assignees' + # def index reviews=select_authorized(:user, Review.search(params), :project) @@ -35,6 +49,7 @@ class Api::ReviewsController < Api::ApiController # # --- Creation of a review --- + # Since 2.9 # # POST /api/reviews # Required parameters: @@ -105,6 +120,7 @@ class Api::ReviewsController < Api::ApiController # # --- Add comment --- + # Since 2.9 # # PUT /api/reviews/add_comment # Required parameters: @@ -135,6 +151,7 @@ class Api::ReviewsController < Api::ApiController # # --- Reassign --- + # Since 2.9 # # PUT /api/reviews/reassign # Required parameters: @@ -171,6 +188,7 @@ class Api::ReviewsController < Api::ApiController # # --- Resolve --- + # Since 2.9 # # PUT /api/reviews/resolve # Required parameters: @@ -212,6 +230,7 @@ class Api::ReviewsController < Api::ApiController # # --- Reopen --- + # Since 2.9 # # PUT /api/reviews/reopen # Required parameters: 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 b978aff15c0..9d820401d0d 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 @@ -176,14 +176,24 @@ class Review < ActiveRecord::Base end end # --- End of code for backward compatibility code --- - + + # --- For UI false_positives = options['false_positives'] if false_positives == "only" conditions << "resolution='FALSE-POSITIVE'" elsif false_positives == "without" conditions << "(resolution<>'FALSE-POSITIVE' OR resolution IS NULL)" end - + # --- End + + # --- For web-service + resolutions = options['resolutions'].split(',') if options['resolutions'] + if resolutions && resolutions.size>0 && !resolutions[0].blank? + conditions << 'resolution in (:resolutions)' + values[:resolutions] = resolutions + end + # --- End + ids=options['ids'].split(',') if options['ids'] if options['id'] conditions << 'id=:id' diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewQuery.java index 07cc0da834e..0892ed83e82 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewQuery.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewQuery.java @@ -43,7 +43,7 @@ public class ReviewQuery extends Query<Review> { private String[] authorLoginsOrIds; private String[] assigneeLoginsOrIds; private String output; - private String falsePositives; + private String[] resolutions; public ReviewQuery() { } @@ -215,28 +215,16 @@ public class ReviewQuery extends Query<Review> { /** * @since 2.9 - * @return the false_positives */ - public String getFalsePositives() { - return falsePositives; + public String[] getResolutions() { + return resolutions; } /** - * Sets the 'false_positives' parameter that can be: - * <ul> - * <li>only</li> - * <li>with</li> - * <li>without</li> - * </ul> - * , 'with' being the default one on the server side. <br> - * <br> - * * @since 2.9 - * @param falsePositives - * the false_positives */ - public ReviewQuery setFalsePositives(String falsePositives) { - this.falsePositives = falsePositives; + public ReviewQuery setResolutions(String... resolutions) { + this.resolutions = resolutions; return this; } @@ -256,8 +244,8 @@ public class ReviewQuery extends Query<Review> { appendUrlParameter(url, "authors", authorLoginsOrIds); appendUrlParameter(url, "assignees", assigneeLoginsOrIds); appendUrlParameter(url, "output", output); - appendUrlParameter(url, "false_positives", falsePositives); - if (falsePositives == null && reviewType != null) { + appendUrlParameter(url, "resolutions", resolutions); + if (resolutions == null && reviewType != null) { // Use of the 2.8 deprecated API: handle backward compatibility appendUrlParameter(url, "review_type", reviewType); } diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ReviewQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ReviewQueryTest.java index ddb58c41d83..18fec4bc693 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ReviewQueryTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ReviewQueryTest.java @@ -29,7 +29,7 @@ import org.junit.Test; public class ReviewQueryTest extends QueryTestCase { @Test - public void testSimpleQueryForResource() { + public void queryForResource() { Resource resource = mock(Resource.class); when(resource.getId()).thenReturn(69); ReviewQuery query = ReviewQuery.createForResource(resource); @@ -38,14 +38,30 @@ public class ReviewQueryTest extends QueryTestCase { } @Test + public void queryById() { + assertThat(new ReviewQuery().setId(13L).getUrl(), is("/api/reviews?id=13&")); + assertThat(new ReviewQuery().setIds(10L, 11L).getUrl(), is("/api/reviews?ids=10,11&")); + } + + @Test + public void queryByResolution() { + ReviewQuery query = new ReviewQuery().setStatuses("RESOLVED").setResolutions("FALSE-POSITIVE"); + assertThat(query.getUrl(), is("/api/reviews?statuses=RESOLVED&resolutions=FALSE-POSITIVE&")); + } + + @Test public void resourceTreeViolations() { - ReviewQuery query = new ReviewQuery(); - query.setIds(10L, 11L).setStatuses("OPEN").setSeverities("MINOR", "INFO").setProjectKeysOrIds("com.sonar.foo:bar") - .setResourceKeysOrIds("2", "3").setAuthorLoginsOrIds("20").setAssigneeLoginsOrIds("admin").setOutput("html") - .setFalsePositives("without"); + ReviewQuery query = new ReviewQuery() + .setStatuses("OPEN") + .setSeverities("MINOR", "INFO") + .setProjectKeysOrIds("com.sonar.foo:bar") + .setResourceKeysOrIds("2", "3") + .setAuthorLoginsOrIds("20") + .setAssigneeLoginsOrIds("admin") + .setOutput("html"); assertThat( query.getUrl(), - is("/api/reviews?ids=10,11&statuses=OPEN&severities=MINOR,INFO&projects=com.sonar.foo%3Abar&resources=2,3&authors=20&assignees=admin&output=html&false_positives=without&")); + is("/api/reviews?statuses=OPEN&severities=MINOR,INFO&projects=com.sonar.foo%3Abar&resources=2,3&authors=20&assignees=admin&output=html&")); } @Test |