public Optional evaluate()

in src/main/java/com/googlesource/gerrit/plugins/simplesubmitrules/rules/NoUnresolvedCommentsRule.java [55:90]


  public Optional<SubmitRecord> evaluate(ChangeData cd) {
    PluginConfig config;
    try {
      config = pluginConfigFactory.getFromProjectConfig(cd.project(), pluginName);
    } catch (NoSuchProjectException e) {
      log.error("Error when fetching config of change {}'s project", cd.getId(), e);

      return error("Error when fetching configuration");
    }

    boolean ruleEnabled =
        config.getBoolean(SimpleSubmitRulesConfig.KEY_BLOCK_IF_UNRESOLVED_COMMENTS, false);

    if (!ruleEnabled) {
      return Optional.empty();
    }

    Integer unresolvedComments;
    try {
      unresolvedComments = cd.unresolvedCommentCount();
    } catch (StorageException e) {
      log.error("Error when counting unresolved comments for change {}", cd.getId(), e);

      return error("Error when counting unresolved comments");
    }

    SubmitRecord sr = new SubmitRecord();
    sr.ruleName = RULE_NAME;
    sr.requirements = Collections.singletonList(REQUIREMENT);
    sr.status =
        unresolvedComments == null || unresolvedComments > 0
            ? SubmitRecord.Status.NOT_READY
            : SubmitRecord.Status.OK;

    return Optional.of(sr);
  }