Search in sources :

Example 31 with PatchSetApproval

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

the class PatchSetApprovalProtoConverterTest method mandatoryValuesConvertedToProto.

@Test
public void mandatoryValuesConvertedToProto() {
    PatchSetApproval patchSetApproval = PatchSetApproval.builder().key(PatchSetApproval.key(PatchSet.id(Change.id(42), 14), Account.id(100013), LabelId.create("label-8"))).value(456).granted(Instant.ofEpochMilli(987654L)).build();
    Entities.PatchSetApproval proto = protoConverter.toProto(patchSetApproval);
    Entities.PatchSetApproval expectedProto = Entities.PatchSetApproval.newBuilder().setKey(Entities.PatchSetApproval_Key.newBuilder().setPatchSetId(Entities.PatchSet_Id.newBuilder().setChangeId(Entities.Change_Id.newBuilder().setId(42)).setId(14)).setAccountId(Entities.Account_Id.newBuilder().setId(100013)).setLabelId(Entities.LabelId.newBuilder().setId("label-8"))).setValue(456).setGranted(987654L).setPostSubmit(false).setCopied(false).build();
    assertThat(proto).isEqualTo(expectedProto);
}
Also used : PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Entities(com.google.gerrit.proto.Entities) Test(org.junit.Test)

Example 32 with PatchSetApproval

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

the class SubmitStrategyOp method saveApprovals.

private void saveApprovals(LabelNormalizer.Result normalized, ChangeUpdate update, boolean includeUnchanged) {
    for (PatchSetApproval psa : normalized.updated()) {
        update.putApprovalFor(psa.accountId(), psa.label(), psa.value());
    }
    for (PatchSetApproval psa : normalized.deleted()) {
        update.removeApprovalFor(psa.accountId(), psa.label());
    }
    // change happened.
    for (PatchSetApproval psa : normalized.unchanged()) {
        if (includeUnchanged || psa.isLegacySubmit()) {
            logger.atFine().log("Adding submit label %s", psa);
            update.putApprovalFor(psa.accountId(), psa.label(), psa.value());
        }
    }
}
Also used : PatchSetApproval(com.google.gerrit.entities.PatchSetApproval)

Example 33 with PatchSetApproval

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

the class SubmitStrategyOp method approve.

private LabelNormalizer.Result approve(ChangeContext ctx, ChangeUpdate update) {
    PatchSet.Id psId = update.getPatchSetId();
    Map<PatchSetApproval.Key, PatchSetApproval> byKey = new HashMap<>();
    for (PatchSetApproval psa : args.approvalsUtil.byPatchSet(ctx.getNotes(), psId)) {
        byKey.put(psa.key(), psa);
    }
    submitter = ApprovalsUtil.newApproval(psId, ctx.getUser(), LabelId.legacySubmit(), 1, ctx.getWhen()).build();
    byKey.put(submitter.key(), submitter);
    // Flatten out existing approvals for this patch set based upon the current
    // permissions. Once the change is closed the approvals are not updated at
    // presentation view time, except for zero votes used to indicate a reviewer
    // was added. So we need to make sure votes are accurate now. This way if
    // permissions get modified in the future, historical records stay accurate.
    LabelNormalizer.Result normalized = args.labelNormalizer.normalize(ctx.getNotes(), byKey.values());
    update.putApproval(submitter.label(), submitter.value());
    saveApprovals(normalized, update, false);
    return normalized;
}
Also used : LabelNormalizer(com.google.gerrit.server.change.LabelNormalizer) HashMap(java.util.HashMap) PatchSet(com.google.gerrit.entities.PatchSet) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) BranchNameKey(com.google.gerrit.entities.BranchNameKey)

Example 34 with PatchSetApproval

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

the class MergeUtil method createDetailedCommitMessage.

/**
 * Adds footers to existing commit message based on the state of the change.
 *
 * <p>This adds the following footers if they are missing:
 *
 * <ul>
 *   <li>Reviewed-on: <i>url</i>
 *   <li>Reviewed-by | Tested-by | <i>Other-Label-Name</i>: <i>reviewer</i>
 *   <li>Change-Id
 * </ul>
 *
 * @return new message
 */
