Refactor CommitValidators to reduce repetition

Use a manual factory. Move the banned commit map loading into the
factory method, throwing IOException, which we couldn't do with an
assisted factory. At this point CommitValidators itself is just a
thin wrapper around the list of CommitValidationListeners.

Since the BanCommit stuff is now in the factory, we can move the
switch on the Policy into the factory method as well, which greatly
reduces complexity at call sites. Callers are still responsible for
constructing their own CommitReceivedEvents, so there is still some
code there.

Change-Id: I9a7060e3a9c43f92f34da66e958ab5d1cbdaf116
This commit is contained in:
Dave Borowitz
2016-09-12 15:52:41 -04:00
committed by Edwin Kempin
parent 146635a467
commit 1010738a99
6 changed files with 104 additions and 129 deletions

View File

@@ -2588,12 +2588,11 @@ public class ReceiveCommits {
rw.parseBody(c);
CommitReceivedEvent receiveEvent =
new CommitReceivedEvent(cmd, project, ctl.getRefName(), c, user);
CommitValidators commitValidators =
commitValidatorsFactory.create(ctl, sshInfo, repo);
CommitValidators commitValidators = commitValidatorsFactory.create(
CommitValidators.Policy.RECEIVE_COMMITS, ctl, sshInfo, repo);
try {
messages.addAll(commitValidators.validateForReceiveCommits(
receiveEvent, rejectCommits));
messages.addAll(commitValidators.validate(receiveEvent));
} catch (CommitValidationException e) {
logDebug("Commit validation failed on {}", c.name());
messages.addAll(e.getMessages());