Search in sources :

Example 1 with ChangeMessage

use of com.google.gerrit.reviewdb.client.ChangeMessage in project gerrit by GerritCodeReview.

the class WorkInProgressOp method addMessage.

private void addMessage(ChangeContext ctx, ChangeUpdate update) throws OrmException {
    Change c = ctx.getChange();
    StringBuilder buf = new StringBuilder(c.isWorkInProgress() ? "Set Work In Progress" : "Set Ready For Review");
    String m = Strings.nullToEmpty(in == null ? null : in.message).trim();
    if (!m.isEmpty()) {
        buf.append("\n\n");
        buf.append(m);
    }
    ChangeMessage cmsg = ChangeMessagesUtil.newMessage(ctx, buf.toString(), c.isWorkInProgress() ? ChangeMessagesUtil.TAG_SET_WIP : ChangeMessagesUtil.TAG_SET_READY);
    cmUtil.addChangeMessage(ctx.getDb(), update, cmsg);
}
Also used : ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) Change(com.google.gerrit.reviewdb.client.Change)

Example 2 with ChangeMessage

use of com.google.gerrit.reviewdb.client.ChangeMessage in project gerrit by GerritCodeReview.

the class SetPrivateOp method addMessage.

private void addMessage(ChangeContext ctx, ChangeUpdate update) throws OrmException {
    Change c = ctx.getChange();
    StringBuilder buf = new StringBuilder(c.isPrivate() ? "Set private" : "Unset private");
    String m = Strings.nullToEmpty(input == null ? null : input.message).trim();
    if (!m.isEmpty()) {
        buf.append("\n\n");
        buf.append(m);
    }
    ChangeMessage cmsg = ChangeMessagesUtil.newMessage(ctx, buf.toString(), c.isPrivate() ? ChangeMessagesUtil.TAG_SET_PRIVATE : ChangeMessagesUtil.TAG_UNSET_PRIVATE);
    cmUtil.addChangeMessage(ctx.getDb(), update, cmsg);
}
Also used : ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) Change(com.google.gerrit.reviewdb.client.Change)

Example 3 with ChangeMessage

use of com.google.gerrit.reviewdb.client.ChangeMessage in project gerrit by GerritCodeReview.

the class SetHashtagsOp method addMessage.

private void addMessage(ChangeContext ctx, ChangeUpdate update) throws OrmException {
    StringBuilder msg = new StringBuilder();
    appendHashtagMessage(msg, "added", toAdd);
    appendHashtagMessage(msg, "removed", toRemove);
    ChangeMessage cmsg = ChangeMessagesUtil.newMessage(ctx, msg.toString(), ChangeMessagesUtil.TAG_SET_HASHTAGS);
    cmUtil.addChangeMessage(ctx.getDb(), update, cmsg);
}
Also used : ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage)

Example 4 with ChangeMessage

use of com.google.gerrit.reviewdb.client.ChangeMessage in project gerrit by GerritCodeReview.

the class MergeOp method abandonAllOpenChangeForDeletedProject.

private void abandonAllOpenChangeForDeletedProject(Project.NameKey destProject) {
    try {
        for (ChangeData cd : internalChangeQuery.byProjectOpen(destProject)) {
            try (BatchUpdate bu = batchUpdateFactory.create(db, destProject, internalUserFactory.create(), ts)) {
                bu.setRequestId(submissionId);
                bu.addOp(cd.getId(), new BatchUpdateOp() {

                    @Override
                    public boolean updateChange(ChangeContext ctx) throws OrmException {
                        Change change = ctx.getChange();
                        if (!change.getStatus().isOpen()) {
                            return false;
                        }
                        change.setStatus(Change.Status.ABANDONED);
                        ChangeMessage msg = ChangeMessagesUtil.newMessage(change.currentPatchSetId(), internalUserFactory.create(), change.getLastUpdatedOn(), ChangeMessagesUtil.TAG_MERGED, "Project was deleted.");
                        cmUtil.addChangeMessage(ctx.getDb(), ctx.getUpdate(change.currentPatchSetId()), msg);
                        return true;
                    }
                });
                try {
                    bu.execute();
                } catch (UpdateException | RestApiException e) {
                    logWarn("Cannot abandon changes for deleted project " + destProject, e);
                }
            }
        }
    } catch (OrmException e) {
        logWarn("Cannot abandon changes for deleted project " + destProject, e);
    }
}
Also used : ChangeContext(com.google.gerrit.server.update.ChangeContext) OrmException(com.google.gwtorm.server.OrmException) ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) Change(com.google.gerrit.reviewdb.client.Change) UpdateException(com.google.gerrit.server.update.UpdateException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) ChangeData(com.google.gerrit.server.query.change.ChangeData) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) BatchUpdateOp(com.google.gerrit.server.update.BatchUpdateOp)

Example 5 with ChangeMessage

use of com.google.gerrit.reviewdb.client.ChangeMessage in project gerrit by GerritCodeReview.

the class ChangeRebuilderImpl method buildUpdates.

