Search in sources :

Example 1 with SubmissionId

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

the class ChangeNotesTest method lastUpdatedOnChangeNotes.

@Test
public void lastUpdatedOnChangeNotes() throws Exception {
    Change c = newChange();
    ChangeNotes notes = newNotes(c);
    Instant ts1 = notes.getChange().getLastUpdatedOn();
    assertThat(ts1).isEqualTo(notes.getChange().getCreatedOn());
    // Various kinds of updates that update the timestamp.
    ChangeUpdate update = newUpdate(c, changeOwner);
    // Change something to get a new commit.
    update.setTopic("topic");
    update.commit();
    Instant ts2 = newNotes(c).getChange().getLastUpdatedOn();
    assertThat(ts2).isGreaterThan(ts1);
    update = newUpdate(c, changeOwner);
    update.setChangeMessage("Some message");
    update.commit();
    Instant ts3 = newNotes(c).getChange().getLastUpdatedOn();
    assertThat(ts3).isGreaterThan(ts2);
    update = newUpdate(c, changeOwner);
    update.setHashtags(ImmutableSet.of("foo"));
    update.commit();
    Instant ts4 = newNotes(c).getChange().getLastUpdatedOn();
    assertThat(ts4).isGreaterThan(ts3);
    incrementPatchSet(c);
    Instant ts5 = newNotes(c).getChange().getLastUpdatedOn();
    assertThat(ts5).isGreaterThan(ts4);
    update = newUpdate(c, changeOwner);
    update.putApproval(LabelId.CODE_REVIEW, (short) 1);
    update.commit();
    Instant ts6 = newNotes(c).getChange().getLastUpdatedOn();
    assertThat(ts6).isGreaterThan(ts5);
    update = newUpdate(c, changeOwner);
    update.setStatus(Change.Status.ABANDONED);
    update.commit();
    Instant ts7 = newNotes(c).getChange().getLastUpdatedOn();
    assertThat(ts7).isGreaterThan(ts6);
    update = newUpdate(c, changeOwner);
    update.putReviewer(otherUser.getAccountId(), ReviewerStateInternal.REVIEWER);
    update.commit();
    Instant ts8 = newNotes(c).getChange().getLastUpdatedOn();
    assertThat(ts8).isGreaterThan(ts7);
    update = newUpdate(c, changeOwner);
    update.setGroups(ImmutableList.of("a", "b"));
    update.commit();
    Instant ts9 = newNotes(c).getChange().getLastUpdatedOn();
    assertThat(ts9).isGreaterThan(ts8);
    // Finish off by merging the change.
    update = newUpdate(c, changeOwner);
    update.merge(new SubmissionId(c), ImmutableList.of(submitRecord("NOT_READY", null, submitLabel(LabelId.VERIFIED, "OK", changeOwner.getAccountId()), submitLabel("Alternative-Code-Review", "NEED", null))));
    update.commit();
    Instant ts10 = newNotes(c).getChange().getLastUpdatedOn();
    assertThat(ts10).isGreaterThan(ts9);
}
Also used : Instant(java.time.Instant) SubmissionId(com.google.gerrit.entities.SubmissionId) Change(com.google.gerrit.entities.Change) Test(org.junit.Test)

Example 2 with SubmissionId

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

the class ChangeNotesTest method approvalsPostSubmit.

