use of com.google.gerrit.extensions.api.changes.RevisionApi in project gerrit by GerritCodeReview.
the class ChangeIT method rebaseNotAllowedForOwnerWithoutPushPermission.
@Test
public void rebaseNotAllowedForOwnerWithoutPushPermission() throws Exception {
// Create two changes both with the same parent
PushOneCommit.Result r = createChange();
testRepo.reset("HEAD~1");
PushOneCommit.Result r2 = createChange();
// Approve and submit the first change
RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
revision.review(ReviewInput.approve());
revision.submit();
projectOperations.project(project).forUpdate().add(block(Permission.PUSH).ref("refs/for/*").group(REGISTERED_USERS)).update();
// Rebase the second
String changeId = r2.getChangeId();
AuthException thrown = assertThrows(AuthException.class, () -> gApi.changes().id(changeId).rebase());
assertThat(thrown).hasMessageThat().contains("rebase not permitted");
}
use of com.google.gerrit.extensions.api.changes.RevisionApi in project gerrit by GerritCodeReview.
the class StickyApprovalsIT method trivialRebase.
private void trivialRebase(String changeId) throws Exception {
setApiUser(admin);
testRepo.reset(getRemoteHead());
PushOneCommit push = pushFactory.create(db, admin.getIdent(), testRepo, "Other Change", "a" + System.nanoTime() + ".txt", PushOneCommit.FILE_CONTENT);
PushOneCommit.Result r = push.to("refs/for/master");
r.assertOkStatus();
RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
ReviewInput in = new ReviewInput().label("Code-Review", 2).label("Verified", 1);
revision.review(in);
revision.submit();
gApi.changes().id(changeId).current().rebase();
assertThat(getChangeKind(changeId)).isEqualTo(TRIVIAL_REBASE);
}
use of com.google.gerrit.extensions.api.changes.RevisionApi in project gerrit by GerritCodeReview.
the class ChangeKindCreator method trivialRebase.
private void trivialRebase(String changeId, TestRepository<InMemoryRepository> testRepo, TestAccount user, Project.NameKey project) throws Exception {
requestScopeOperations.setApiUser(user.id());
testRepo.reset(projectOperations.project(project).getHead("master"));
PushOneCommit push = pushFactory.create(user.newIdent(), testRepo, "Other Change", "a" + System.nanoTime() + ".txt", PushOneCommit.FILE_CONTENT);
PushOneCommit.Result r = push.to("refs/for/master");
r.assertOkStatus();
RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
ReviewInput in = new ReviewInput().label(LabelId.CODE_REVIEW, 2).label(LabelId.VERIFIED, 1);
revision.review(in);
revision.submit();
gApi.changes().id(changeId).current().rebase();
assertThat(getChangeKind(changeId)).isEqualTo(ChangeKind.TRIVIAL_REBASE);
}
use of com.google.gerrit.extensions.api.changes.RevisionApi in project gerrit by GerritCodeReview.
the class ImpersonationIT method voteOnBehalfOfRequiresLabel.
@Test
public void voteOnBehalfOfRequiresLabel() throws Exception {
allowCodeReviewOnBehalfOf();
PushOneCommit.Result r = createChange();
RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
ReviewInput in = new ReviewInput();
in.onBehalfOf = user.id().toString();
in.message = "Message on behalf of";
AuthException thrown = assertThrows(AuthException.class, () -> revision.review(in));
assertThat(thrown).hasMessageThat().contains("label required to post review on behalf of \"" + in.onBehalfOf + '"');
}
use of com.google.gerrit.extensions.api.changes.RevisionApi in project gerrit by GerritCodeReview.
the class ImpersonationIT method voteOnBehalfOfInvisibleUserNotAllowed.
@GerritConfig(name = "accounts.visibility", value = "SAME_GROUP")
@Test
public void voteOnBehalfOfInvisibleUserNotAllowed() throws Exception {
allowCodeReviewOnBehalfOf();
requestScopeOperations.setApiUser(accountCreator.user2().id());
assertThat(accountControlFactory.get().canSee(user.id())).isFalse();
PushOneCommit.Result r = createChange();
RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
ReviewInput in = new ReviewInput();
in.onBehalfOf = user.id().toString();
in.label("Code-Review", 1);
UnprocessableEntityException thrown = assertThrows(UnprocessableEntityException.class, () -> revision.review(in));
assertThat(thrown).hasMessageThat().contains("not found");
assertThat(thrown).hasMessageThat().contains(in.onBehalfOf);
}
Aggregations