Skip to content
Permalink
Browse files
Merge branch 'JENKINS-31004'
Conflicts:
	src/main/java/org/jenkinsci/plugins/sonargerrit/SonarToGerritBuilder.java
	src/test/java/org/jenkinsci/plugins/sonargerrit/SonarToGerritBuilderTest.java
  • Loading branch information
aquarellian committed Oct 21, 2015
2 parents 40a6624 + 561ef1f commit 5588d421064ea76805024897496ce0e082ebf907
@@ -13,7 +13,6 @@
import com.google.gerrit.extensions.common.FileInfo;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.sonyericsson.hudson.plugins.gerrit.trigger.GerritManagement;
import com.sonyericsson.hudson.plugins.gerrit.trigger.VerdictCategory;
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.IGerritHudsonTriggerConfig;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger;
import com.urswolfer.gerrit.client.rest.GerritAuthData;
@@ -249,14 +248,14 @@ public boolean apply(@Nullable String input) {
}

// Step 6 - Send review to Gerrit
Collection<String> categoryNames = getCategoryNames(gerritConfig.getCategories());
ReviewInput reviewInput = getReviewResult(file2issues, categoryNames);
ReviewInput reviewInput = getReviewResult(file2issues);

// Step 7 - Post review
revision.review(reviewInput);
LOGGER.log(Level.INFO, "Review has been sent");
} catch (RestApiException e) {
LOGGER.severe(e.getMessage());
listener.getLogger().println("Unable to post review: " + e.getMessage());
LOGGER.severe("Unable to post review: " + e.getMessage());
return false;
}

@@ -303,7 +302,7 @@ private int parseNumber(String number, int deflt) {
}

