use of com.google.gerrit.extensions.common.SuggestedReviewerInfo in project gerrit by GerritCodeReview.
the class ReviewersUtil method suggestAccountGroups.
private List<SuggestedReviewerInfo> suggestAccountGroups(SuggestReviewers suggestReviewers, ProjectControl projectControl, VisibilityControl visibilityControl, int limit) throws OrmException, IOException {
try (Timer0.Context ctx = metrics.queryGroupsLatency.start()) {
List<SuggestedReviewerInfo> groups = new ArrayList<>();
for (GroupReference g : suggestAccountGroups(suggestReviewers, projectControl)) {
GroupAsReviewer result = suggestGroupAsReviewer(suggestReviewers, projectControl.getProject(), g, visibilityControl);
if (result.allowed || result.allowedWithConfirmation) {
GroupBaseInfo info = new GroupBaseInfo();
info.id = Url.encode(g.getUUID().get());
info.name = g.getName();
SuggestedReviewerInfo suggestedReviewerInfo = new SuggestedReviewerInfo();
suggestedReviewerInfo.group = info;
suggestedReviewerInfo.count = result.size;
if (result.allowedWithConfirmation) {
suggestedReviewerInfo.confirm = true;
}
groups.add(suggestedReviewerInfo);
if (groups.size() >= limit) {
break;
}
}
}
return groups;
}
}
use of com.google.gerrit.extensions.common.SuggestedReviewerInfo in project gerrit by GerritCodeReview.
the class SuggestReviewersIT method defaultReviewerSuggestionOnFirstChange.
@Test
public void defaultReviewerSuggestionOnFirstChange() throws Exception {
TestAccount user1 = user("customuser1", "User1");
setApiUser(user1);
List<SuggestedReviewerInfo> reviewers = suggestReviewers(createChange().getChangeId(), "", 4);
assertThat(reviewers).isEmpty();
}
use of com.google.gerrit.extensions.common.SuggestedReviewerInfo in project gerrit by GerritCodeReview.
the class SuggestReviewersIT method reviewerRanking.
@Test
@GerritConfig(name = "suggest.maxSuggestedReviewers", value = "10")
public void reviewerRanking() throws Exception {
// Assert that user are ranked by the number of times they have applied a
// a label to a change (highest), added comments (medium) or owned a
// change (low).
String fullName = "Primum Finalis";
TestAccount userWhoOwns = user("customuser1", fullName);
TestAccount reviewer1 = user("customuser2", fullName);
TestAccount reviewer2 = user("customuser3", fullName);
TestAccount userWhoComments = user("customuser4", fullName);
TestAccount userWhoLooksForSuggestions = user("customuser5", fullName);
// Create a change as userWhoOwns and add some reviews
setApiUser(userWhoOwns);
String changeId1 = createChangeFromApi();
setApiUser(reviewer1);
reviewChange(changeId1);
setApiUser(user1);
String changeId2 = createChangeFromApi();
setApiUser(reviewer1);
reviewChange(changeId2);
setApiUser(reviewer2);
reviewChange(changeId2);
// Create a comment as a different user
setApiUser(userWhoComments);
ReviewInput ri = new ReviewInput();
ri.message = "Test";
gApi.changes().id(changeId1).revision(1).review(ri);
// Create a change as a new user to assert that we receive the correct
// ranking
setApiUser(userWhoLooksForSuggestions);
List<SuggestedReviewerInfo> reviewers = suggestReviewers(createChangeFromApi(), "Pri", 4);
assertThat(reviewers.stream().map(r -> r.account._accountId).collect(toList())).containsExactly(reviewer1.id.get(), reviewer2.id.get(), userWhoOwns.id.get(), userWhoComments.id.get()).inOrder();
}
use of com.google.gerrit.extensions.common.SuggestedReviewerInfo in project gerrit by GerritCodeReview.
the class SuggestReviewersIT method suggestReviewersGroupSizeConsiderations.
@Test
@GerritConfig(name = "addreviewer.maxAllowed", value = "2")
@GerritConfig(name = "addreviewer.maxWithoutConfirmation", value = "1")
public void suggestReviewersGroupSizeConsiderations() throws Exception {
AccountGroup largeGroup = group("large");
AccountGroup mediumGroup = group("medium");
// Both groups have Administrator as a member. Add two users to large
// group to push it past maxAllowed, and one to medium group to push it
// past maxWithoutConfirmation.
user("individual 0", "Test0 Last0", largeGroup, mediumGroup);
user("individual 1", "Test1 Last1", largeGroup);
String changeId = createChange().getChangeId();
List<SuggestedReviewerInfo> reviewers;
SuggestedReviewerInfo reviewer;
// Individual account suggestions have count of 1 and no confirm.
reviewers = suggestReviewers(changeId, "test", 10);
assertThat(reviewers).hasSize(2);
reviewer = reviewers.get(0);
assertThat(reviewer.count).isEqualTo(1);
assertThat(reviewer.confirm).isNull();
// Large group should never be suggested.
reviewers = suggestReviewers(changeId, largeGroup.getName(), 10);
assertThat(reviewers).isEmpty();
// Medium group should be suggested with appropriate count and confirm.
reviewers = suggestReviewers(changeId, mediumGroup.getName(), 10);
assertThat(reviewers).hasSize(1);
reviewer = reviewers.get(0);
assertThat(reviewer.group.name).isEqualTo(mediumGroup.getName());
assertThat(reviewer.count).isEqualTo(2);
assertThat(reviewer.confirm).isTrue();
}
use of com.google.gerrit.extensions.common.SuggestedReviewerInfo in project gerrit by GerritCodeReview.
the class SuggestReviewersIT method defaultReviewerSuggestion.
@Test
public void defaultReviewerSuggestion() throws Exception {
TestAccount user1 = user("customuser1", "User1");
TestAccount reviewer1 = user("customuser2", "User2");
TestAccount reviewer2 = user("customuser3", "User3");
setApiUser(user1);
String changeId1 = createChangeFromApi();
setApiUser(reviewer1);
reviewChange(changeId1);
setApiUser(user1);
String changeId2 = createChangeFromApi();
setApiUser(reviewer1);
reviewChange(changeId2);
setApiUser(reviewer2);
reviewChange(changeId2);
setApiUser(user1);
String changeId3 = createChangeFromApi();
List<SuggestedReviewerInfo> reviewers = suggestReviewers(changeId3, null, 4);
assertThat(reviewers.stream().map(r -> r.account._accountId).collect(toList())).containsExactly(reviewer1.id.get(), reviewer2.id.get()).inOrder();
// check that existing reviewers are filtered out
gApi.changes().id(changeId3).addReviewer(reviewer1.email);
reviewers = suggestReviewers(changeId3, null, 4);
assertThat(reviewers.stream().map(r -> r.account._accountId).collect(toList())).containsExactly(reviewer2.id.get()).inOrder();
}
Aggregations