use of com.google.gerrit.entities.LabelType in project gerrit by GerritCodeReview.
the class SubmitWithStickyApprovalDiff method getLatestApprovedPatchsetId.
private PatchSet.Id getLatestApprovedPatchsetId(ChangeNotes notes) {
ProjectState projectState = projectCache.get(notes.getProjectName()).orElseThrow(illegalState(notes.getProjectName()));
PatchSet.Id maxPatchSetId = PatchSet.id(notes.getChangeId(), 1);
for (PatchSetApproval patchSetApproval : notes.getApprovals().values()) {
if (!patchSetApproval.label().equals(LabelId.CODE_REVIEW)) {
continue;
}
Optional<LabelType> lt = projectState.getLabelTypes(notes).byLabel(patchSetApproval.labelId());
if (!lt.isPresent() || !lt.get().isMaxPositive(patchSetApproval)) {
continue;
}
if (patchSetApproval.patchSetId().get() > maxPatchSetId.get()) {
maxPatchSetId = patchSetApproval.patchSetId();
}
}
return maxPatchSetId;
}
use of com.google.gerrit.entities.LabelType in project gerrit by GerritCodeReview.
the class MoveChangeIT method moveChangeWithCurrentPatchSetLocked.
@Test
public void moveChangeWithCurrentPatchSetLocked() throws Exception {
// Move change that is locked
PushOneCommit.Result r = createChange();
BranchNameKey newBranch = BranchNameKey.create(r.getChange().change().getProject(), "moveTest");
createBranch(newBranch);
LabelType patchSetLock = TestLabels.patchSetLock();
try (ProjectConfigUpdate u = updateProject(project)) {
u.getConfig().upsertLabelType(patchSetLock);
u.save();
}
projectOperations.project(project).forUpdate().add(allowLabel(patchSetLock.getName()).ref("refs/heads/*").group(REGISTERED_USERS).range(0, 1)).update();
revision(r).review(new ReviewInput().label("Patch-Set-Lock", 1));
ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> move(r.getChangeId(), newBranch.branch()));
assertThat(thrown).hasMessageThat().contains(String.format("The current patch set of change %s is locked", r.getChange().getId()));
}
use of com.google.gerrit.entities.LabelType in project gerrit by GerritCodeReview.
the class PostReview method onBehalfOf.
private RevisionResource onBehalfOf(RevisionResource rev, LabelTypes labelTypes, ReviewInput in) throws BadRequestException, AuthException, UnprocessableEntityException, PermissionBackendException, IOException, ConfigInvalidException {
logger.atFine().log("request is executed on behalf of %s", in.onBehalfOf);
if (in.labels == null || in.labels.isEmpty()) {
throw new AuthException(String.format("label required to post review on behalf of \"%s\"", in.onBehalfOf));
}
if (in.drafts != DraftHandling.KEEP) {
throw new AuthException("not allowed to modify other user's drafts");
}
logger.atFine().log("label input: %s", in.labels);
CurrentUser caller = rev.getUser();
PermissionBackend.ForChange perm = rev.permissions();
Iterator<Map.Entry<String, Short>> itr = in.labels.entrySet().iterator();
while (itr.hasNext()) {
Map.Entry<String, Short> ent = itr.next();
Optional<LabelType> type = labelTypes.byLabel(ent.getKey());
if (!type.isPresent()) {
logger.atFine().log("label %s not found", ent.getKey());
if (strictLabels) {
throw new BadRequestException(String.format("label \"%s\" is not a configured label", ent.getKey()));
}
logger.atFine().log("ignoring input for unknown label %s", ent.getKey());
itr.remove();
continue;
}
if (caller.isInternalUser()) {
logger.atFine().log("skipping on behalf of permission check for label %s" + " because caller is an internal user", type.get().getName());
} else {
try {
perm.check(new LabelPermission.WithValue(ON_BEHALF_OF, type.get(), ent.getValue()));
} catch (AuthException e) {
throw new AuthException(String.format("not permitted to modify label \"%s\" on behalf of \"%s\"", type.get().getName(), in.onBehalfOf), e);
}
}
}
if (in.labels.isEmpty()) {
logger.atFine().log("labels are empty after unknown labels have been removed");
throw new AuthException(String.format("label required to post review on behalf of \"%s\"", in.onBehalfOf));
}
IdentifiedUser reviewer = accountResolver.resolve(in.onBehalfOf).asUniqueUserOnBehalfOf(caller);
logger.atFine().log("on behalf of user was resolved to %s", reviewer.getLoggableName());
try {
permissionBackend.user(reviewer).change(rev.getNotes()).check(ChangePermission.READ);
} catch (AuthException e) {
throw new UnprocessableEntityException(String.format("on_behalf_of account %s cannot see change", reviewer.getAccountId()), e);
}
return new RevisionResource(changeResourceFactory.create(rev.getNotes(), reviewer), rev.getPatchSet());
}
use of com.google.gerrit.entities.LabelType in project gerrit by GerritCodeReview.
the class AbstractPushForReview method pushNewPatchsetOverridingStickyLabel.
@Test
public void pushNewPatchsetOverridingStickyLabel() throws Exception {
try (ProjectConfigUpdate u = updateProject(project)) {
LabelType codeReview = TestLabels.codeReview().toBuilder().setCopyMaxScore(true).build();
u.getConfig().upsertLabelType(codeReview);
u.save();
}
PushOneCommit.Result r = pushTo("refs/for/master%l=Code-Review+2");
r.assertOkStatus();
PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo, PushOneCommit.SUBJECT, "b.txt", "anotherContent", r.getChangeId());
r = push.to("refs/for/master%l=Code-Review+1");
r.assertOkStatus();
}
use of com.google.gerrit.entities.LabelType in project gerrit by GerritCodeReview.
the class AbstractPushForReview method pushWithMultipleApprovals.
@Test
public void pushWithMultipleApprovals() throws Exception {
LabelType Q = label("Custom-Label", value(1, "Positive"), value(0, "No score"), value(-1, "Negative"));
String heads = "refs/heads/*";
try (ProjectConfigUpdate u = updateProject(project)) {
u.getConfig().upsertLabelType(Q);
u.save();
}
projectOperations.project(project).forUpdate().add(allowLabel("Custom-Label").ref(heads).group(ANONYMOUS_USERS).range(-1, 1)).update();
RevCommit c = commitBuilder().author(admin.newIdent()).committer(admin.newIdent()).add(PushOneCommit.FILE_NAME, PushOneCommit.FILE_CONTENT).message(PushOneCommit.SUBJECT).create();
pushHead(testRepo, "refs/for/master%l=Code-Review+1,l=Custom-Label-1", false);
ChangeInfo ci = get(GitUtil.getChangeId(testRepo, c).get(), DETAILED_LABELS, DETAILED_ACCOUNTS);
LabelInfo cr = ci.labels.get("Code-Review");
assertThat(cr.all).hasSize(1);
cr = ci.labels.get("Custom-Label");
assertThat(cr.all).hasSize(1);
// Check that the user who pushed the change was added as a reviewer since they added a vote
assertThatUserIsOnlyReviewer(ci, admin);
}
Aggregations