Add options ignoreDrafts and ignoreSubjectRegEx
Adding options to ignore certain commits when adding reviewers.
This is quite useful if the committer knows that the
commit is not in a reviewable state but already wants to push it.
Change-Id: I7cffd46ce9d4b77b1710834bdf4f627879881073
diff --git a/src/main/java/com/googlesource/gerrit/plugins/reviewersbyblame/ChangeUpdatedListener.java b/src/main/java/com/googlesource/gerrit/plugins/reviewersbyblame/ChangeUpdatedListener.java
index e4bc8a7..eb7098b 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/reviewersbyblame/ChangeUpdatedListener.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/reviewersbyblame/ChangeUpdatedListener.java
@@ -87,10 +87,18 @@
Project.NameKey projectName = e.getProjectNameKey();
int maxReviewers;
+ boolean ignoreDrafts;
+ String ignoreSubjectRegEx;
try {
maxReviewers =
cfg.getFromProjectConfigWithInheritance(projectName, pluginName)
.getInt("maxReviewers", 3);
+ ignoreDrafts =
+ cfg.getFromProjectConfigWithInheritance(projectName, pluginName)
+ .getBoolean("ignoreDrafts", false);
+ ignoreSubjectRegEx =
+ cfg.getFromProjectConfigWithInheritance(projectName, pluginName)
+ .getString("ignoreSubjectRegEx", "");
} catch (NoSuchProjectException x) {
log.error(x.getMessage(), x);
return;
@@ -111,6 +119,10 @@
return;
}
+ if (ignoreDrafts && ps.isDraft()) {
+ return;
+ }
+
final Change change = reviewDb.changes().get(psId.getParentKey());
if (change == null) {
log.warn("Change " + changeId.get() + " not found.");
@@ -120,6 +132,11 @@
final RevCommit commit =
rw.parseCommit(ObjectId.fromString(e.patchSet.get().revision));
+ if (!ignoreSubjectRegEx.isEmpty()
+ && commit.getShortMessage().matches(ignoreSubjectRegEx)) {
+ return;
+ }
+
final Runnable task =
reviewersByBlameFactory.create(commit, change, ps, maxReviewers, git);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/reviewersbyblame/ReviewersByBlameModule.java b/src/main/java/com/googlesource/gerrit/plugins/reviewersbyblame/ReviewersByBlameModule.java
index 89218c9..2c7e945 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/reviewersbyblame/ReviewersByBlameModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/reviewersbyblame/ReviewersByBlameModule.java
@@ -31,5 +31,14 @@
.toInstance(new ProjectConfigEntry("Max Reviewers", 3, true,
"The maximum number of reviewers that should be automatically added"
+ " to a change based on the git blame computation on the changed files."));
+ bind(ProjectConfigEntry.class).annotatedWith(Exports.named("ignoreDrafts"))
+ .toInstance(
+ new ProjectConfigEntry("Ignore Drafts", false,
+ "Ignore draft commits when adding reviewers"));
+ bind(ProjectConfigEntry.class)
+ .annotatedWith(Exports.named("ignoreSubjectRegEx"))
+ .toInstance(
+ new ProjectConfigEntry("Ignore Regex", "", true,
+ "Ignore commits where the subject matches the given regular expression"));
}
}
diff --git a/src/main/resources/Documentation/about.md b/src/main/resources/Documentation/about.md
index 62863ee..1828d00 100644
--- a/src/main/resources/Documentation/about.md
+++ b/src/main/resources/Documentation/about.md
@@ -6,5 +6,6 @@
authored most of the lines touched by the change, since these users should be
familiar with the code and can mostly review the change.
-The maximum number of reviewers that are added by this plugin can be
+The maximum number of reviewers that are added as well as exceptions when no
+reviewers should be 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
index 434bd45..404f970 100644
--- a/src/main/resources/Documentation/config.md
+++ b/src/main/resources/Documentation/config.md
@@ -11,6 +11,8 @@
```
[plugin "reviewers-by-blame"]
maxReviewers = 2
+ ignoreDrafts = true
+ ignoreSubjectRegEx = WIP(.*)
```
plugin.reviewers-by-blame.maxReviewers
@@ -18,3 +20,16 @@
this plugin.
By default 3.
+
+
+plugin.reviewers-by-blame.ignoreDrafts
+: Ignore draft commits when adding reviewers.
+
+ By default false.
+
+
+plugin.reviewers-by-blame.ignoreSubjectRegEx
+: Ignore commits where the subject of the commit messages matches
+ the given regular expression. If empty or not set, no commits are ignored.
+
+ By default not set.
\ No newline at end of file