Search in sources :

Example 1 with LabelVote

use of com.google.gerrit.server.util.LabelVote in project gerrit by GerritCodeReview.

the class LabelPredicate method predicates.

protected static List<Predicate<ChangeData>> predicates(Args args) {
    String v = args.value;
    List<Integer> counts = getCounts(args.count, args.countOp);
    try {
        MagicLabelVote mlv = MagicLabelVote.parseWithEquals(v);
        List<Predicate<ChangeData>> result = Lists.newArrayListWithCapacity(counts.size());
        if (counts.isEmpty()) {
            result.add(magicLabelPredicate(args, mlv, /* count= */
            null));
        } else {
            counts.forEach(count -> result.add(magicLabelPredicate(args, mlv, count)));
        }
        return result;
    } catch (IllegalArgumentException e) {
    // Try next format.
    }
    Parsed parsed = null;
    try {
        LabelVote lv = LabelVote.parse(v);
        parsed = new Parsed(lv.label(), "=", lv.value());
    } catch (IllegalArgumentException e) {
    // Try next format.
    }
    try {
        LabelVote lv = LabelVote.parseWithEquals(v);
        parsed = new Parsed(lv.label(), "=", lv.value());
    } catch (IllegalArgumentException e) {
    // Try next format.
    }
    Range range;
    if (parsed == null) {
        range = RangeUtil.getRange(v, -MAX_LABEL_VALUE, MAX_LABEL_VALUE);
        if (range == null) {
            range = new Range(v, 1, 1);
        }
    } else {
        range = RangeUtil.getRange(parsed.label, parsed.test, parsed.numericValue, -MAX_LABEL_VALUE, MAX_LABEL_VALUE);
    }
    String prefix = range.prefix;
    int min = range.min;
    int max = range.max;
    List<Predicate<ChangeData>> r = Lists.newArrayListWithCapacity((counts.isEmpty() ? 1 : counts.size()) * (max - min + 1));
    for (int i = min; i <= max; i++) {
        if (counts.isEmpty()) {
            r.add(onePredicate(args, prefix, i, /* count= */
            null));
        } else {
            for (int count : counts) {
                r.add(onePredicate(args, prefix, i, count));
            }
        }
    }
    return r;
}
Also used : LabelVote(com.google.gerrit.server.util.LabelVote) Range(com.google.gerrit.index.query.RangeUtil.Range) Predicate(com.google.gerrit.index.query.Predicate) OrPredicate(com.google.gerrit.index.query.OrPredicate)

Example 2 with LabelVote

use of com.google.gerrit.server.util.LabelVote in project gerrit by GerritCodeReview.

the class ChangeNotesParser method parseCopiedApproval.

/**
 * Parses copied {@link PatchSetApproval}.
 */
private void parseCopiedApproval(PatchSet.Id psId, Instant ts, String line) throws ConfigInvalidException {
    ParsedPatchSetApproval parsedPatchSetApproval = ChangeNoteUtil.parseCopiedApproval(line);
    checkFooter(parsedPatchSetApproval.accountIdent().isPresent(), FOOTER_COPIED_LABEL, parsedPatchSetApproval.footerLine());
    PersonIdent accountIdent = RawParseUtils.parsePersonIdent(parsedPatchSetApproval.accountIdent().get());
    checkFooter(accountIdent != null, FOOTER_COPIED_LABEL, parsedPatchSetApproval.footerLine());
    Account.Id accountId = parseIdent(accountIdent);
    Account.Id realAccountId = null;
    if (parsedPatchSetApproval.realAccountIdent().isPresent()) {
        PersonIdent realIdent = RawParseUtils.parsePersonIdent(parsedPatchSetApproval.realAccountIdent().get());
        checkFooter(realIdent != null, FOOTER_COPIED_LABEL, parsedPatchSetApproval.footerLine());
        realAccountId = parseIdent(realIdent);
    }
    LabelVote l;
    try {
        l = LabelVote.parseWithEquals(parsedPatchSetApproval.labelVote());
    } catch (IllegalArgumentException e) {
        ConfigInvalidException pe = parseException("invalid %s: %s", FOOTER_COPIED_LABEL, parsedPatchSetApproval.footerLine());
        pe.initCause(e);
        throw pe;
    }
    PatchSetApproval.Builder psa = PatchSetApproval.builder().key(PatchSetApproval.key(psId, accountId, LabelId.create(l.label()))).uuid(parsedPatchSetApproval.uuid().map(PatchSetApproval::uuid)).value(l.value()).granted(ts).tag(parsedPatchSetApproval.tag()).copied(true);
    if (realAccountId != null) {
        psa.realAccountId(realAccountId);
    }
    approvals.putIfAbsent(psa.key(), psa);
    bufferedApprovals.add(psa);
}
Also used : Account(com.google.gerrit.entities.Account) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) PersonIdent(org.eclipse.jgit.lib.PersonIdent) LabelVote(com.google.gerrit.server.util.LabelVote) ParsedPatchSetApproval(com.google.gerrit.server.notedb.ChangeNoteUtil.ParsedPatchSetApproval) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) ParsedPatchSetApproval(com.google.gerrit.server.notedb.ChangeNoteUtil.ParsedPatchSetApproval)