@Test
public void approvalsPostSubmit() throws Exception {
    Change c = newChange();
    SubmissionId submissionId = new SubmissionId(c);
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.putApproval(LabelId.CODE_REVIEW, (short) 1);
    update.putApproval(LabelId.VERIFIED, (short) 1);
    update.commit();
    update = newUpdate(c, changeOwner);
    update.merge(submissionId, ImmutableList.of(submitRecord("NOT_READY", null, submitLabel(LabelId.VERIFIED, "OK", changeOwner.getAccountId()), submitLabel(LabelId.CODE_REVIEW, "NEED", null))));
    update.commit();
    update = newUpdate(c, changeOwner);
    update.putApproval(LabelId.CODE_REVIEW, (short) 2);
    update.commit();
    ChangeNotes notes = newNotes(c);
    List<PatchSetApproval> approvals = Lists.newArrayList(notes.getApprovals().values());
    assertThat(approvals).hasSize(2);
    assertThat(approvals.get(0).label()).isEqualTo(LabelId.VERIFIED);
    assertThat(approvals.get(0).value()).isEqualTo((short) 1);
    assertThat(approvals.get(0).postSubmit()).isFalse();
    assertParsedUuid(approvals.get(1));
    assertThat(approvals.get(1).label()).isEqualTo(LabelId.CODE_REVIEW);
    assertThat(approvals.get(1).value()).isEqualTo((short) 2);
    assertThat(approvals.get(1).postSubmit()).isTrue();
    assertParsedUuid(approvals.get(1));
}
Also used : SubmissionId(com.google.gerrit.entities.SubmissionId) Change(com.google.gerrit.entities.Change) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Test(org.junit.Test)

Example 3 with SubmissionId

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

the class ChangeNotesTest method submitRecords.

@Test
public void submitRecords() throws Exception {
    Change c = newChange();
    SubmissionId submissionId = new SubmissionId(c);
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.setSubjectForCommit("Submit patch set 1");
    update.merge(submissionId, ImmutableList.of(submitRecord("NOT_READY", null, submitLabel(LabelId.VERIFIED, "OK", changeOwner.getAccountId()), submitLabel(LabelId.CODE_REVIEW, "NEED", null)), submitRecord("NOT_READY", null, submitLabel(LabelId.VERIFIED, "OK", changeOwner.getAccountId()), submitLabel("Alternative-Code-Review", "NEED", null))));
    update.commit();
    ChangeNotes notes = newNotes(c);
    List<SubmitRecord> recs = notes.getSubmitRecords();
    assertThat(recs).hasSize(2);
    assertThat(recs.get(0)).isEqualTo(submitRecord("NOT_READY", null, submitLabel(LabelId.VERIFIED, "OK", changeOwner.getAccountId()), submitLabel(LabelId.CODE_REVIEW, "NEED", null)));
    assertThat(recs.get(1)).isEqualTo(submitRecord("NOT_READY", null, submitLabel(LabelId.VERIFIED, "OK", changeOwner.getAccountId()), submitLabel("Alternative-Code-Review", "NEED", null)));
    assertThat(notes.getChange().getSubmissionId()).isEqualTo(submissionId.toString());
}
Also used : SubmitRecord(com.google.gerrit.entities.SubmitRecord) SubmissionId(com.google.gerrit.entities.SubmissionId) Change(com.google.gerrit.entities.Change) Test(org.junit.Test)

Example 4 with SubmissionId

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

the class ChangeUpdate method applyImpl.

