use of com.google.gerrit.common.data.LabelType in project gerrit by GerritCodeReview.
the class ProjectConfigTest method readConfigLabelScores.
@Test
public void readConfigLabelScores() throws Exception {
RevCommit rev = util.commit(//
util.tree(//
util.file("groups", util.blob(group(developers))), util.file("project.config", util.blob(//
"" + //
"[label \"CustomLabel\"]\n" + //
LABEL_SCORES_CONFIG))));
ProjectConfig cfg = read(rev);
Map<String, LabelType> labels = cfg.getLabelSections();
LabelType type = labels.entrySet().iterator().next().getValue();
assertThat(type.isCopyMinScore()).isNotEqualTo(LabelType.DEF_COPY_MIN_SCORE);
assertThat(type.isCopyMaxScore()).isNotEqualTo(LabelType.DEF_COPY_MAX_SCORE);
assertThat(type.isCopyAllScoresOnMergeFirstParentUpdate()).isNotEqualTo(LabelType.DEF_COPY_ALL_SCORES_ON_MERGE_FIRST_PARENT_UPDATE);
assertThat(type.isCopyAllScoresOnTrivialRebase()).isNotEqualTo(LabelType.DEF_COPY_ALL_SCORES_ON_TRIVIAL_REBASE);
assertThat(type.isCopyAllScoresIfNoCodeChange()).isNotEqualTo(LabelType.DEF_COPY_ALL_SCORES_IF_NO_CODE_CHANGE);
assertThat(type.isCopyAllScoresIfNoChange()).isNotEqualTo(LabelType.DEF_COPY_ALL_SCORES_IF_NO_CHANGE);
}
use of com.google.gerrit.common.data.LabelType in project gerrit by GerritCodeReview.
the class ReviewCommand method parseCommandLine.
@Override
protected void parseCommandLine() throws UnloggedFailure {
optionList = new ArrayList<>();
customLabels = new HashMap<>();
ProjectControl allProjectsControl;
try {
allProjectsControl = projectControlFactory.controlFor(allProjects);
} catch (NoSuchProjectException e) {
throw die("missing " + allProjects.get());
}
for (LabelType type : allProjectsControl.getLabelTypes().getLabelTypes()) {
StringBuilder usage = new StringBuilder("score for ").append(type.getName()).append("\n");
for (LabelValue v : type.getValues()) {
usage.append(v.format()).append("\n");
}
final String name = "--" + type.getName().toLowerCase();
optionList.add(new ApproveOption(name, usage.toString(), type));
}
super.parseCommandLine();
}
use of com.google.gerrit.common.data.LabelType in project gerrit by GerritCodeReview.
the class ApprovalCopier method canCopy.
private static boolean canCopy(ProjectState project, PatchSetApproval psa, PatchSet.Id psId, ChangeKind kind) {
int n = psa.getKey().getParentKey().get();
checkArgument(n != psId.get());
LabelType type = project.getLabelTypes().byLabel(psa.getLabelId());
if (type == null) {
return false;
} else if ((type.isCopyMinScore() && type.isMaxNegative(psa)) || (type.isCopyMaxScore() && type.isMaxPositive(psa))) {
return true;
}
switch(kind) {
case MERGE_FIRST_PARENT_UPDATE:
return type.isCopyAllScoresOnMergeFirstParentUpdate();
case NO_CODE_CHANGE:
return type.isCopyAllScoresIfNoCodeChange();
case TRIVIAL_REBASE:
return type.isCopyAllScoresOnTrivialRebase();
case NO_CHANGE:
return type.isCopyAllScoresIfNoChange() || type.isCopyAllScoresOnTrivialRebase() || type.isCopyAllScoresOnMergeFirstParentUpdate() || type.isCopyAllScoresIfNoCodeChange();
case REWORK:
default:
return false;
}
}
use of com.google.gerrit.common.data.LabelType in project gerrit by GerritCodeReview.
the class ApprovalsUtil method addReviewers.
private List<PatchSetApproval> addReviewers(ReviewDb db, ChangeUpdate update, LabelTypes labelTypes, Change change, PatchSet.Id psId, Account.Id authorId, Account.Id committerId, Iterable<Account.Id> wantReviewers, Collection<Account.Id> existingReviewers) throws OrmException {
List<LabelType> allTypes = labelTypes.getLabelTypes();
if (allTypes.isEmpty()) {
return ImmutableList.of();
}
Set<Account.Id> need = Sets.newLinkedHashSet(wantReviewers);
if (authorId != null && canSee(db, update.getNotes(), authorId)) {
need.add(authorId);
}
if (committerId != null && canSee(db, update.getNotes(), committerId)) {
need.add(committerId);
}
need.remove(change.getOwner());
need.removeAll(existingReviewers);
if (need.isEmpty()) {
return ImmutableList.of();
}
List<PatchSetApproval> cells = Lists.newArrayListWithCapacity(need.size());
LabelId labelId = Iterables.getLast(allTypes).getLabelId();
for (Account.Id account : need) {
cells.add(new PatchSetApproval(new PatchSetApproval.Key(psId, account, labelId), (short) 0, update.getWhen()));
update.putReviewer(account, REVIEWER);
}
db.patchSetApprovals().upsert(cells);
return Collections.unmodifiableList(cells);
}
use of com.google.gerrit.common.data.LabelType in project gerrit by GerritCodeReview.
the class ChangeControl method getLabelTypes.
/** All available label types for this change. */
public LabelTypes getLabelTypes() {
String destBranch = getChange().getDest().get();
List<LabelType> all = getProjectControl().getLabelTypes().getLabelTypes();
List<LabelType> r = Lists.newArrayListWithCapacity(all.size());
for (LabelType l : all) {
List<String> refs = l.getRefPatterns();
if (refs == null) {
r.add(l);
} else {
for (String refPattern : refs) {
if (RefConfigSection.isValid(refPattern) && match(destBranch, refPattern)) {
r.add(l);
break;
}
}
}
}
return new LabelTypes(r);
}
Aggregations