use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.
the class ChangeEditModifier method modifyCommit.
private ChangeEdit modifyCommit(Repository repository, ChangeNotes notes, ModificationIntention modificationIntention, CommitModification commitModification) throws AuthException, BadRequestException, IOException, InvalidChangeOperationException, PermissionBackendException, ResourceConflictException {
assertCanEdit(notes);
Optional<ChangeEdit> optionalChangeEdit = lookupChangeEdit(notes);
EditBehavior editBehavior = optionalChangeEdit.<EditBehavior>map(changeEdit -> new ExistingEditBehavior(changeEdit, noteDbEdits)).orElseGet(() -> new NewEditBehavior(noteDbEdits));
ModificationTarget modificationTarget = editBehavior.getModificationTarget(notes, modificationIntention);
RevCommit commitToModify = modificationTarget.getCommit(repository);
ObjectId newTreeId = createNewTree(repository, commitToModify, commitModification.treeModifications());
newTreeId = editBehavior.mergeTreesIfNecessary(repository, newTreeId, commitToModify);
PatchSet basePatchset = modificationTarget.getBasePatchset();
RevCommit basePatchsetCommit = NoteDbEdits.lookupCommit(repository, basePatchset.commitId());
boolean changeIdRequired = projectCache.get(notes.getChange().getProject()).orElseThrow(illegalState(notes.getChange().getProject())).is(BooleanProjectConfig.REQUIRE_CHANGE_ID);
String currentChangeId = notes.getChange().getKey().get();
String newCommitMessage = createNewCommitMessage(changeIdRequired, currentChangeId, editBehavior, commitModification, commitToModify);
newCommitMessage = editBehavior.mergeCommitMessageIfNecessary(newCommitMessage, commitToModify);
Optional<ChangeEdit> unmodifiedEdit = editBehavior.getEditIfNoModification(newTreeId, newCommitMessage);
if (unmodifiedEdit.isPresent()) {
return unmodifiedEdit.get();
}
Instant nowTimestamp = TimeUtil.now();
ObjectId newEditCommit = createCommit(repository, basePatchsetCommit, newTreeId, newCommitMessage, nowTimestamp);
return editBehavior.updateEditInStorage(repository, notes, basePatchset, newEditCommit, nowTimestamp);
}
use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.
the class StreamEventsApiListener method onTopicEdited.
@Override
public void onTopicEdited(TopicEditedListener.Event ev) {
try {
ChangeNotes notes = getNotes(ev.getChange());
Change change = notes.getChange();
TopicChangedEvent event = new TopicChangedEvent(change);
event.change = changeAttributeSupplier(change, notes);
event.changer = accountAttributeSupplier(ev.getWho());
event.oldTopic = ev.getOldTopic();
dispatcher.run(d -> d.postEvent(change, event));
} catch (StorageException e) {
logger.atSevere().withCause(e).log("Failed to dispatch event");
}
}
use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.
the class StreamEventsApiListener method onReviewerDeleted.
@Override
public void onReviewerDeleted(ReviewerDeletedListener.Event ev) {
try {
ChangeNotes notes = getNotes(ev.getChange());
Change change = notes.getChange();
ReviewerDeletedEvent event = new ReviewerDeletedEvent(change);
event.change = changeAttributeSupplier(change, notes);
event.patchSet = patchSetAttributeSupplier(change, psUtil.current(notes));
event.reviewer = accountAttributeSupplier(ev.getReviewer());
event.remover = accountAttributeSupplier(ev.getWho());
event.comment = ev.getComment();
event.approvals = approvalsAttributeSupplier(change, ev.getNewApprovals(), ev.getOldApprovals());
dispatcher.run(d -> d.postEvent(change, event));
} catch (StorageException e) {
logger.atSevere().withCause(e).log("Failed to dispatch event");
}
}
use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.
the class StreamEventsApiListener method onChangeRestored.
@Override
public void onChangeRestored(ChangeRestoredListener.Event ev) {
try {
ChangeNotes notes = getNotes(ev.getChange());
Change change = notes.getChange();
ChangeRestoredEvent event = new ChangeRestoredEvent(change);
event.change = changeAttributeSupplier(change, notes);
event.restorer = accountAttributeSupplier(ev.getWho());
event.patchSet = patchSetAttributeSupplier(change, psUtil.current(notes));
event.reason = ev.getReason();
dispatcher.run(d -> d.postEvent(change, event));
} catch (StorageException e) {
logger.atSevere().withCause(e).log("Failed to dispatch event");
}
}
use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.
the class StreamEventsApiListener method onChangeMerged.
@Override
public void onChangeMerged(ChangeMergedListener.Event ev) {
try {
ChangeNotes notes = getNotes(ev.getChange());
Change change = notes.getChange();
ChangeMergedEvent event = new ChangeMergedEvent(change);
event.change = changeAttributeSupplier(change, notes);
event.submitter = accountAttributeSupplier(ev.getWho());
event.patchSet = patchSetAttributeSupplier(change, psUtil.current(notes));
event.newRev = ev.getNewRevisionId();
dispatcher.run(d -> d.postEvent(change, event));
} catch (StorageException e) {
logger.atSevere().withCause(e).log("Failed to dispatch event");
}
}
Aggregations