Suppress error messages when exempt from owner approval.
* OWNERS files are not required if a CL is exempt from owner approval.
Change-Id: I122340ae306e3cf20340fc488d5132f3e322a209
diff --git a/src/main/java/com/googlesource/gerrit/plugins/findowners/Action.java b/src/main/java/com/googlesource/gerrit/plugins/findowners/Action.java
index 70c343a..45ec043 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/findowners/Action.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/findowners/Action.java
@@ -202,7 +202,9 @@
try (ReviewDb reviewDb = reviewDbProvider.open()) {
ChangeData changeData = changeDataFactory.create(reviewDb, change);
if (changeData.change().getDest().get() == null) {
- log.error("Cannot get branch of change: " + changeData.getId().get());
+ if (!Checker.isExemptFromOwnerApproval(changeData)) {
+ log.error("Cannot get branch of change: " + changeData.getId().get());
+ }
return null; // no "Find Owners" button
}
Status status = resource.getChange().getStatus();
diff --git a/src/main/java/com/googlesource/gerrit/plugins/findowners/Cache.java b/src/main/java/com/googlesource/gerrit/plugins/findowners/Cache.java
index 43b685a..87e40f5 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/findowners/Cache.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/findowners/Cache.java
@@ -106,7 +106,14 @@
String dbKey = Cache.makeKey(changeData.getId().get(), patchset, branch);
// TODO: get changed files of the given patchset?
return get(
- accountCache, emails, dbKey, repository, project, branch, changeData.currentFilePaths());
+ accountCache,
+ emails,
+ dbKey,
+ repository,
+ changeData,
+ project,
+ branch,
+ changeData.currentFilePaths());
}
/** Returns a cached or new OwnersDb, for the specified branch and changed files. */
@@ -115,12 +122,14 @@
Emails emails,
String key,
Repository repository,
+ ChangeData changeData,
Project.NameKey project,
String branch,
Collection<String> files) {
if (dbCache == null) { // Do not cache OwnersDb
log.trace("Create new OwnersDb, key=" + key);
- return new OwnersDb(accountCache, emails, key, repository, project, branch, files);
+ return new OwnersDb(
+ accountCache, emails, key, repository, changeData, project, branch, files);
}
try {
log.trace("Get from cash " + dbCache + ", key=" + key + ", cache size=" + dbCache.size());
@@ -130,12 +139,14 @@
@Override
public OwnersDb call() {
log.trace("Create new OwnersDb, key=" + key);
- return new OwnersDb(accountCache, emails, key, repository, project, branch, files);
+ return new OwnersDb(
+ accountCache, emails, key, repository, changeData, project, branch, files);
}
});
} catch (ExecutionException e) {
log.error("Cache.get has exception: " + e);
- return new OwnersDb(accountCache, emails, key, repository, project, branch, files);
+ return new OwnersDb(
+ accountCache, emails, key, repository, changeData, project, branch, files);
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/findowners/OwnersDb.java b/src/main/java/com/googlesource/gerrit/plugins/findowners/OwnersDb.java
index 3d4eb82..d551339 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/findowners/OwnersDb.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/findowners/OwnersDb.java
@@ -21,6 +21,7 @@
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.account.AccountCache;
import com.google.gerrit.server.account.Emails;
+import com.google.gerrit.server.query.change.ChangeData;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.PathMatcher;
@@ -66,6 +67,7 @@
Emails emails,
String key,
Repository repository,
+ ChangeData changeData,
Project.NameKey project,
String branch,
Collection<String> files) {
@@ -75,7 +77,7 @@
preferredEmails.put("*", "*");
String ownersFileName = Config.getOwnersFileName(project);
// Some hacked CL could have a target branch that is not created yet.
- ObjectId id = getBranchId(repository, branch);
+ ObjectId id = getBranchId(repository, branch, changeData);
revision = "";
if (id != null) {
for (String fileName : files) {
@@ -287,10 +289,10 @@
}
/** Returns ObjectId of the given branch, or null. */
- private static ObjectId getBranchId(Repository repo, String branch) {
+ private static ObjectId getBranchId(Repository repo, String branch, ChangeData changeData) {
try {
ObjectId id = repo.resolve(branch);
- if (id == null) {
+ if (id == null && changeData != null && !Checker.isExemptFromOwnerApproval(changeData)) {
log.error("cannot find branch " + branch);
}
return id;