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;
}
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);
}
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;
}
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());
}
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;
}
Aggregations