protected Set getMissingDownstreamMerges()

in src/main/java/com/googlesource/gerrit/plugins/automerger/MergeValidator.java [105:143]


  protected Set<String> getMissingDownstreamMerges(ChangeInfo upstreamChange)
      throws RestApiException, IOException, ConfigInvalidException, InvalidQueryParameterException {
    Set<String> missingDownstreamBranches = new HashSet<>();

    Set<String> downstreamBranches =
        config.getDownstreamBranches(upstreamChange.branch, upstreamChange.project);
    for (String downstreamBranch : downstreamBranches) {
      boolean dsExists = false;
      QueryBuilder queryBuilder = new QueryBuilder();
      if (upstreamChange.topic == null || upstreamChange.topic.equals("")) {
        // If topic is null or empty, we immediately know that downstream is missing.
        missingDownstreamBranches.add(downstreamBranch);
        continue;
      }
      queryBuilder.addParameter("topic", upstreamChange.topic);
      queryBuilder.addParameter("branch", downstreamBranch);
      queryBuilder.addParameter("status", "open");
      List<ChangeInfo> changes =
          gApi.changes()
              .query(queryBuilder.get())
              .withOptions(ListChangesOption.ALL_REVISIONS, ListChangesOption.CURRENT_COMMIT)
              .get();
      for (ChangeInfo change : changes) {
        RevisionInfo revision = change.revisions.get(change.currentRevision);
        List<CommitInfo> parents = revision.commit.parents;
        if (parents.size() > 1) {
          String secondParent = parents.get(1).commit;
          if (secondParent.equals(upstreamChange.currentRevision)) {
            dsExists = true;
            break;
          }
        }
      }
      if (!dsExists) {
        missingDownstreamBranches.add(downstreamBranch);
      }
    }
    return missingDownstreamBranches;
  }