@Override
protected CommitBuilder applyImpl(RevWalk rw, ObjectInserter ins, ObjectId curr) throws IOException {
    checkState(deleteCommentRewriter == null && deleteChangeMessageRewriter == null, "cannot update and rewrite ref in one BatchUpdate");
    PatchSet.Id patchSetId = psId != null ? psId : getChange().currentPatchSetId();
    StringBuilder msg = new StringBuilder();
    if (commitSubject != null) {
        msg.append(commitSubject);
    } else {
        msg.append("Update patch set ").append(patchSetId.get());
    }
    msg.append("\n\n");
    if (changeMessage != null) {
        msg.append(changeMessage);
        msg.append("\n\n");
    }
    addPatchSetFooter(msg, patchSetId);
    if (currentPatchSet) {
        addFooter(msg, FOOTER_CURRENT, Boolean.TRUE);
    }
    if (psDescription != null) {
        addFooter(msg, FOOTER_PATCH_SET_DESCRIPTION, psDescription);
    }
    if (changeId != null) {
        addFooter(msg, FOOTER_CHANGE_ID, changeId);
    }
    if (subject != null) {
        addFooter(msg, FOOTER_SUBJECT, subject);
    }
    if (branch != null) {
        addFooter(msg, FOOTER_BRANCH, branch);
    }
    if (status != null) {
        addFooter(msg, FOOTER_STATUS, status.name().toLowerCase());
        if (status.equals(Change.Status.ABANDONED)) {
            clearAttentionSet("Change was abandoned");
        }
        if (status.equals(Change.Status.MERGED)) {
            clearAttentionSet("Change was submitted");
        }
    }
    if (topic != null) {
        addFooter(msg, FOOTER_TOPIC, topic);
    }
    if (commit != null) {
        addFooter(msg, FOOTER_COMMIT, commit);
    }
    if (assignee != null) {
        if (assignee.isPresent()) {
            addFooter(msg, FOOTER_ASSIGNEE);
            noteUtil.appendAccountIdIdentString(msg, assignee.get()).append('\n');
        } else {
            addFooter(msg, FOOTER_ASSIGNEE).append('\n');
        }
    }
    Joiner comma = Joiner.on(',');
    if (hashtags != null) {
        addFooter(msg, FOOTER_HASHTAGS, comma.join(hashtags));
    }
    if (tag != null) {
        addFooter(msg, FOOTER_TAG, tag);
    }
    if (groups != null) {
        addFooter(msg, FOOTER_GROUPS, comma.join(groups));
    }
    for (Map.Entry<Account.Id, ReviewerStateInternal> e : reviewers.entrySet()) {
        addFooter(msg, e.getValue().getFooterKey());
        noteUtil.appendAccountIdIdentString(msg, e.getKey()).append('\n');
    }
    applyReviewerUpdatesToAttentionSet();
    for (Map.Entry<Address, ReviewerStateInternal> e : reviewersByEmail.entrySet()) {
        addFooter(msg, e.getValue().getByEmailFooterKey(), e.getKey().toString());
    }
    for (Table.Cell<String, Account.Id, Optional<Short>> c : approvals.cellSet()) {
        addLabelFooter(msg, c, patchSetId);
    }
    for (PatchSetApproval patchSetApproval : copiedApprovals) {
        addCopiedLabelFooter(msg, patchSetApproval);
    }
    if (submissionId != null) {
        addFooter(msg, FOOTER_SUBMISSION_ID, submissionId);
    }
    if (submitRecords != null) {
        for (SubmitRecord rec : submitRecords) {
            addFooter(msg, FOOTER_SUBMITTED_WITH).append(rec.status);
            if (rec.errorMessage != null) {
                msg.append(' ').append(sanitizeFooter(rec.errorMessage));
            }
            msg.append('\n');
            if (rec.ruleName != null) {
                addFooter(msg, FOOTER_SUBMITTED_WITH).append("Rule-Name: ").append(rec.ruleName);
                msg.append('\n');
            }
            if (rec.labels != null) {
                for (SubmitRecord.Label label : rec.labels) {
                    // Label names/values are safe to append without sanitizing.
                    addFooter(msg, FOOTER_SUBMITTED_WITH).append(label.status).append(": ").append(label.label);
                    if (label.appliedBy != null) {
                        msg.append(": ");
                        noteUtil.appendAccountIdIdentString(msg, label.appliedBy);
                    }
                    msg.append('\n');
                }
            }
        }
    }
    if (!Objects.equals(accountId, realAccountId)) {
        addFooter(msg, FOOTER_REAL_USER);
        noteUtil.appendAccountIdIdentString(msg, realAccountId).append('\n');
    }
    if (isPrivate != null) {
        addFooter(msg, FOOTER_PRIVATE, isPrivate);
    }
    if (workInProgress != null) {
        addFooter(msg, FOOTER_WORK_IN_PROGRESS, workInProgress);
        if (workInProgress) {
            clearAttentionSet("Change was marked work in progress");
        } else {
            addAllReviewersToAttentionSet();
        }
    }
    if (revertOf != null) {
        addFooter(msg, FOOTER_REVERT_OF, revertOf);
    }
    if (cherryPickOf != null) {
        if (cherryPickOf.isPresent()) {
            addFooter(msg, FOOTER_CHERRY_PICK_OF, cherryPickOf.get());
        } else {
            // Update cherryPickOf with an empty value.
            addFooter(msg, FOOTER_CHERRY_PICK_OF).append('\n');
        }
    }
    updateAttentionSet(msg);
    CommitBuilder cb = new CommitBuilder();
    cb.setMessage(msg.toString());
    try {
        ObjectId treeId = storeRevisionNotes(rw, ins, curr);
        if (treeId != null) {
            cb.setTreeId(treeId);
        }
    } catch (ConfigInvalidException e) {
        throw new StorageException(e);
    }
    return cb;
}
Also used : Joiner(com.google.common.base.Joiner) TreeBasedTable(com.google.common.collect.TreeBasedTable) Table(com.google.common.collect.Table) Address(com.google.gerrit.entities.Address) Optional(java.util.Optional) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) ObjectId(org.eclipse.jgit.lib.ObjectId) CommitBuilder(org.eclipse.jgit.lib.CommitBuilder) PatchSet(com.google.gerrit.entities.PatchSet) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) SubmitRecord(com.google.gerrit.entities.SubmitRecord) SubmissionId(com.google.gerrit.entities.SubmissionId) LabelId(com.google.gerrit.entities.LabelId) ObjectId(org.eclipse.jgit.lib.ObjectId) Map(java.util.Map) NoteMap(org.eclipse.jgit.notes.NoteMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) StorageException(com.google.gerrit.exceptions.StorageException)

