Merge changes I383a3c20,I25631902
* changes: Add debug logs for reviewer suggestion CurrentUser: Add method for getting a loggable name
This commit is contained in:
commit
9b4a79532b
@ -95,6 +95,11 @@ public abstract class CurrentUser {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/** @return unique name of the user for logging, never {@code null} */
|
||||
public String getLoggableName() {
|
||||
return getUserName().orElseGet(() -> getClass().getSimpleName());
|
||||
}
|
||||
|
||||
/** Check if user is the IdentifiedUser */
|
||||
public boolean isIdentifiedUser() {
|
||||
return false;
|
||||
|
@ -323,6 +323,7 @@ public class IdentifiedUser extends CurrentUser {
|
||||
}
|
||||
|
||||
/** @return unique name of the user for logging, never {@code null} */
|
||||
@Override
|
||||
public String getLoggableName() {
|
||||
return getUserName()
|
||||
.orElseGet(
|
||||
|
@ -65,6 +65,8 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ReviewersUtil {
|
||||
@Singleton
|
||||
@ -110,6 +112,8 @@ public class ReviewersUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ReviewersUtil.class);
|
||||
|
||||
// Generate a candidate list at 2x the size of what the user wants to see to
|
||||
// give the ranking algorithm a good set of candidates it can work with
|
||||
private static final int CANDIDATE_LIST_MULTIPLIER = 2;
|
||||
@ -163,20 +167,29 @@ public class ReviewersUtil {
|
||||
VisibilityControl visibilityControl,
|
||||
boolean excludeGroups)
|
||||
throws IOException, OrmException, ConfigInvalidException, PermissionBackendException {
|
||||
CurrentUser currentUser = self.get();
|
||||
log.debug(
|
||||
"Suggesting reviewers for change {} to user {}.",
|
||||
changeNotes.getChangeId().get(),
|
||||
currentUser.getLoggableName());
|
||||
String query = suggestReviewers.getQuery();
|
||||
log.debug("Query: {}", query);
|
||||
int limit = suggestReviewers.getLimit();
|
||||
|
||||
if (!suggestReviewers.getSuggestAccounts()) {
|
||||
log.debug("Reviewer suggestion is disabled.");
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<Account.Id> candidateList = new ArrayList<>();
|
||||
if (!Strings.isNullOrEmpty(query)) {
|
||||
candidateList = suggestAccounts(suggestReviewers);
|
||||
log.debug("Candidate list: {}", candidateList);
|
||||
}
|
||||
|
||||
List<Account.Id> sortedRecommendations =
|
||||
recommendAccounts(changeNotes, suggestReviewers, projectState, candidateList);
|
||||
log.debug("Sorted recommendations: {}", sortedRecommendations);
|
||||
|
||||
// Filter accounts by visibility and enforce limit
|
||||
List<Account.Id> filteredRecommendations = new ArrayList<>();
|
||||
@ -192,20 +205,40 @@ public class ReviewersUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
log.debug("Filtered recommendations: {}", filteredRecommendations);
|
||||
|
||||
List<SuggestedReviewerInfo> suggestedReviewer = loadAccounts(filteredRecommendations);
|
||||
if (!excludeGroups && suggestedReviewer.size() < limit && !Strings.isNullOrEmpty(query)) {
|
||||
List<SuggestedReviewerInfo> suggestedReviewers = loadAccounts(filteredRecommendations);
|
||||
if (!excludeGroups && suggestedReviewers.size() < limit && !Strings.isNullOrEmpty(query)) {
|
||||
// Add groups at the end as individual accounts are usually more
|
||||
// important.
|
||||
suggestedReviewer.addAll(
|
||||
suggestedReviewers.addAll(
|
||||
suggestAccountGroups(
|
||||
suggestReviewers, projectState, visibilityControl, limit - suggestedReviewer.size()));
|
||||
suggestReviewers,
|
||||
projectState,
|
||||
visibilityControl,
|
||||
limit - suggestedReviewers.size()));
|
||||
}
|
||||
|
||||
if (suggestedReviewer.size() <= limit) {
|
||||
return suggestedReviewer;
|
||||
if (suggestedReviewers.size() > limit) {
|
||||
suggestedReviewers = suggestedReviewers.subList(0, limit);
|
||||
log.debug("Limited suggested reviewers to {} accounts.", limit);
|
||||
}
|
||||
return suggestedReviewer.subList(0, limit);
|
||||
log.debug(
|
||||
"Suggested reviewers: {}",
|
||||
suggestedReviewers
|
||||
.stream()
|
||||
.map(
|
||||
r -> {
|
||||
if (r.account != null) {
|
||||
return "a/" + r.account._accountId;
|
||||
} else if (r.group != null) {
|
||||
return "g/" + r.group.id;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
})
|
||||
.collect(toList()));
|
||||
return suggestedReviewers;
|
||||
}
|
||||
|
||||
private List<Account.Id> suggestAccounts(SuggestReviewers suggestReviewers) throws OrmException {
|
||||
|
Loading…
Reference in New Issue
Block a user