Search in sources :

Example 31 with ChangeMessage

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

the class DeleteReviewerByEmailOp method updateChange.

@Override
public boolean updateChange(ChangeContext ctx) throws OrmException {
    changeId = ctx.getChange().getId();
    PatchSet.Id psId = ctx.getChange().currentPatchSetId();
    String msg = "Removed reviewer " + reviewer;
    changeMessage = new ChangeMessage(new ChangeMessage.Key(changeId, ChangeUtil.messageUuid()), ctx.getAccountId(), ctx.getWhen(), psId);
    changeMessage.setMessage(msg);
    ctx.getUpdate(psId).setChangeMessage(msg);
    ctx.getUpdate(psId).removeReviewerByEmail(reviewer);
    return true;
}
Also used : ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) PatchSet(com.google.gerrit.reviewdb.client.PatchSet)

Example 32 with ChangeMessage

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

the class ChangeBundle method getLatestTimestamp.

private Timestamp getLatestTimestamp() {
    Ordering<Timestamp> o = Ordering.natural().nullsFirst();
    Timestamp ts = null;
    for (ChangeMessage cm : filterChangeMessages()) {
        ts = o.max(ts, cm.getWrittenOn());
    }
    for (PatchSet ps : getPatchSets()) {
        ts = o.max(ts, ps.getCreatedOn());
    }
    for (PatchSetApproval psa : filterPatchSetApprovals().values()) {
        ts = o.max(ts, psa.getGranted());
    }
    for (PatchLineComment plc : filterPatchLineComments().values()) {
        // Ignore draft comments, as they do not show up in the change meta graph.
        if (plc.getStatus() != PatchLineComment.Status.DRAFT) {
            ts = o.max(ts, plc.getWrittenOn());
        }
    }
    return firstNonNull(ts, change.getLastUpdatedOn());
}
Also used : PatchLineComment(com.google.gerrit.reviewdb.client.PatchLineComment) ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Timestamp(java.sql.Timestamp) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval)

Example 33 with ChangeMessage

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

the class ChangeJson method messages.

private Collection<ChangeMessageInfo> messages(ChangeControl ctl, ChangeData cd, Map<PatchSet.Id, PatchSet> map) throws OrmException {
    List<ChangeMessage> messages = cmUtil.byChange(db.get(), cd.notes());
    if (messages.isEmpty()) {
        return Collections.emptyList();
    }
    List<ChangeMessageInfo> result = Lists.newArrayListWithCapacity(messages.size());
    for (ChangeMessage message : messages) {
        PatchSet.Id patchNum = message.getPatchSetId();
        PatchSet ps = patchNum != null ? map.get(patchNum) : null;
        if (patchNum == null || ctl.isPatchVisible(ps, db.get())) {
            ChangeMessageInfo cmi = new ChangeMessageInfo();
            cmi.id = message.getKey().get();
            cmi.author = accountLoader.get(message.getAuthor());
            cmi.date = message.getWrittenOn();
            cmi.message = message.getMessage();
            cmi.tag = message.getTag();
            cmi._revisionNumber = patchNum != null ? patchNum.get() : null;
            Account.Id realAuthor = message.getRealAuthor();
            if (realAuthor != null) {
                cmi.realAuthor = accountLoader.get(realAuthor);
            }
            result.add(cmi);
        }
    }
    return result;
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) PatchSet(com.google.gerrit.reviewdb.client.PatchSet)

Example 34 with ChangeMessage

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

the class Submit method mergeChange.

public Change mergeChange(BatchUpdate.Factory updateFactory, RevisionResource rsrc, IdentifiedUser submitter, SubmitInput input) throws OrmException, RestApiException, IOException {
    Change change = rsrc.getChange();
    if (!change.getStatus().isOpen()) {
        throw new ResourceConflictException("change is " + ChangeUtil.status(change));
    } else if (!ProjectUtil.branchExists(repoManager, change.getDest())) {
        throw new ResourceConflictException(String.format("destination branch \"%s\" not found.", change.getDest().get()));
    } else if (!rsrc.getPatchSet().getId().equals(change.currentPatchSetId())) {
        // TODO Allow submitting non-current revision by changing the current.
        throw new ResourceConflictException(String.format("revision %s is not current revision", rsrc.getPatchSet().getRevision().get()));
    }
    try (MergeOp op = mergeOpFactory.create(updateFactory)) {
        ReviewDb db = dbProvider.get();
        op.merge(db, change, submitter, true, input, false);
        try {
            change = changeNotesFactory.createChecked(db, change.getProject(), change.getId()).getChange();
        } catch (NoSuchChangeException e) {
            throw new ResourceConflictException("change is deleted");
        }
    }
    switch(change.getStatus()) {
        case MERGED:
            return change;
        case NEW:
            ChangeMessage msg = getConflictMessage(rsrc);
            if (msg != null) {
                throw new ResourceConflictException(msg.getMessage());
            }
        //$FALL-THROUGH$
        case ABANDONED:
        case DRAFT:
        default:
            throw new ResourceConflictException("change is " + ChangeUtil.status(change));
    }
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) NoSuchChangeException(com.google.gerrit.server.project.NoSuchChangeException) ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) MergeOp(com.google.gerrit.server.git.MergeOp) Change(com.google.gerrit.reviewdb.client.Change) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb)

Example 35 with ChangeMessage

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

the class SetAssigneeOp method addMessage.

private void addMessage(ChangeContext ctx, ChangeUpdate update) throws OrmException {
    StringBuilder msg = new StringBuilder();
    msg.append("Assignee ");
    if (oldAssignee == null) {
        msg.append("added: ");
        msg.append(newAssignee.getNameEmail());
    } else {
        msg.append("changed from: ");
        msg.append(oldAssignee.getNameEmail());
        msg.append(" to: ");
        msg.append(newAssignee.getNameEmail());
    }
    ChangeMessage cmsg = ChangeMessagesUtil.newMessage(ctx, msg.toString(), ChangeMessagesUtil.TAG_SET_ASSIGNEE);
    cmUtil.addChangeMessage(ctx.getDb(), update, cmsg);
}
Also used : ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage)

Aggregations

ChangeMessage (com.google.gerrit.reviewdb.client.ChangeMessage)42 Change (com.google.gerrit.reviewdb.client.Change)31 Test (org.junit.Test)25 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)16 ObjectId (org.eclipse.jgit.lib.ObjectId)11 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)9 PatchSetApproval (com.google.gerrit.reviewdb.client.PatchSetApproval)9 RevId (com.google.gerrit.reviewdb.client.RevId)8 GerritServerId (com.google.gerrit.server.config.GerritServerId)7 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)6 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)6 RequestId (com.google.gerrit.server.util.RequestId)6 Account (com.google.gerrit.reviewdb.client.Account)5 Comment (com.google.gerrit.reviewdb.client.Comment)5 ChangeData (com.google.gerrit.server.query.change.ChangeData)5 CommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput)4 PatchLineComment (com.google.gerrit.reviewdb.client.PatchLineComment)4 Timestamp (java.sql.Timestamp)3 ArrayList (java.util.ArrayList)3 Table (com.google.common.collect.Table)2