public List onCommitReceived()

in src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/FooterValidator.java [80:122]


  public List<CommitValidationMessage> onCommitReceived(CommitReceivedEvent receiveEvent)
      throws CommitValidationException {
    try {
      PluginConfig cfg =
          cfgFactory.getFromProjectConfigWithInheritance(
              receiveEvent.project.getNameKey(), pluginName);
      String[] requiredFooters = cfg.getStringList(KEY_REQUIRED_FOOTER);
      if (requiredFooters.length > 0
          && validatorConfig.isEnabled(
              receiveEvent.user,
              receiveEvent.getProjectNameKey(),
              receiveEvent.getRefName(),
              KEY_REQUIRED_FOOTER,
              receiveEvent.pushOptions)) {
        List<CommitValidationMessage> messages = new LinkedList<>();
        Set<String> footers =
            FluentIterable.from(receiveEvent.commit.getFooterLines())
                .transform(
                    new Function<FooterLine, String>() {
                      @Override
                      public String apply(FooterLine f) {
                        return f.getKey().toLowerCase(Locale.US);
                      }
                    })
                .toSet();
        for (int i = 0; i < requiredFooters.length; i++) {
          if (!footers.contains(requiredFooters[i].toLowerCase(Locale.US))) {
            messages.add(
                new CommitValidationMessage(
                    "missing required footer: " + requiredFooters[i], true));
          }
        }
        if (!messages.isEmpty()) {
          throw new CommitValidationException(
              "missing required footers in commit message", messages);
        }
      }
    } catch (NoSuchProjectException e) {
      throw new CommitValidationException("failed to check for required footers", e);
    }

    return Collections.emptyList();
  }