Line data Source code
1 : // Copyright (C) 2013 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.restapi.change; 16 : 17 : import static com.google.gerrit.server.config.GerritConfigListenerHelper.acceptIfChanged; 18 : 19 : import com.google.common.flogger.FluentLogger; 20 : import com.google.gerrit.extensions.common.AccountVisibility; 21 : import com.google.gerrit.server.change.ReviewerModifier; 22 : import com.google.gerrit.server.config.ConfigKey; 23 : import com.google.gerrit.server.config.GerritConfigListener; 24 : import com.google.gerrit.server.config.GerritServerConfig; 25 : import com.google.inject.Inject; 26 : import org.eclipse.jgit.lib.Config; 27 : import org.kohsuke.args4j.Option; 28 : 29 : public class SuggestReviewers { 30 152 : private static final FluentLogger logger = FluentLogger.forEnclosingClass(); 31 : 32 : private static final int DEFAULT_MAX_SUGGESTED = 10; 33 : 34 : private static final boolean DEFAULT_SKIP_SERVICE_USERS = true; 35 : 36 : protected final ReviewersUtil reviewersUtil; 37 : 38 : private final boolean suggestAccounts; 39 : private final int maxAllowed; 40 : private final int maxAllowedWithoutConfirmation; 41 : protected int limit; 42 : protected String query; 43 : protected final int maxSuggestedReviewers; 44 : protected boolean skipServiceUsers; 45 : 46 : @Option( 47 : name = "--limit", 48 : aliases = {"-n"}, 49 : metaVar = "CNT", 50 : usage = "maximum number of reviewers to list") 51 : public void setLimit(int l) { 52 1 : this.limit = l <= 0 ? maxSuggestedReviewers : Math.min(l, maxSuggestedReviewers); 53 1 : } 54 : 55 : @Option( 56 : name = "--query", 57 : aliases = {"-q"}, 58 : metaVar = "QUERY", 59 : usage = "match reviewers query") 60 : public void setQuery(String q) { 61 1 : this.query = q; 62 1 : } 63 : 64 : public String getQuery() { 65 2 : return query; 66 : } 67 : 68 : public boolean getSuggestAccounts() { 69 2 : return suggestAccounts; 70 : } 71 : 72 : public int getLimit() { 73 2 : return limit; 74 : } 75 : 76 : public int getMaxAllowed() { 77 1 : return maxAllowed; 78 : } 79 : 80 : public int getMaxAllowedWithoutConfirmation() { 81 1 : return maxAllowedWithoutConfirmation; 82 : } 83 : 84 : public boolean isSkipServiceUsers() { 85 1 : return skipServiceUsers; 86 : } 87 : 88 : @Inject 89 : public SuggestReviewers( 90 91 : AccountVisibility av, @GerritServerConfig Config cfg, ReviewersUtil reviewersUtil) { 91 91 : this.reviewersUtil = reviewersUtil; 92 91 : this.maxSuggestedReviewers = 93 91 : cfg.getInt("suggest", "maxSuggestedReviewers", DEFAULT_MAX_SUGGESTED); 94 91 : this.limit = this.maxSuggestedReviewers; 95 91 : String suggest = cfg.getString("suggest", null, "accounts"); 96 91 : this.suggestAccounts = !"OFF".equalsIgnoreCase(suggest) && !"false".equalsIgnoreCase(suggest); 97 : 98 91 : this.maxAllowed = 99 91 : cfg.getInt("addreviewer", "maxAllowed", ReviewerModifier.DEFAULT_MAX_REVIEWERS); 100 91 : this.maxAllowedWithoutConfirmation = 101 91 : cfg.getInt( 102 : "addreviewer", 103 : "maxWithoutConfirmation", 104 : ReviewerModifier.DEFAULT_MAX_REVIEWERS_WITHOUT_CHECK); 105 : 106 91 : logger.atFine().log("AccountVisibility: %s", av.name()); 107 : 108 91 : this.skipServiceUsers = 109 91 : cfg.getBoolean("suggest", "skipServiceUsers", DEFAULT_SKIP_SERVICE_USERS); 110 91 : } 111 : 112 : public static GerritConfigListener configListener() { 113 152 : return acceptIfChanged( 114 152 : ConfigKey.create("suggest", "maxSuggestedReviewers"), 115 152 : ConfigKey.create("suggest", "accounts"), 116 152 : ConfigKey.create("addreviewer", "maxAllowed"), 117 152 : ConfigKey.create("addreviewer", "maxWithoutConfirmation")); 118 : } 119 : }