Beispiel #1
0
  private void checkSubmitRulesAndState(ChangeSet cs)
      throws ResourceConflictException, OrmException {

    StringBuilder msgbuf = new StringBuilder();
    List<Change.Id> problemChanges = new ArrayList<>();
    for (Change.Id id : cs.ids()) {
      try {
        ChangeData cd = changeDataFactory.create(db, id);
        if (cd.change().getStatus() != Change.Status.NEW) {
          throw new ResourceConflictException(
              "Change " + cd.change().getChangeId() + " is in state " + cd.change().getStatus());
        } else {
          records.put(cd.change().getId(), checkSubmitRule(cd));
        }
      } catch (ResourceConflictException e) {
        msgbuf.append(e.getMessage() + "\n");
        problemChanges.add(id);
      }
    }
    String reason = msgbuf.toString();
    if (!reason.isEmpty()) {
      throw new ResourceConflictException(
          "The change could not be "
              + "submitted because it depends on change(s) "
              + problemChanges.toString()
              + ", which could not be submitted "
              + "because:\n"
              + reason);
    }
  }
Beispiel #2
0
  @Override
  public List<Record> apply(RevisionResource rsrc, Input input) throws AuthException, OrmException {
    if (input == null) {
      input = new Input();
    }
    if (input.rule != null && !rules.isProjectRulesEnabled()) {
      throw new AuthException("project rules are disabled");
    }
    input.filters = MoreObjects.firstNonNull(input.filters, filters);
    SubmitRuleEvaluator evaluator =
        new SubmitRuleEvaluator(changeDataFactory.create(db.get(), rsrc.getControl()));

    List<SubmitRecord> records =
        evaluator
            .setPatchSet(rsrc.getPatchSet())
            .setLogErrors(false)
            .setSkipSubmitFilters(input.filters == Filters.SKIP)
            .setRule(input.rule)
            .evaluate();
    List<Record> out = Lists.newArrayListWithCapacity(records.size());
    AccountLoader accounts = accountInfoFactory.create(true);
    for (SubmitRecord r : records) {
      out.add(new Record(r, accounts));
    }
    if (!out.isEmpty()) {
      out.get(0).prologReductionCount = evaluator.getReductionsConsumed();
    }
    accounts.fill();
    return out;
  }
  private static ChangeKind getChangeKindInternal(
      ChangeKindCache cache,
      ReviewDb db,
      Change change,
      PatchSet patch,
      ChangeData.Factory changeDataFactory,
      ProjectCache projectCache,
      GitRepositoryManager repoManager) {
    Repository repo = null;
    // TODO - dborowitz: add NEW_CHANGE type for default.
    ChangeKind kind = ChangeKind.REWORK;
    // Trivial case: if we're on the first patch, we don't need to open
    // the repository.
    if (patch.getId().get() > 1) {
      try {
        ProjectState projectState = projectCache.checkedGet(change.getProject());

        repo = repoManager.openRepository(change.getProject());

        ChangeData cd = changeDataFactory.create(db, change);
        Collection<PatchSet> patchSetCollection = cd.patches();
        PatchSet priorPs = patch;
        for (PatchSet ps : patchSetCollection) {
          if (ps.getId().get() < patch.getId().get()
              && (ps.getId().get() > priorPs.getId().get() || priorPs == patch)) {
            // We only want the previous patch set, so walk until the last one
            priorPs = ps;
          }
        }

        // If we still think the previous patch is the current patch,
        // we only have one patch set.  Return the default.
        // This can happen if a user creates a draft, uploads a second patch,
        // and deletes the draft.
        if (priorPs != patch) {
          kind =
              cache.getChangeKind(
                  projectState,
                  repo,
                  ObjectId.fromString(priorPs.getRevision().get()),
                  ObjectId.fromString(patch.getRevision().get()));
        }
      } catch (IOException | OrmException e) {
        // Do nothing; assume we have a complex change
        log.warn(
            "Unable to get change kind for patchSet "
                + patch.getPatchSetId()
                + "of change "
                + change.getChangeId(),
            e);
      } finally {
        if (repo != null) {
          repo.close();
        }
      }
    }
    return kind;
  }
Beispiel #4
0
 private SubmitType getSubmitType(ChangeControl ctl, PatchSet ps) {
   try {
     ChangeData cd = changeDataFactory.create(db, ctl);
     SubmitTypeRecord r = new SubmitRuleEvaluator(cd).setPatchSet(ps).getSubmitType();
     if (r.status != SubmitTypeRecord.Status.OK) {
       logError("Failed to get submit type for " + ctl.getChange().getKey());
       return null;
     }
     return r.type;
   } catch (OrmException e) {
     logError("Failed to get submit type for " + ctl.getChange().getKey(), e);
     return null;
   }
 }
Beispiel #5
0
 /**
  * Synchronously index a change.
  *
  * @param change change to index.
  * @param db review database.
  */
 public void index(ReviewDb db, Change change) throws IOException {
   index(changeDataFactory.create(db, change));
 }