Search in sources :

Example 36 with ChangeNotes

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);
}
Also used : CommitMessageUtil(com.google.gerrit.server.util.CommitMessageUtil) ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) ProjectCache(com.google.gerrit.server.project.ProjectCache) Inject(com.google.inject.Inject) RawTextComparator(org.eclipse.jgit.diff.RawTextComparator) ChangeFileContentModification(com.google.gerrit.server.edit.tree.ChangeFileContentModification) ReceiveCommand(org.eclipse.jgit.transport.ReceiveCommand) InvalidPathException(org.eclipse.jgit.dircache.InvalidPathException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) RevWalk(org.eclipse.jgit.revwalk.RevWalk) MergeConflictException(com.google.gerrit.extensions.restapi.MergeConflictException) ChangeIndexer(com.google.gerrit.server.index.change.ChangeIndexer) InvalidChangeOperationException(com.google.gerrit.server.project.InvalidChangeOperationException) RefNames(com.google.gerrit.entities.RefNames) AuthException(com.google.gerrit.extensions.restapi.AuthException) RawText(org.eclipse.jgit.diff.RawText) RawInput(com.google.gerrit.extensions.restapi.RawInput) MergeChunk(org.eclipse.jgit.merge.MergeChunk) MergeAlgorithm(org.eclipse.jgit.merge.MergeAlgorithm) TimeZone(java.util.TimeZone) RefUpdate(org.eclipse.jgit.lib.RefUpdate) Instant(java.time.Instant) NullProgressMonitor(org.eclipse.jgit.lib.NullProgressMonitor) MergeStrategy(org.eclipse.jgit.merge.MergeStrategy) RevTree(org.eclipse.jgit.revwalk.RevTree) Objects(java.util.Objects) PersonIdent(org.eclipse.jgit.lib.PersonIdent) List(java.util.List) BatchRefUpdate(org.eclipse.jgit.lib.BatchRefUpdate) BooleanProjectConfig(com.google.gerrit.entities.BooleanProjectConfig) Optional(java.util.Optional) Singleton(com.google.inject.Singleton) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) RevCommit(org.eclipse.jgit.revwalk.RevCommit) ChangePermission(com.google.gerrit.server.permissions.ChangePermission) CommitBuilder(org.eclipse.jgit.lib.CommitBuilder) Change(com.google.gerrit.entities.Change) PatchSet(com.google.gerrit.entities.PatchSet) ChangeUtil(com.google.gerrit.server.ChangeUtil) LockFailureException(com.google.gerrit.git.LockFailureException) Charsets(com.google.common.base.Charsets) TreeModification(com.google.gerrit.server.edit.tree.TreeModification) SupportedAlgorithm(org.eclipse.jgit.diff.DiffAlgorithm.SupportedAlgorithm) ProjectCache.illegalState(com.google.gerrit.server.project.ProjectCache.illegalState) CurrentUser(com.google.gerrit.server.CurrentUser) TreeCreator(com.google.gerrit.server.edit.tree.TreeCreator) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) IOException(java.io.IOException) ThreeWayMerger(org.eclipse.jgit.merge.ThreeWayMerger) DiffAlgorithm(org.eclipse.jgit.diff.DiffAlgorithm) DeleteFileModification(com.google.gerrit.server.edit.tree.DeleteFileModification) RenameFileModification(com.google.gerrit.server.edit.tree.RenameFileModification) ObjectId(org.eclipse.jgit.lib.ObjectId) MergeResult(org.eclipse.jgit.merge.MergeResult) RestoreFileModification(com.google.gerrit.server.edit.tree.RestoreFileModification) Provider(com.google.inject.Provider) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) Project(com.google.gerrit.entities.Project) TimeUtil(com.google.gerrit.server.util.time.TimeUtil) PatchSetUtil(com.google.gerrit.server.PatchSetUtil) GerritPersonIdent(com.google.gerrit.server.GerritPersonIdent) Repository(org.eclipse.jgit.lib.Repository) ObjectId(org.eclipse.jgit.lib.ObjectId) Instant(java.time.Instant) PatchSet(com.google.gerrit.entities.PatchSet) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 37 with ChangeNotes

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");
    }
}
Also used : ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) Change(com.google.gerrit.entities.Change) StorageException(com.google.gerrit.exceptions.StorageException)

Example 38 with ChangeNotes

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");
    }
}
Also used : ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) Change(com.google.gerrit.entities.Change) StorageException(com.google.gerrit.exceptions.StorageException)

Example 39 with ChangeNotes

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");
    }
}
Also used : ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) Change(com.google.gerrit.entities.Change) StorageException(com.google.gerrit.exceptions.StorageException)

Example 40 with ChangeNotes

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");
    }
}
Also used : ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) Change(com.google.gerrit.entities.Change) StorageException(com.google.gerrit.exceptions.StorageException)

Aggregations

ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)134 Test (org.junit.Test)54 Change (com.google.gerrit.entities.Change)47 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)43 PatchSet (com.google.gerrit.entities.PatchSet)42 ObjectId (org.eclipse.jgit.lib.ObjectId)33 StorageException (com.google.gerrit.exceptions.StorageException)22 Change (com.google.gerrit.reviewdb.client.Change)21 Project (com.google.gerrit.entities.Project)17 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)16 FixInput (com.google.gerrit.extensions.api.changes.FixInput)16 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)14 HumanComment (com.google.gerrit.entities.HumanComment)13 TestChanges.newPatchSet (com.google.gerrit.testing.TestChanges.newPatchSet)12 IOException (java.io.IOException)12 RevCommit (org.eclipse.jgit.revwalk.RevCommit)12 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)11 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)10 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)10 AuthException (com.google.gerrit.extensions.restapi.AuthException)9