Search in sources :

Example 41 with ChangeMessage

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

the class MergedByPushOp method updateChange.

@Override
public boolean updateChange(ChangeContext ctx) throws OrmException, IOException {
    change = ctx.getChange();
    correctBranch = refName.equals(change.getDest().get());
    if (!correctBranch) {
        return false;
    }
    if (patchSetProvider != null) {
        // Caller might have also arranged for construction of a new patch set
        // that is not present in the old notes so we can't use PatchSetUtil.
        patchSet = patchSetProvider.get();
    } else {
        patchSet = checkNotNull(psUtil.get(ctx.getDb(), ctx.getNotes(), psId), "patch set %s not found", psId);
    }
    info = getPatchSetInfo(ctx);
    ChangeUpdate update = ctx.getUpdate(psId);
    Change.Status status = change.getStatus();
    if (status == Change.Status.MERGED) {
        return true;
    }
    if (status.isOpen()) {
        change.setCurrentPatchSet(info);
        change.setStatus(Change.Status.MERGED);
        // we cannot reconstruct the submit records for when this change was
        // submitted, this is why we must fix the status
        update.fixStatus(Change.Status.MERGED);
        update.setCurrentPatchSet();
    }
    StringBuilder msgBuf = new StringBuilder();
    msgBuf.append("Change has been successfully pushed");
    if (!refName.equals(change.getDest().get())) {
        msgBuf.append(" into ");
        if (refName.startsWith(Constants.R_HEADS)) {
            msgBuf.append("branch ");
            msgBuf.append(Repository.shortenRefName(refName));
        } else {
            msgBuf.append(refName);
        }
    }
    msgBuf.append(".");
    ChangeMessage msg = ChangeMessagesUtil.newMessage(psId, ctx.getUser(), ctx.getWhen(), msgBuf.toString(), ChangeMessagesUtil.TAG_MERGED);
    cmUtil.addChangeMessage(ctx.getDb(), update, msg);
    PatchSetApproval submitter = ApprovalsUtil.newApproval(change.currentPatchSetId(), ctx.getUser(), LabelId.legacySubmit(), 1, ctx.getWhen());
    update.putApproval(submitter.getLabel(), submitter.getValue());
    ctx.getDb().patchSetApprovals().upsert(Collections.singleton(submitter));
    return true;
}
Also used : ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) Change(com.google.gerrit.reviewdb.client.Change) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) ChangeUpdate(com.google.gerrit.server.notedb.ChangeUpdate)

Example 42 with ChangeMessage

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

the class ChangeData method reviewedBy.

public Set<Account.Id> reviewedBy() throws OrmException {
    if (reviewedBy == null) {
        if (!lazyLoad) {
            return Collections.emptySet();
        }
        Change c = change();
        if (c == null) {
            return Collections.emptySet();
        }
        List<ReviewedByEvent> events = new ArrayList<>();
        for (ChangeMessage msg : messages()) {
            if (msg.getAuthor() != null) {
                events.add(ReviewedByEvent.create(msg));
            }
        }
        events = Lists.reverse(events);
        reviewedBy = new LinkedHashSet<>();
        Account.Id owner = c.getOwner();
        for (ReviewedByEvent event : events) {
            if (owner.equals(event.author())) {
                break;
            }
            reviewedBy.add(event.author());
        }
    }
    return reviewedBy;
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) ArrayList(java.util.ArrayList) ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) Change(com.google.gerrit.reviewdb.client.Change)

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