in src/main/java/com/googlesource/gerrit/plugins/hooks/CommitReceived.java [40:71]
public List<CommitValidationMessage> onCommitReceived(CommitReceivedEvent receiveEvent)
throws CommitValidationException {
String refname = receiveEvent.refName;
String commandRef = receiveEvent.command.getRefName();
ObjectId old = ObjectId.zeroId();
if (receiveEvent.commit.getParentCount() > 0) {
old = receiveEvent.commit.getParent(0);
}
HookArgs args = hookFactory.createArgs();
String projectName = receiveEvent.project.getName();
args.add("--project", projectName);
args.add("--refname", refname);
args.add("--uploader", receiveEvent.user.getNameEmail());
args.add("--uploader-username", receiveEvent.user.getUserName().orElse(null));
args.add("--oldrev", old.name());
args.add("--newrev", receiveEvent.commit.name());
args.add("--cmdref", commandRef);
HookResult result = hook.execute(projectName, args);
if (result != null) {
String output = result.toString();
if (result.getExitValue() != 0) {
throw new CommitValidationException(output);
}
if (!output.isEmpty()) {
return ImmutableList.of(new CommitValidationMessage(output, false));
}
}
return Collections.emptyList();
}