@Override
public void buildUpdates(NoteDbUpdateManager manager, ChangeBundle bundle) throws IOException, OrmException {
    manager.setCheckExpectedState(false).setRefLogMessage("Rebuilding change");
    Change change = new Change(bundle.getChange());
    if (bundle.getPatchSets().isEmpty()) {
        throw new NoPatchSetsException(change.getId());
    }
    // We will rebuild all events, except for draft comments, in buckets based
    // on author and timestamp.
    List<Event> events = new ArrayList<>();
    ListMultimap<Account.Id, DraftCommentEvent> draftCommentEvents = MultimapBuilder.hashKeys().arrayListValues().build();
    events.addAll(getHashtagsEvents(change, manager));
    // Delete ref only after hashtags have been read
    deleteChangeMetaRef(change, manager.getChangeRepo().cmds);
    deleteDraftRefs(change, manager.getAllUsersRepo());
    Integer minPsNum = getMinPatchSetNum(bundle);
    TreeMap<PatchSet.Id, PatchSetEvent> patchSetEvents = new TreeMap<>(ReviewDbUtil.intKeyOrdering());
    for (PatchSet ps : bundle.getPatchSets()) {
        PatchSetEvent pse = new PatchSetEvent(change, ps, manager.getChangeRepo().rw);
        patchSetEvents.put(ps.getId(), pse);
        events.add(pse);
        for (Comment c : getComments(bundle, serverId, Status.PUBLISHED, ps)) {
            CommentEvent e = new CommentEvent(c, change, ps, patchListCache);
            events.add(e.addDep(pse));
        }
        for (Comment c : getComments(bundle, serverId, Status.DRAFT, ps)) {
            DraftCommentEvent e = new DraftCommentEvent(c, change, ps, patchListCache);
            draftCommentEvents.put(c.author.getId(), e);
        }
    }
    ensurePatchSetOrder(patchSetEvents);
    for (PatchSetApproval psa : bundle.getPatchSetApprovals()) {
        PatchSetEvent pse = patchSetEvents.get(psa.getPatchSetId());
        if (pse != null) {
            events.add(new ApprovalEvent(psa, change.getCreatedOn()).addDep(pse));
        }
    }
    for (Table.Cell<ReviewerStateInternal, Account.Id, Timestamp> r : bundle.getReviewers().asTable().cellSet()) {
        events.add(new ReviewerEvent(r, change.getCreatedOn()));
    }
    Change noteDbChange = new Change(null, null, null, null, null);
    for (ChangeMessage msg : bundle.getChangeMessages()) {
        Event msgEvent = new ChangeMessageEvent(change, noteDbChange, msg, change.getCreatedOn());
        if (msg.getPatchSetId() != null) {
            PatchSetEvent pse = patchSetEvents.get(msg.getPatchSetId());
            if (pse == null) {
                // Ignore events for missing patch sets.
                continue;
            }
            msgEvent.addDep(pse);
        }
        events.add(msgEvent);
    }
    sortAndFillEvents(change, noteDbChange, bundle.getPatchSets(), events, minPsNum);
    EventList<Event> el = new EventList<>();
    for (Event e : events) {
        if (!el.canAdd(e)) {
            flushEventsToUpdate(manager, el, change);
            checkState(el.canAdd(e));
        }
        el.add(e);
    }
    flushEventsToUpdate(manager, el, change);
    EventList<DraftCommentEvent> plcel = new EventList<>();
    for (Account.Id author : draftCommentEvents.keys()) {
        for (DraftCommentEvent e : Ordering.natural().sortedCopy(draftCommentEvents.get(author))) {
            if (!plcel.canAdd(e)) {
                flushEventsToDraftUpdate(manager, plcel, change);
                checkState(plcel.canAdd(e));
            }
            plcel.add(e);
        }
        flushEventsToDraftUpdate(manager, plcel, change);
    }
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) ArrayList(java.util.ArrayList) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) Timestamp(java.sql.Timestamp) PatchLineComment(com.google.gerrit.reviewdb.client.PatchLineComment) Comment(com.google.gerrit.reviewdb.client.Comment) Table(com.google.common.collect.Table) ReviewerStateInternal(com.google.gerrit.server.notedb.ReviewerStateInternal) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) TreeMap(java.util.TreeMap) ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) GerritServerId(com.google.gerrit.server.config.GerritServerId) ObjectId(org.eclipse.jgit.lib.ObjectId)

Aggregations

ChangeMessage (com.google.gerrit.reviewdb.client.ChangeMessage)29 Change (com.google.gerrit.reviewdb.client.Change)21 Test (org.junit.Test)15 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)10 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)7 PatchSetApproval (com.google.gerrit.reviewdb.client.PatchSetApproval)5 ObjectId (org.eclipse.jgit.lib.ObjectId)5 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)4 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)4 CommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput)4 Account (com.google.gerrit.reviewdb.client.Account)4 Comment (com.google.gerrit.reviewdb.client.Comment)4 PatchLineComment (com.google.gerrit.reviewdb.client.PatchLineComment)4 Timestamp (java.sql.Timestamp)3 Table (com.google.common.collect.Table)2 DraftInput (com.google.gerrit.extensions.api.changes.DraftInput)2 LabelId (com.google.gerrit.reviewdb.client.LabelId)2 RevId (com.google.gerrit.reviewdb.client.RevId)2 ChangeData (com.google.gerrit.server.query.change.ChangeData)2 ArrayList (java.util.ArrayList)2