public Response apply()

in src/main/java/com/googlesource/gerrit/plugins/zuul/GetCrd.java [54:94]


  public Response<CrdInfo> apply(RevisionResource rsrc)
      throws RepositoryNotFoundException, IOException, BadRequestException, AuthException,
          PermissionBackendException {
    CrdInfo out = new CrdInfo();
    out.dependsOn = new ArrayList<>();
    out.neededBy = new ArrayList<>();

    Change.Key thisId = rsrc.getChange().getKey();

    // get depends on info
    Project.NameKey p = rsrc.getChange().getProject();
    String rev = rsrc.getPatchSet().commitId().getName();
    String commitMsg = commitMessageFetcher.fetch(p, rev);
    Pattern pattern = Pattern.compile("[Dd]epends-[Oo]n:? (I[0-9a-f]{8,40})", Pattern.DOTALL);
    Matcher matcher = pattern.matcher(commitMsg);
    while (matcher.find()) {
      String otherId = matcher.group(1);
      logger.atFinest().log("Change %s depends on change %s", thisId, otherId);
      out.dependsOn.add(otherId);
    }

    // get needed by info
    QueryChanges query = changes.list();
    String neededByQuery = "message:" + thisId + " -change:" + thisId;
    query.addQuery(neededByQuery);
    Response<List<?>> response = query.apply(TopLevelResource.INSTANCE);
    List<ChangeInfo> changes = (List<ChangeInfo>) response.value();
    // check for dependency cycles
    for (ChangeInfo other : changes) {
      String otherId = other.changeId;
      logger.atFinest().log("Change %s needed by %s", thisId, otherId);
      if (out.dependsOn.contains(otherId)) {
        logger.atFiner().log(
            "Detected dependency cycle between changes %s and %s", thisId, otherId);
        out.cycle = true;
      }
      out.neededBy.add(otherId);
    }

    return Response.ok(out);
  }