use of com.google.gerrit.common.data.LabelType in project gerrit by GerritCodeReview.
the class ImpersonationIT method allowSubmitOnBehalfOf.
private void allowSubmitOnBehalfOf() throws Exception {
ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
String heads = "refs/heads/*";
AccountGroup.UUID uuid = systemGroupBackend.getGroup(REGISTERED_USERS).getUUID();
Util.allow(cfg, Permission.SUBMIT_AS, uuid, heads);
Util.allow(cfg, Permission.SUBMIT, uuid, heads);
LabelType codeReviewType = Util.codeReview();
Util.allow(cfg, Permission.forLabel(codeReviewType.getName()), -2, 2, uuid, heads);
saveProjectConfig(project, cfg);
}
use of com.google.gerrit.common.data.LabelType in project gerrit by GerritCodeReview.
the class ChangeInserter method postUpdate.
@Override
public void postUpdate(Context ctx) throws OrmException {
if (sendMail && (notify != NotifyHandling.NONE || !accountsToNotify.isEmpty())) {
Runnable sender = new Runnable() {
@Override
public void run() {
try {
CreateChangeSender cm = createChangeSenderFactory.create(change.getProject(), change.getId());
cm.setFrom(change.getOwner());
cm.setPatchSet(patchSet, patchSetInfo);
cm.setNotify(notify);
cm.setAccountsToNotify(accountsToNotify);
cm.addReviewers(reviewers);
cm.addExtraCC(extraCC);
cm.send();
} catch (Exception e) {
log.error("Cannot send email for new change " + change.getId(), e);
}
}
@Override
public String toString() {
return "send-email newchange";
}
};
if (requestScopePropagator != null) {
@SuppressWarnings("unused") Future<?> possiblyIgnoredError = sendEmailExecutor.submit(requestScopePropagator.wrap(sender));
} else {
sender.run();
}
}
/* For labels that are not set in this operation, show the "current" value
* of 0, and no oldValue as the value was not modified by this operation.
* For labels that are set in this operation, the value was modified, so
* show a transition from an oldValue of 0 to the new value.
*/
if (fireRevisionCreated) {
revisionCreated.fire(change, patchSet, ctx.getAccount(), ctx.getWhen(), notify);
if (approvals != null && !approvals.isEmpty()) {
ChangeControl changeControl = changeControlFactory.controlFor(ctx.getDb(), change, ctx.getUser());
List<LabelType> labels = changeControl.getLabelTypes().getLabelTypes();
Map<String, Short> allApprovals = new HashMap<>();
Map<String, Short> oldApprovals = new HashMap<>();
for (LabelType lt : labels) {
allApprovals.put(lt.getName(), (short) 0);
oldApprovals.put(lt.getName(), null);
}
for (Map.Entry<String, Short> entry : approvals.entrySet()) {
if (entry.getValue() != 0) {
allApprovals.put(entry.getKey(), entry.getValue());
oldApprovals.put(entry.getKey(), (short) 0);
}
}
commentAdded.fire(change, patchSet, ctx.getAccount(), null, allApprovals, oldApprovals, ctx.getWhen());
}
}
}
use of com.google.gerrit.common.data.LabelType in project gerrit by GerritCodeReview.
the class ReviewerRecommender method baseRankingForCandidateList.
private Map<Account.Id, MutableDouble> baseRankingForCandidateList(List<Account.Id> candidates, ProjectControl projectControl, double baseWeight) throws OrmException {
// Get each reviewer's activity based on number of applied labels
// (weighted 10d), number of comments (weighted 0.5d) and number of owned
// changes (weighted 1d).
Map<Account.Id, MutableDouble> reviewers = new LinkedHashMap<>();
if (candidates.size() == 0) {
return reviewers;
}
List<Predicate<ChangeData>> predicates = new ArrayList<>();
for (Account.Id id : candidates) {
try {
Predicate<ChangeData> projectQuery = changeQueryBuilder.project(projectControl.getProject().getName());
// Get all labels for this project and create a compound OR query to
// fetch all changes where users have applied one of these labels
List<LabelType> labelTypes = projectControl.getLabelTypes().getLabelTypes();
List<Predicate<ChangeData>> labelPredicates = new ArrayList<>(labelTypes.size());
for (LabelType type : labelTypes) {
labelPredicates.add(changeQueryBuilder.label(type.getName() + ",user=" + id));
}
Predicate<ChangeData> reviewerQuery = Predicate.and(projectQuery, Predicate.or(labelPredicates));
Predicate<ChangeData> ownerQuery = Predicate.and(projectQuery, changeQueryBuilder.owner(id.toString()));
Predicate<ChangeData> commentedByQuery = Predicate.and(projectQuery, changeQueryBuilder.commentby(id.toString()));
predicates.add(reviewerQuery);
predicates.add(ownerQuery);
predicates.add(commentedByQuery);
reviewers.put(id, new MutableDouble());
} catch (QueryParseException e) {
// Unhandled: If an exception is thrown, we won't increase the
// candidates's score
log.error("Exception while suggesting reviewers", e);
}
}
List<List<ChangeData>> result = internalChangeQuery.setLimit(25).setRequestedFields(ImmutableSet.of()).query(predicates);
Iterator<List<ChangeData>> queryResultIterator = result.iterator();
Iterator<Account.Id> reviewersIterator = reviewers.keySet().iterator();
int i = 0;
Account.Id currentId = null;
while (queryResultIterator.hasNext()) {
List<ChangeData> currentResult = queryResultIterator.next();
if (i % WEIGHTS.length == 0) {
currentId = reviewersIterator.next();
}
reviewers.get(currentId).add(WEIGHTS[i % WEIGHTS.length] * baseWeight * currentResult.size());
i++;
}
return reviewers;
}
use of com.google.gerrit.common.data.LabelType in project gerrit by GerritCodeReview.
the class ChangeJson method labelsForOpenChange.
private Map<String, LabelWithStatus> labelsForOpenChange(PermissionBackend.ForChange perm, ChangeData cd, LabelTypes labelTypes, boolean standard, boolean detailed) throws OrmException, PermissionBackendException {
Map<String, LabelWithStatus> labels = initLabels(cd, labelTypes, standard);
if (detailed) {
setAllApprovals(perm, cd, labels);
}
for (Map.Entry<String, LabelWithStatus> e : labels.entrySet()) {
LabelType type = labelTypes.byLabel(e.getKey());
if (type == null) {
continue;
}
if (standard) {
for (PatchSetApproval psa : cd.currentApprovals()) {
if (type.matches(psa)) {
short val = psa.getValue();
Account.Id accountId = psa.getAccountId();
setLabelScores(type, e.getValue(), val, accountId);
}
}
}
if (detailed) {
setLabelValues(type, e.getValue());
}
}
return labels;
}
use of com.google.gerrit.common.data.LabelType in project gerrit by GerritCodeReview.
the class Schema_125 method migrateData.
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException {
try (Repository git = repoManager.openRepository(allUsersName);
MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allUsersName, git)) {
ProjectConfig config = ProjectConfig.read(md);
config.getAccessSection(RefNames.REFS_USERS + "*", true).remove(new Permission(Permission.READ));
GroupReference registered = systemGroupBackend.getGroup(REGISTERED_USERS);
AccessSection users = config.getAccessSection(RefNames.REFS_USERS + "${" + RefPattern.USERID_SHARDED + "}", true);
grant(config, users, Permission.READ, true, registered);
grant(config, users, Permission.PUSH, true, registered);
grant(config, users, Permission.SUBMIT, true, registered);
for (LabelType lt : getLabelTypes(config)) {
if ("Code-Review".equals(lt.getName()) || "Verified".equals(lt.getName())) {
grant(config, users, lt, lt.getMin().getValue(), lt.getMax().getValue(), registered);
}
}
md.getCommitBuilder().setAuthor(serverUser);
md.getCommitBuilder().setCommitter(serverUser);
md.setMessage(COMMIT_MSG);
config.commit(md);
} catch (ConfigInvalidException | IOException ex) {
throw new OrmException(ex);
}
}
Aggregations