Example 5 with SubmissionId

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

the class ReplaceOp method updateRepo.

@Override
public void updateRepo(RepoContext ctx) throws Exception {
    commit = ctx.getRevWalk().parseCommit(commitId);
    ctx.getRevWalk().parseBody(commit);
    changeKind = changeKindCache.getChangeKind(projectState.getNameKey(), ctx.getRevWalk(), ctx.getRepoView().getConfig(), priorCommitId, commitId);
    if (checkMergedInto) {
        String mergedInto = findMergedInto(ctx, dest.branch(), commit);
        if (mergedInto != null) {
            mergedByPushOp = mergedByPushOpFactory.create(requestScopePropagator, patchSetId, new SubmissionId(change), mergedInto, mergeResultRevId);
        }
    }
    cmd = new ReceiveCommand(ObjectId.zeroId(), commitId, patchSetId.toRefName());
    ctx.addRefUpdate(cmd);
}
Also used : ReceiveCommand(org.eclipse.jgit.transport.ReceiveCommand) SubmissionId(com.google.gerrit.entities.SubmissionId)

Aggregations

SubmissionId (com.google.gerrit.entities.SubmissionId)18 Change (com.google.gerrit.entities.Change)13 Test (org.junit.Test)12 ObjectId (org.eclipse.jgit.lib.ObjectId)5 PatchSetApproval (com.google.gerrit.entities.PatchSetApproval)4 Instant (java.time.Instant)4 Joiner (com.google.common.base.Joiner)3 SubmitRecord (com.google.gerrit.entities.SubmitRecord)3 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)3 BatchUpdateOp (com.google.gerrit.server.update.BatchUpdateOp)3 ChangeContext (com.google.gerrit.server.update.ChangeContext)3 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)2 ListMultimap (com.google.common.collect.ListMultimap)2 MultimapBuilder (com.google.common.collect.MultimapBuilder)2 Account (com.google.gerrit.entities.Account)2 LabelTypes (com.google.gerrit.entities.LabelTypes)2