Write debug log if account from commit identity is added as reviewer

If a user pushes a commit that has another user as author or committer
that user is automatically added as reviewer. Log this on fine level so
that we see in traces when this happens.

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I25487d917557a023f8b5df1c5c408f79db0c9156
This commit is contained in:
Edwin Kempin
2019-12-23 15:55:32 +01:00
parent 9bf7a5130e
commit 96af065cbf
3 changed files with 22 additions and 5 deletions

View File

@@ -556,10 +556,16 @@ public class ChangeInserter implements InsertChangeOp {
reviewerInputs.stream(),
Streams.stream(
newAddReviewerInputFromCommitIdentity(
change, patchSetInfo.getAuthor().getAccount(), NotifyHandling.NONE)),
change,
patchSetInfo.getCommitId(),
patchSetInfo.getAuthor().getAccount(),
NotifyHandling.NONE)),
Streams.stream(
newAddReviewerInputFromCommitIdentity(
change, patchSetInfo.getCommitter().getAccount(), NotifyHandling.NONE)))
change,
patchSetInfo.getCommitId(),
patchSetInfo.getCommitter().getAccount(),
NotifyHandling.NONE)))
.collect(toImmutableList());
}
}

View File

@@ -81,6 +81,7 @@ import java.util.Set;
import java.util.function.Function;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.ObjectId;
public class ReviewerAdder {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
@@ -125,12 +126,16 @@ public class ReviewerAdder {
}
public static Optional<InternalAddReviewerInput> newAddReviewerInputFromCommitIdentity(
Change change, @Nullable Account.Id accountId, NotifyHandling notify) {
Change change, ObjectId commitId, @Nullable Account.Id accountId, NotifyHandling notify) {
if (accountId == null || accountId.equals(change.getOwner())) {
// If git ident couldn't be resolved to a user, or if it's not forged, do nothing.
return Optional.empty();
}
logger.atFine().log(
"Adding account %d from author/committer identity of commit %s as reviewer to change %d",
accountId.get(), commitId.name(), change.getChangeId());
InternalAddReviewerInput in = new InternalAddReviewerInput();
in.reviewer = accountId.toString();
in.state = REVIEWER;

View File

@@ -368,10 +368,16 @@ public class ReplaceOp implements BatchUpdateOp {
Streams.concat(
Streams.stream(
newAddReviewerInputFromCommitIdentity(
change, psInfo.getAuthor().getAccount(), NotifyHandling.NONE)),
change,
psInfo.getCommitId(),
psInfo.getAuthor().getAccount(),
NotifyHandling.NONE)),
Streams.stream(
newAddReviewerInputFromCommitIdentity(
change, psInfo.getCommitter().getAccount(), NotifyHandling.NONE)));
change,
psInfo.getCommitId(),
psInfo.getCommitter().getAccount(),
NotifyHandling.NONE)));
if (magicBranch != null) {
inputs =
Streams.concat(