No longer require RefControl to construct ChangeHookValidator
The RefControl was being used just to get the IdentifiedUser, however the user is already in the CommitReceiveEvent. Removing the need to pass in RefControl to the constructor makes it more easy to eventually make the ChangeHookValidator injectable via a plugin. Change-Id: Ic721adaf46613d0e1f94604d9c5a47ba03758686
This commit is contained in:
@@ -131,7 +131,7 @@ public class CommitValidators {
|
|||||||
validators.add(new ConfigValidator(refControl, repo));
|
validators.add(new ConfigValidator(refControl, repo));
|
||||||
validators.add(new BannedCommitsValidator(rejectCommits));
|
validators.add(new BannedCommitsValidator(rejectCommits));
|
||||||
validators.add(new PluginCommitValidationListener(commitValidationListeners));
|
validators.add(new PluginCommitValidationListener(commitValidationListeners));
|
||||||
validators.add(new ChangeHookValidator(refControl, hooks));
|
validators.add(new ChangeHookValidator(hooks));
|
||||||
|
|
||||||
List<CommitValidationMessage> messages = new LinkedList<>();
|
List<CommitValidationMessage> messages = new LinkedList<>();
|
||||||
|
|
||||||
@@ -165,7 +165,7 @@ public class CommitValidators {
|
|||||||
}
|
}
|
||||||
validators.add(new ConfigValidator(refControl, repo));
|
validators.add(new ConfigValidator(refControl, repo));
|
||||||
validators.add(new PluginCommitValidationListener(commitValidationListeners));
|
validators.add(new PluginCommitValidationListener(commitValidationListeners));
|
||||||
validators.add(new ChangeHookValidator(refControl, hooks));
|
validators.add(new ChangeHookValidator(hooks));
|
||||||
|
|
||||||
List<CommitValidationMessage> messages = new LinkedList<>();
|
List<CommitValidationMessage> messages = new LinkedList<>();
|
||||||
|
|
||||||
@@ -549,26 +549,22 @@ public class CommitValidators {
|
|||||||
/** Reject commits that don't pass user-supplied ref-update hook. */
|
/** Reject commits that don't pass user-supplied ref-update hook. */
|
||||||
public static class ChangeHookValidator implements
|
public static class ChangeHookValidator implements
|
||||||
CommitValidationListener {
|
CommitValidationListener {
|
||||||
private final RefControl refControl;
|
|
||||||
private final ChangeHooks hooks;
|
private final ChangeHooks hooks;
|
||||||
|
|
||||||
public ChangeHookValidator(RefControl refControl, ChangeHooks hooks) {
|
public ChangeHookValidator(ChangeHooks hooks) {
|
||||||
this.refControl = refControl;
|
|
||||||
this.hooks = hooks;
|
this.hooks = hooks;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<CommitValidationMessage> onCommitReceived(
|
public List<CommitValidationMessage> onCommitReceived(
|
||||||
CommitReceivedEvent receiveEvent) throws CommitValidationException {
|
CommitReceivedEvent receiveEvent) throws CommitValidationException {
|
||||||
|
IdentifiedUser user = receiveEvent.user;
|
||||||
if (refControl.getUser().isIdentifiedUser()) {
|
|
||||||
IdentifiedUser user = refControl.getUser().asIdentifiedUser();
|
|
||||||
|
|
||||||
String refname = receiveEvent.refName;
|
String refname = receiveEvent.refName;
|
||||||
ObjectId old = ObjectId.zeroId();
|
ObjectId old = ObjectId.zeroId();
|
||||||
if (receiveEvent.commit.getParentCount() > 0) {
|
if (receiveEvent.commit.getParentCount() > 0) {
|
||||||
old = receiveEvent.commit.getParent(0);
|
old = receiveEvent.commit.getParent(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (receiveEvent.command.getRefName().startsWith(REFS_CHANGES)) {
|
if (receiveEvent.command.getRefName().startsWith(REFS_CHANGES)) {
|
||||||
/*
|
/*
|
||||||
* If the ref-update hook tries to distinguish behavior between pushes to
|
* If the ref-update hook tries to distinguish behavior between pushes to
|
||||||
@@ -585,7 +581,6 @@ public class CommitValidators {
|
|||||||
if (result != null && result.getExitValue() != 0) {
|
if (result != null && result.getExitValue() != 0) {
|
||||||
throw new CommitValidationException(result.toString().trim());
|
throw new CommitValidationException(result.toString().trim());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user