Search in sources :

Example 16 with RevisionApi

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");
}
Also used : RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) AuthException(com.google.gerrit.extensions.restapi.AuthException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 17 with RevisionApi

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);
}
Also used : RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit)

Example 18 with RevisionApi

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);
}
Also used : RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit)

Example 19 with RevisionApi

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 + '"');
}
Also used : RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) AuthException(com.google.gerrit.extensions.restapi.AuthException) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 20 with RevisionApi

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);
}
Also used : UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

RevisionApi (com.google.gerrit.extensions.api.changes.RevisionApi)23 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)21 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)20 Test (org.junit.Test)20 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)8 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)6 AuthException (com.google.gerrit.extensions.restapi.AuthException)5 PatchSetApproval (com.google.gerrit.entities.PatchSetApproval)3 GitPerson (com.google.gerrit.extensions.common.GitPerson)3 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)3 TestAccount (com.google.gerrit.acceptance.TestAccount)2 AccountInput (com.google.gerrit.extensions.api.accounts.AccountInput)2 ChangeInput (com.google.gerrit.extensions.common.ChangeInput)2 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)1 VerifyNoPiiInChangeNotes (com.google.gerrit.acceptance.VerifyNoPiiInChangeNotes)1 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)1 ChangeMessage (com.google.gerrit.entities.ChangeMessage)1 LabelType (com.google.gerrit.entities.LabelType)1 Project (com.google.gerrit.entities.Project)1 SubmitRequirementResult (com.google.gerrit.entities.SubmitRequirementResult)1