use of com.google.gerrit.server.approval.ApprovalsUtil in project gerrit by GerritCodeReview.
the class PatchSetUtil method isPatchSetLocked.
/**
* Is the current patch set locked against state changes?
*/
public boolean isPatchSetLocked(ChangeNotes notes) {
Change change = notes.getChange();
if (change.isMerged()) {
return false;
}
ProjectState projectState = projectCache.get(notes.getProjectName()).orElseThrow(illegalState(notes.getProjectName()));
ApprovalsUtil approvalsUtil = approvalsUtilProvider.get();
for (PatchSetApproval ap : approvalsUtil.byPatchSet(notes, change.currentPatchSetId())) {
Optional<LabelType> type = projectState.getLabelTypes(notes).byLabel(ap.label());
if (type.isPresent() && ap.value() == 1 && type.get().getFunction() == LabelFunction.PATCH_SET_LOCK) {
return true;
}
}
return false;
}
use of com.google.gerrit.server.approval.ApprovalsUtil in project gerrit by GerritCodeReview.
the class AddReviewersOp method updateChange.
@Override
public boolean updateChange(ChangeContext ctx) throws RestApiException, IOException {
change = ctx.getChange();
if (!accountIds.isEmpty()) {
if (state == CC) {
addedCCs = approvalsUtil.addCcs(ctx.getNotes(), ctx.getUpdate(change.currentPatchSetId()), accountIds, forGroup);
} else {
addedReviewers = approvalsUtil.addReviewers(ctx.getNotes(), ctx.getUpdate(change.currentPatchSetId()), projectCache.get(change.getProject()).orElseThrow(illegalState(change.getProject())).getLabelTypes(change.getDest()), change, accountIds);
}
}
ReviewerStateInternal internalState = ReviewerStateInternal.fromReviewerState(state);
// TODO(dborowitz): This behavior should live in ApprovalsUtil or something, like addCcs does.
ImmutableSet<Address> existing = ctx.getNotes().getReviewersByEmail().byState(internalState);
ImmutableList<Address> addressesToAdd = addresses.stream().filter(a -> !existing.contains(a)).collect(toImmutableList());
if (state == CC) {
addedCCsByEmail = addressesToAdd;
} else {
addedReviewersByEmail = addressesToAdd;
}
for (Address a : addressesToAdd) {
ctx.getUpdate(change.currentPatchSetId()).putReviewerByEmail(a, internalState);
}
if (addedCCs.isEmpty() && addedReviewers.isEmpty() && addressesToAdd.isEmpty()) {
return false;
}
checkAdded();
if (patchSet == null) {
patchSet = requireNonNull(psUtil.current(ctx.getNotes()));
}
return true;
}
Aggregations