use of com.google.gerrit.server.project.ChangeControl in project gerrit by GerritCodeReview.
the class AbstractQueryChangesTest method newPatchSet.
protected Change newPatchSet(TestRepository<Repo> repo, Change c) throws Exception {
// Add a new file so the patch set is not a trivial rebase, to avoid default
// Code-Review label copying.
int n = c.currentPatchSetId().get() + 1;
RevCommit commit = repo.parseBody(repo.commit().message("message").add("file" + n, "contents " + n).create());
ChangeControl ctl = changeControlFactory.controlFor(db, c, user);
PatchSetInserter inserter = patchSetFactory.create(ctl, new PatchSet.Id(c.getId(), n), commit).setNotify(NotifyHandling.NONE).setFireRevisionCreated(false).setValidate(false);
try (BatchUpdate bu = updateFactory.create(db, c.getProject(), user, TimeUtil.nowTs());
ObjectInserter oi = repo.getRepository().newObjectInserter();
ObjectReader reader = oi.newReader();
RevWalk rw = new RevWalk(reader)) {
bu.setRepository(repo.getRepository(), rw, oi);
bu.addOp(c.getId(), inserter);
bu.execute();
}
return inserter.getChange();
}
use of com.google.gerrit.server.project.ChangeControl in project gerrit by GerritCodeReview.
the class ConsistencyCheckerIT method missingRepo.
@Test
public void missingRepo() throws Exception {
// NoteDb can't have a change without a repo.
assume().that(notesMigration.enabled()).isFalse();
ChangeControl ctl = insertChange();
Project.NameKey name = ctl.getProject().getNameKey();
((InMemoryRepositoryManager) repoManager).deleteRepository(name);
assertProblems(ctl, null, problem("Destination repository not found: " + name));
}
use of com.google.gerrit.server.project.ChangeControl in project gerrit by GerritCodeReview.
the class ConsistencyCheckerIT method currentPatchSetMissing.
@Test
public void currentPatchSetMissing() throws Exception {
// NoteDb can't create a change without a patch set.
assume().that(notesMigration.enabled()).isFalse();
ChangeControl ctl = insertChange();
db.patchSets().deleteKeys(singleton(ctl.getChange().currentPatchSetId()));
assertProblems(ctl, null, problem("Current patch set 1 not found"));
}
use of com.google.gerrit.server.project.ChangeControl in project gerrit by GerritCodeReview.
the class ChangeIncludedIn method apply.
@Override
public IncludedInInfo apply(ChangeResource rsrc) throws RestApiException, OrmException, IOException {
ChangeControl ctl = rsrc.getControl();
PatchSet ps = psUtil.current(db.get(), rsrc.getNotes());
Project.NameKey project = ctl.getProject().getNameKey();
return includedIn.apply(project, ps.getRevision().get());
}
use of com.google.gerrit.server.project.ChangeControl in project gerrit by GerritCodeReview.
the class ChangeInserter method postUpdate.
@Override
public void postUpdate(Context ctx) throws OrmException {
if (sendMail && (notify != NotifyHandling.NONE || !accountsToNotify.isEmpty())) {
Runnable sender = new Runnable() {
@Override
public void run() {
try {
CreateChangeSender cm = createChangeSenderFactory.create(change.getProject(), change.getId());
cm.setFrom(change.getOwner());
cm.setPatchSet(patchSet, patchSetInfo);
cm.setNotify(notify);
cm.setAccountsToNotify(accountsToNotify);
cm.addReviewers(reviewers);
cm.addExtraCC(extraCC);
cm.send();
} catch (Exception e) {
log.error("Cannot send email for new change " + change.getId(), e);
}
}
@Override
public String toString() {
return "send-email newchange";
}
};
if (requestScopePropagator != null) {
@SuppressWarnings("unused") Future<?> possiblyIgnoredError = sendEmailExecutor.submit(requestScopePropagator.wrap(sender));
} else {
sender.run();
}
}
/* For labels that are not set in this operation, show the "current" value
* of 0, and no oldValue as the value was not modified by this operation.
* For labels that are set in this operation, the value was modified, so
* show a transition from an oldValue of 0 to the new value.
*/
if (fireRevisionCreated) {
revisionCreated.fire(change, patchSet, ctx.getAccount(), ctx.getWhen(), notify);
if (approvals != null && !approvals.isEmpty()) {
ChangeControl changeControl = changeControlFactory.controlFor(ctx.getDb(), change, ctx.getUser());
List<LabelType> labels = changeControl.getLabelTypes().getLabelTypes();
Map<String, Short> allApprovals = new HashMap<>();
Map<String, Short> oldApprovals = new HashMap<>();
for (LabelType lt : labels) {
allApprovals.put(lt.getName(), (short) 0);
oldApprovals.put(lt.getName(), null);
}
for (Map.Entry<String, Short> entry : approvals.entrySet()) {
if (entry.getValue() != 0) {
allApprovals.put(entry.getKey(), entry.getValue());
oldApprovals.put(entry.getKey(), (short) 0);
}
}
commentAdded.fire(change, patchSet, ctx.getAccount(), null, allApprovals, oldApprovals, ctx.getWhen());
}
}
}
Aggregations