@VisibleForTesting
ReviewInput getReviewResult(Multimap<String, Issue> finalIssues, Collection<String> existingCategories) {
ReviewInput getReviewResult(Multimap<String, Issue> finalIssues) {
String reviewMessage = getReviewMessage(finalIssues);
ReviewInput reviewInput = new ReviewInput().message(reviewMessage);

@@ -312,8 +311,7 @@ ReviewInput getReviewResult(Multimap<String, Issue> finalIssues, Collection<Stri
reviewInput.notify = getNotificationSettings(finalIssuesCount);

if (postScore) {
String realCategory = getRealCategory(existingCategories);
reviewInput.label(realCategory, getReviewMark(finalIssuesCount));
reviewInput.label(category, getReviewMark(finalIssuesCount));
}

reviewInput.comments = new HashMap<String, List<ReviewInput.CommentInput>>();
@@ -342,19 +340,6 @@ ReviewInput getReviewResult(Multimap<String, Issue> finalIssues, Collection<Stri
return reviewInput;
}

private Collection<String> getCategoryNames(List<VerdictCategory> categories) {
Set<String> availableCategories = new HashSet<String>();
for (VerdictCategory verdictCategory : categories) {
availableCategories.add(verdictCategory.getVerdictDescription());
}
return availableCategories;
}

protected String getRealCategory(Collection<String> categories) {
// todo notify user about switching category to default?
return categories.contains(category) ? category : DEFAULT_CATEGORY;
}

@VisibleForTesting
void filterIssuesByChangedLines(Multimap<String, Issue> finalIssues, RevisionApi revision) throws RestApiException {
for (String filename : new HashSet<String>(finalIssues.keySet())) {
@@ -167,39 +167,57 @@ public void testFilterIssuesByChangedLines() throws InterruptedException, IOExce
@Test
public void getReviewResultTest() throws InterruptedException, IOException, URISyntaxException, RestApiException {
Multimap<String, Issue> finalIssues = LinkedListMultimap.create();
List<String> categories = Collections.singletonList("Test");

finalIssues.put("guice-bootstrap/src/main/java/com/magenta/guice/bootstrap/plugins/PluginsManager.java", new DummyIssue());
finalIssues.put("guice-bootstrap/src/main/java/com/magenta/guice/bootstrap/plugins/PluginsManager.java", new DummyIssue());
SonarToGerritBuilder builder = new SonarToGerritBuilder("", "", "", Severity.INFO.name(), true, false,
<<<<<<< HEAD
"No Issues Header", "Some Issues Header", "Issue Comment", true, "Test", "+1", "-1", "NONE", "OWNER");
ReviewInput reviewResult = builder.getReviewResult(finalIssues, categories);
=======
"No Issues Header", "Some Issues Header", "Issue Comment", true, "Test", "+1", "-1");
ReviewInput reviewResult = builder.getReviewResult(finalIssues);
>>>>>>> JENKINS-31004
Assert.assertEquals("Some Issues Header", reviewResult.message);
Assert.assertEquals(1, reviewResult.comments.size());
Assert.assertEquals(1, reviewResult.labels.size());
Assert.assertEquals(-1, reviewResult.labels.get("Test").intValue());
Assert.assertEquals(ReviewInput.NotifyHandling.OWNER, reviewResult.notify);

builder = new SonarToGerritBuilder("", "", "", Severity.INFO.name(), true, false,
<<<<<<< HEAD
"No Issues Header", "Some Issues Header", "Issue Comment", false, "Test", "1", "-1", null, null);
reviewResult = builder.getReviewResult(finalIssues, categories);
=======
"No Issues Header", "Some Issues Header", "Issue Comment", false, "Test", "1", "-1");
reviewResult = builder.getReviewResult(finalIssues);
>>>>>>> JENKINS-31004
Assert.assertEquals("Some Issues Header", reviewResult.message);
Assert.assertEquals(1, reviewResult.comments.size());
Assert.assertEquals(null, reviewResult.labels);
Assert.assertEquals(ReviewInput.NotifyHandling.OWNER, reviewResult.notify);

builder = new SonarToGerritBuilder("", "", "", Severity.INFO.name(), true, false,
<<<<<<< HEAD
"No Issues Header", "Some Issues Header", "Issue Comment", true, "Test", "0", "0", null, null);
reviewResult = builder.getReviewResult(finalIssues, categories);
=======
"No Issues Header", "Some Issues Header", "Issue Comment", true, "Test", "0", "0");
reviewResult = builder.getReviewResult(finalIssues);
>>>>>>> JENKINS-31004
Assert.assertEquals("Some Issues Header", reviewResult.message);
Assert.assertEquals(1, reviewResult.comments.size());
Assert.assertEquals(1, reviewResult.labels.size());
Assert.assertEquals(0, reviewResult.labels.get("Test").intValue());
Assert.assertEquals(ReviewInput.NotifyHandling.OWNER, reviewResult.notify);

builder = new SonarToGerritBuilder("", "", "", Severity.INFO.name(), true, false,
<<<<<<< HEAD
"No Issues Header", "Some Issues Header", "Issue Comment", true, "Test", "1test", "-1test", "NONE", "ALL");
reviewResult = builder.getReviewResult(finalIssues, categories);
=======
"No Issues Header", "Some Issues Header", "Issue Comment", true, "Test", "1test", "-1test");
reviewResult = builder.getReviewResult(finalIssues);
>>>>>>> JENKINS-31004
Assert.assertEquals("Some Issues Header", reviewResult.message);
Assert.assertEquals(1, reviewResult.comments.size());
Assert.assertEquals(1, reviewResult.labels.size());
@@ -209,23 +227,26 @@ public void getReviewResultTest() throws InterruptedException, IOException, URIS
builder = new SonarToGerritBuilder("", "", "", Severity.INFO.name(), true, false,
"No Issues Header", "Some Issues Header", "Issue Comment", true, "Test", "1", "-1", null, null);
finalIssues = LinkedListMultimap.create();
reviewResult = builder.getReviewResult(finalIssues, categories);
reviewResult = builder.getReviewResult(finalIssues);
Assert.assertEquals("No Issues Header", reviewResult.message);
Assert.assertEquals(0, reviewResult.comments.size());
Assert.assertEquals(1, reviewResult.labels.size());
Assert.assertEquals(+1, reviewResult.labels.get("Test").intValue());
Assert.assertEquals(ReviewInput.NotifyHandling.NONE, reviewResult.notify);

categories = new ArrayList<String>();
builder = new SonarToGerritBuilder("", "", "", Severity.INFO.name(), true, false,
"No Issues Header", "Some Issues Header", "Issue Comment", true, "Test", "1", "-1", "OWNER_REVIEWERS", "ALL");
finalIssues = LinkedListMultimap.create();
reviewResult = builder.getReviewResult(finalIssues, categories);
reviewResult = builder.getReviewResult(finalIssues);
Assert.assertEquals("No Issues Header", reviewResult.message);
Assert.assertEquals(0, reviewResult.comments.size());
Assert.assertEquals(1, reviewResult.labels.size());
<<<<<<< HEAD
Assert.assertEquals(+1, reviewResult.labels.get("Code-Review").intValue());
Assert.assertEquals(ReviewInput.NotifyHandling.OWNER_REVIEWERS, reviewResult.notify);
=======
Assert.assertEquals(+1, reviewResult.labels.get("Test").intValue());
>>>>>>> JENKINS-31004

}

0 comments on commit 5588d42

Please sign in to comment.