private String createDetailedCommitMessage(RevCommit n, ChangeNotes notes, PatchSet.Id psId) {
    Change c = notes.getChange();
    final List<FooterLine> footers = n.getFooterLines();
    final StringBuilder msgbuf = new StringBuilder();
    msgbuf.append(n.getFullMessage());
    if (msgbuf.length() == 0) {
        // WTF, an empty commit message?
        msgbuf.append("<no commit message provided>");
    }
    if (msgbuf.charAt(msgbuf.length() - 1) != '\n') {
        // Missing a trailing LF? Correct it (perhaps the editor was broken).
        msgbuf.append('\n');
    }
    if (footers.isEmpty()) {
        // Doesn't end in a "Signed-off-by: ..." style line? Add another line
        // break to start a new paragraph for the reviewed-by tag lines.
        // 
        msgbuf.append('\n');
    }
    if (ChangeUtil.getChangeIdsFromFooter(n, urlFormatter.get()).isEmpty()) {
        msgbuf.append(FooterConstants.CHANGE_ID.getName());
        msgbuf.append(": ");
        msgbuf.append(c.getKey().get());
        msgbuf.append('\n');
    }
    Optional<String> url = urlFormatter.get().getChangeViewUrl(c.getProject(), c.getId());
    if (url.isPresent()) {
        if (!contains(footers, FooterConstants.REVIEWED_ON, url.get())) {
            msgbuf.append(FooterConstants.REVIEWED_ON.getName()).append(": ").append(url.get()).append('\n');
        }
    }
    PatchSetApproval submitAudit = null;
    for (PatchSetApproval a : safeGetApprovals(notes, psId)) {
        if (a.value() <= 0) {
            // Negative votes aren't counted.
            continue;
        }
        if (a.isLegacySubmit()) {
            // 
            if (submitAudit == null || a.granted().compareTo(submitAudit.granted()) > 0) {
                submitAudit = a;
            }
            continue;
        }
        final Account acc = identifiedUserFactory.create(a.accountId()).getAccount();
        final StringBuilder identbuf = new StringBuilder();
        if (acc.fullName() != null && acc.fullName().length() > 0) {
            if (identbuf.length() > 0) {
                identbuf.append(' ');
            }
            identbuf.append(acc.fullName());
        }
        if (acc.preferredEmail() != null && acc.preferredEmail().length() > 0) {
            if (isSignedOffBy(footers, acc.preferredEmail())) {
                continue;
            }
            if (identbuf.length() > 0) {
                identbuf.append(' ');
            }
            identbuf.append('<');
            identbuf.append(acc.preferredEmail());
            identbuf.append('>');
        }
        if (identbuf.length() == 0) {
            // Nothing reasonable to describe them by? Ignore them.
            continue;
        }
        final String tag;
        if (isCodeReview(a.labelId())) {
            tag = "Reviewed-by";
        } else if (isVerified(a.labelId())) {
            tag = "Tested-by";
        } else {
            final Optional<LabelType> lt = project.getLabelTypes().byLabel(a.labelId());
            if (!lt.isPresent()) {
                continue;
            }
            tag = lt.get().getName();
        }
        if (!contains(footers, new FooterKey(tag), identbuf.toString())) {
            msgbuf.append(tag);
            msgbuf.append(": ");
            msgbuf.append(identbuf);
            msgbuf.append('\n');
        }
    }
    return msgbuf.toString();
}
Also used : Account(com.google.gerrit.entities.Account) Optional(java.util.Optional) FooterLine(org.eclipse.jgit.revwalk.FooterLine) FooterKey(org.eclipse.jgit.revwalk.FooterKey) Change(com.google.gerrit.entities.Change) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval)

Example 35 with PatchSetApproval

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

the class ChangeNotesParser method parseAddApproval.

/**
 * Parses {@link PatchSetApproval} out of the {@link ChangeNoteUtil#FOOTER_LABEL} value.
 */
private PatchSetApproval.Builder parseAddApproval(PatchSet.Id psId, Account.Id committerId, Account.Id realAccountId, Instant ts, ParsedPatchSetApproval parsedPatchSetApproval) throws ConfigInvalidException {
    Account.Id approverId = parseApprover(committerId, parsedPatchSetApproval);
    LabelVote l;
    try {
        l = LabelVote.parseWithEquals(parsedPatchSetApproval.labelVote());
    } catch (IllegalArgumentException e) {
        ConfigInvalidException pe = parseException("invalid %s: %s", FOOTER_LABEL, parsedPatchSetApproval.footerLine());
        pe.initCause(e);
        throw pe;
    }
    PatchSetApproval.Builder psa = PatchSetApproval.builder().key(PatchSetApproval.key(psId, approverId, LabelId.create(l.label()))).uuid(parsedPatchSetApproval.uuid().map(PatchSetApproval::uuid)).value(l.value()).granted(ts).tag(Optional.ofNullable(tag));
    if (!Objects.equals(realAccountId, committerId)) {
        psa.realAccountId(realAccountId);
    }
    approvals.putIfAbsent(psa.key(), psa);
    return psa;
}
Also used : Account(com.google.gerrit.entities.Account) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) LabelVote(com.google.gerrit.server.util.LabelVote) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) ParsedPatchSetApproval(com.google.gerrit.server.notedb.ChangeNoteUtil.ParsedPatchSetApproval)

Aggregations

PatchSetApproval (com.google.gerrit.entities.PatchSetApproval)93 Test (org.junit.Test)57 Change (com.google.gerrit.entities.Change)41 LabelType (com.google.gerrit.entities.LabelType)22 Account (com.google.gerrit.entities.Account)20 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)14 Map (java.util.Map)14 ObjectId (org.eclipse.jgit.lib.ObjectId)14 LabelId (com.google.gerrit.entities.LabelId)13 PatchSet (com.google.gerrit.entities.PatchSet)12 SubmitRecord (com.google.gerrit.entities.SubmitRecord)12 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)11 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)10 SubmissionId (com.google.gerrit.entities.SubmissionId)9 ChangeData (com.google.gerrit.server.query.change.ChangeData)9 Inject (com.google.inject.Inject)9 Instant (java.time.Instant)9 HashMap (java.util.HashMap)9 List (java.util.List)9 ChangeMessage (com.google.gerrit.entities.ChangeMessage)8