Example 3 with LabelVote

use of com.google.gerrit.server.util.LabelVote 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)

Example 4 with LabelVote

use of com.google.gerrit.server.util.LabelVote in project gerrit by GerritCodeReview.

the class ReviewCommand method addLabel.

@Option(name = "--label", aliases = "-l", usage = "custom label(s) to assign", metaVar = "LABEL=VALUE")
void addLabel(String token) {
    LabelVote v = LabelVote.parseWithEquals(token);
    // Disallow SUBM.
    LabelType.checkName(v.label());
    customLabels.put(v.label(), v.value());
}
Also used : LabelVote(com.google.gerrit.server.util.LabelVote) Option(org.kohsuke.args4j.Option)

Example 5 with LabelVote

use of com.google.gerrit.server.util.LabelVote in project gerrit by GerritCodeReview.

the class ChangeNotesParser method parseAddApproval.

private PatchSetApproval parseAddApproval(PatchSet.Id psId, Account.Id committerId, Account.Id realAccountId, Timestamp ts, String line) throws ConfigInvalidException {
    // There are potentially 3 accounts involved here:
    //  1. The account from the commit, which is the effective IdentifiedUser
    //     that produced the update.
    //  2. The account in the label footer itself, which is used during submit
    //     to copy other users' labels to a new patch set.
    //  3. The account in the Real-user footer, indicating that the whole
    //     update operation was executed by this user on behalf of the effective
    //     user.
    Account.Id effectiveAccountId;
    String labelVoteStr;
    int s = line.indexOf(' ');
    if (s > 0) {
        // Account in the label line (2) becomes the effective ID of the
        // approval. If there is a real user (3) different from the commit user
        // (2), we actually don't store that anywhere in this case; it's more
        // important to record that the real user (3) actually initiated submit.
        labelVoteStr = line.substring(0, s);
        PersonIdent ident = RawParseUtils.parsePersonIdent(line.substring(s + 1));
        checkFooter(ident != null, FOOTER_LABEL, line);
        effectiveAccountId = noteUtil.parseIdent(ident, id);
    } else {
        labelVoteStr = line;
        effectiveAccountId = committerId;
    }
    LabelVote l;
    try {
        l = LabelVote.parseWithEquals(labelVoteStr);
    } catch (IllegalArgumentException e) {
        ConfigInvalidException pe = parseException("invalid %s: %s", FOOTER_LABEL, line);
        pe.initCause(e);
        throw pe;
    }
    PatchSetApproval psa = new PatchSetApproval(new PatchSetApproval.Key(psId, effectiveAccountId, new LabelId(l.label())), l.value(), ts);
    psa.setTag(tag);
    if (!Objects.equals(realAccountId, committerId)) {
        psa.setRealAccountId(realAccountId);
    }
    ApprovalKey k = ApprovalKey.create(psId, effectiveAccountId, l.label());
    if (!approvals.containsKey(k)) {
        approvals.put(k, psa);
    }
    return psa;
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) PersonIdent(org.eclipse.jgit.lib.PersonIdent) LabelVote(com.google.gerrit.server.util.LabelVote) LabelId(com.google.gerrit.reviewdb.client.LabelId) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval)

Aggregations

LabelVote (com.google.gerrit.server.util.LabelVote)6 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)3 Account (com.google.gerrit.entities.Account)2 PatchSetApproval (com.google.gerrit.entities.PatchSetApproval)2 ParsedPatchSetApproval (com.google.gerrit.server.notedb.ChangeNoteUtil.ParsedPatchSetApproval)2 PersonIdent (org.eclipse.jgit.lib.PersonIdent)2 OrPredicate (com.google.gerrit.index.query.OrPredicate)1 Predicate (com.google.gerrit.index.query.Predicate)1 Range (com.google.gerrit.index.query.RangeUtil.Range)1 Account (com.google.gerrit.reviewdb.client.Account)1 LabelId (com.google.gerrit.reviewdb.client.LabelId)1 PatchSetApproval (com.google.gerrit.reviewdb.client.PatchSetApproval)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Option (org.kohsuke.args4j.Option)1