Search in sources :

Example 81 with PatchSet

use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.

the class AbandonOp method updateChange.

@Override
public boolean updateChange(ChangeContext ctx) throws ResourceConflictException {
    change = ctx.getChange();
    PatchSet.Id psId = change.currentPatchSetId();
    ChangeUpdate update = ctx.getUpdate(psId);
    if (!change.isNew()) {
        throw new ResourceConflictException("change is " + ChangeUtil.status(change));
    }
    patchSet = psUtil.get(ctx.getNotes(), psId);
    change.setStatus(Change.Status.ABANDONED);
    change.setLastUpdatedOn(ctx.getWhen());
    update.setStatus(change.getStatus());
    mailMessage = cmUtil.setChangeMessage(ctx, commentMessage(), ChangeMessagesUtil.TAG_ABANDON);
    return true;
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) PatchSet(com.google.gerrit.entities.PatchSet) ChangeUpdate(com.google.gerrit.server.notedb.ChangeUpdate)

Example 82 with PatchSet

use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.

the class EventFactory method addPatchSets.

public void addPatchSets(RevWalk revWalk, ChangeAttribute ca, Collection<PatchSet> ps, Map<PatchSet.Id, Collection<PatchSetApproval>> approvals, boolean includeFiles, Change change, LabelTypes labelTypes) {
    if (!ps.isEmpty()) {
        ca.patchSets = new ArrayList<>(ps.size());
        for (PatchSet p : ps) {
            PatchSetAttribute psa = asPatchSetAttribute(revWalk, change, p);
            if (approvals != null) {
                addApprovals(psa, p.id(), approvals, labelTypes);
            }
            ca.patchSets.add(psa);
            if (includeFiles) {
                addPatchSetFileNames(psa, change, p);
            }
        }
    }
}
Also used : PatchSetAttribute(com.google.gerrit.server.data.PatchSetAttribute) PatchSet(com.google.gerrit.entities.PatchSet)

Example 83 with PatchSet

use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.

the class ChangeEditModifier method createEdit.

/**
 * Creates a new change edit.
 *
 * @param repository the affected Git repository
 * @param notes the {@link ChangeNotes} of the change for which the change edit should be created
 * @throws AuthException if the user isn't authenticated or not allowed to use change edits
 * @throws InvalidChangeOperationException if a change edit already existed for the change
 */
public void createEdit(Repository repository, ChangeNotes notes) throws AuthException, IOException, InvalidChangeOperationException, PermissionBackendException, ResourceConflictException {
    assertCanEdit(notes);
    Optional<ChangeEdit> changeEdit = lookupChangeEdit(notes);
    if (changeEdit.isPresent()) {
        throw new InvalidChangeOperationException(String.format("A change edit already exists for change %s", notes.getChangeId()));
    }
    PatchSet currentPatchSet = lookupCurrentPatchSet(notes);
    ObjectId patchSetCommitId = currentPatchSet.commitId();
    noteDbEdits.createEdit(repository, notes, currentPatchSet, patchSetCommitId, TimeUtil.now());
}
Also used : InvalidChangeOperationException(com.google.gerrit.server.project.InvalidChangeOperationException) ObjectId(org.eclipse.jgit.lib.ObjectId) PatchSet(com.google.gerrit.entities.PatchSet)

Example 84 with PatchSet

use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.

the class StreamEventsApiListener method onCommentAdded.

@Override
public void onCommentAdded(CommentAddedListener.Event ev) {
    try {
        ChangeNotes notes = getNotes(ev.getChange());
        Change change = notes.getChange();
        PatchSet ps = getPatchSet(notes, ev.getRevision());
        CommentAddedEvent event = new CommentAddedEvent(change);
        event.change = changeAttributeSupplier(change, notes);
        event.author = accountAttributeSupplier(ev.getWho());
        event.patchSet = patchSetAttributeSupplier(change, ps);
        event.comment = ev.getComment();
        event.approvals = approvalsAttributeSupplier(change, ev.getApprovals(), ev.getOldApprovals());
        dispatcher.run(d -> d.postEvent(change, event));
    } catch (StorageException e) {
        logger.atSevere().withCause(e).log("Failed to dispatch event");
    }
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) Change(com.google.gerrit.entities.Change) StorageException(com.google.gerrit.exceptions.StorageException)

Example 85 with PatchSet

use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.

the class StreamEventsApiListener method onWorkInProgressStateChanged.

@Override
public void onWorkInProgressStateChanged(WorkInProgressStateChangedListener.Event ev) {
    try {
        ChangeNotes notes = getNotes(ev.getChange());
        Change change = notes.getChange();
        PatchSet patchSet = getPatchSet(notes, ev.getRevision());
        WorkInProgressStateChangedEvent event = new WorkInProgressStateChangedEvent(change);
        event.change = changeAttributeSupplier(change, notes);
        event.changer = accountAttributeSupplier(ev.getWho());
        event.patchSet = patchSetAttributeSupplier(change, patchSet);
        dispatcher.run(d -> d.postEvent(change, event));
    } catch (StorageException e) {
        logger.atSevere().withCause(e).log("Failed to dispatch event");
    }
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) Change(com.google.gerrit.entities.Change) StorageException(com.google.gerrit.exceptions.StorageException)

Aggregations

PatchSet (com.google.gerrit.entities.PatchSet)123 Change (com.google.gerrit.entities.Change)61 Test (org.junit.Test)48 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)41 ObjectId (org.eclipse.jgit.lib.ObjectId)35 RevCommit (org.eclipse.jgit.revwalk.RevCommit)29 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)28 Project (com.google.gerrit.entities.Project)25 StorageException (com.google.gerrit.exceptions.StorageException)25 Repository (org.eclipse.jgit.lib.Repository)22 IOException (java.io.IOException)20 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)19 ChangeData (com.google.gerrit.server.query.change.ChangeData)18 HumanComment (com.google.gerrit.entities.HumanComment)16 RevWalk (org.eclipse.jgit.revwalk.RevWalk)16 Inject (com.google.inject.Inject)14 Map (java.util.Map)14 List (java.util.List)13 ImmutableList (com.google.common.collect.ImmutableList)12 AuthException (com.google.gerrit.extensions.restapi.AuthException)11