Search in sources :

Example 1 with SuggestedReviewerInfo

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;
    }
}
Also used : SuggestedReviewerInfo(com.google.gerrit.extensions.common.SuggestedReviewerInfo) ArrayList(java.util.ArrayList) GroupBaseInfo(com.google.gerrit.extensions.common.GroupBaseInfo) Timer0(com.google.gerrit.metrics.Timer0) GroupReference(com.google.gerrit.common.data.GroupReference)

Example 2 with SuggestedReviewerInfo

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();
}
Also used : SuggestedReviewerInfo(com.google.gerrit.extensions.common.SuggestedReviewerInfo) TestAccount(com.google.gerrit.acceptance.TestAccount) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 3 with SuggestedReviewerInfo

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();
}
Also used : SuggestedReviewerInfo(com.google.gerrit.extensions.common.SuggestedReviewerInfo) TestAccount(com.google.gerrit.acceptance.TestAccount) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) GerritConfig(com.google.gerrit.acceptance.GerritConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 4 with SuggestedReviewerInfo

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();
}
Also used : AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) SuggestedReviewerInfo(com.google.gerrit.extensions.common.SuggestedReviewerInfo) GerritConfig(com.google.gerrit.acceptance.GerritConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 5 with SuggestedReviewerInfo

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();
}
Also used : SuggestedReviewerInfo(com.google.gerrit.extensions.common.SuggestedReviewerInfo) TestAccount(com.google.gerrit.acceptance.TestAccount) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

SuggestedReviewerInfo (com.google.gerrit.extensions.common.SuggestedReviewerInfo)7 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)5 Test (org.junit.Test)5 TestAccount (com.google.gerrit.acceptance.TestAccount)4 GerritConfig (com.google.gerrit.acceptance.GerritConfig)2 GroupReference (com.google.gerrit.common.data.GroupReference)2 GroupBaseInfo (com.google.gerrit.extensions.common.GroupBaseInfo)2 Timer0 (com.google.gerrit.metrics.Timer0)2 Project (com.google.gerrit.reviewdb.client.Project)2 ArrayList (java.util.ArrayList)2 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 NoSuchGroupException (com.google.gerrit.common.errors.NoSuchGroupException)1 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)1 Url (com.google.gerrit.extensions.restapi.Url)1 Description (com.google.gerrit.metrics.Description)1 Units (com.google.gerrit.metrics.Description.Units)1 MetricMaker (com.google.gerrit.metrics.MetricMaker)1