Support configuration of max reviewers per project
It is now possible to define the maximum number of reviewers that
should be added to a change by this plugin on project level in the
'project.config' file of the project. If not defined on a project
the value is inherited from the parent projects. The default value is
3.
Change-Id: If5b1a56ae3df964154bc6c6b2487ada7fea49650
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/reviewersbyblame/RefUpdateListener.java b/src/main/java/com/googlesource/gerrit/plugins/reviewersbyblame/RefUpdateListener.java
index 5b39824..08f0e1b 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/reviewersbyblame/RefUpdateListener.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/reviewersbyblame/RefUpdateListener.java
@@ -33,8 +33,10 @@
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.IdentifiedUser;
+import com.google.gerrit.server.config.PluginConfigFactory;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.git.WorkQueue;
+import com.google.gerrit.server.project.NoSuchProjectException;
import com.google.gerrit.server.util.RequestContext;
import com.google.gerrit.server.util.ThreadLocalRequestContext;
import com.google.gwtorm.server.OrmException;
@@ -54,6 +56,7 @@
private final IdentifiedUser.GenericFactory identifiedUserFactory;
private final ThreadLocalRequestContext tl;
private final SchemaFactory<ReviewDb> schemaFactory;
+ private final PluginConfigFactory cfg;
private ReviewDb db;
@Inject
@@ -61,18 +64,34 @@
final GitRepositoryManager repoManager, final WorkQueue workQueue,
final IdentifiedUser.GenericFactory identifiedUserFactory,
final ThreadLocalRequestContext tl,
- final SchemaFactory<ReviewDb> schemaFactory) {
+ final SchemaFactory<ReviewDb> schemaFactory,
+ final PluginConfigFactory cfg) {
this.reviewersByBlameFactory = reviewersByBlameFactory;
this.repoManager = repoManager;
this.workQueue = workQueue;
this.identifiedUserFactory = identifiedUserFactory;
this.tl = tl;
this.schemaFactory = schemaFactory;
+ this.cfg = cfg;
}
@Override
public void onGitReferenceUpdated(final Event e) {
Project.NameKey projectName = new Project.NameKey(e.getProjectName());
+
+ int maxReviewers;
+ try {
+ maxReviewers =
+ cfg.getWithInheritance(projectName, "reviewers-by-blame")
+ .getInt("maxReviewers", 3);
+ } catch (NoSuchProjectException x) {
+ log.error(x.getMessage(), x);
+ return;
+ }
+ if (maxReviewers <= 0) {
+ return;
+ }
+
Repository git;
try {
git = repoManager.openRepository(projectName);
@@ -105,7 +124,6 @@
final RevCommit commit =
rw.parseCommit(ObjectId.fromString(u.getNewObjectId()));
- int maxReviewers = 3; //TODO Move to config
final Runnable task =
reviewersByBlameFactory.create(commit, change, ps, maxReviewers, git);
diff --git a/src/main/resources/Documentation/about.md b/src/main/resources/Documentation/about.md
index 3e47046..62863ee 100644
--- a/src/main/resources/Documentation/about.md
+++ b/src/main/resources/Documentation/about.md
@@ -6,5 +6,5 @@
authored most of the lines touched by the change, since these users should be
familiar with the code and can mostly review the change.
-Currently, the number of maximum reviewers added by this plugin is hardcoded to
-3 users for every project.
+The maximum number of reviewers that are added by this plugin can be
+[configured per project](config.html).
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md
new file mode 100644
index 0000000..434bd45
--- /dev/null
+++ b/src/main/resources/Documentation/config.md
@@ -0,0 +1,20 @@
+Configuration
+=============
+
+The configuration of the @PLUGIN@ plugin is done on project level in
+the `project.config` file of the project. Missing values are inherited
+from the parent projects. This means a global default configuration can
+be done in the `project.config` file of the `All-Projects` root project.
+Other projects can then override the configuration in their own
+`project.config` file.
+
+```
+ [plugin "reviewers-by-blame"]
+ maxReviewers = 2
+```
+
+plugin.reviewers-by-blame.maxReviewers
+: The maximum number of reviewers that should be added to a change by
+ this plugin.
+
+ By default 3.