in src/main/java/com/googlesource/gerrit/plugins/serviceuser/ValidateServiceUserCommits.java [48:82]
public List<CommitValidationMessage> onCommitReceived(CommitReceivedEvent receiveEvent)
throws CommitValidationException {
try {
PersonIdent committer = receiveEvent.commit.getCommitterIdent();
ServiceUserInfo serviceUser = serviceUserResolver.getAsServiceUser(committer);
if (serviceUser != null) {
if (serviceUser.owner != null
&& serviceUserResolver.listActiveOwners(serviceUser).isEmpty()) {
throw new CommitValidationException(
String.format(
"Commit %s of service user %s (%s) is rejected because "
+ "all service user owner accounts are inactive.",
receiveEvent.commit.getId().getName(),
committer.getName(),
committer.getEmailAddress()));
}
Optional<AccountState> creator =
accountCache.get(Account.id(serviceUser.createdBy._accountId));
if (!creator.isPresent() || !creator.get().account().isActive()) {
throw new CommitValidationException(
String.format(
"Commit %s of service user %s (%s) is rejected because "
+ "the account of the service creator is inactive.",
receiveEvent.commit.getId().getName(),
committer.getName(),
committer.getEmailAddress()));
}
}
} catch (RestApiException e) {
log.error(e.getMessage(), e);
throw new CommitValidationException(
"Internal error while checking for service user commits.", e);
}
return Collections.emptyList();
}