Search in sources :

Example 1 with RevisionApi

use of com.google.gerrit.extensions.api.changes.RevisionApi in project gerrit by GerritCodeReview.

the class StickyApprovalsIT method stickyVoteStoredOnRebase.

@Test
public void stickyVoteStoredOnRebase() throws Exception {
    // Code-Review will be sticky.
    String label = LabelId.CODE_REVIEW;
    try (ProjectConfigUpdate u = updateProject(project)) {
        u.getConfig().updateLabelType(label, b -> b.setCopyAnyScore(true));
        u.save();
    }
    // 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().label(LabelId.VERIFIED, 1));
    revision.submit();
    // Add an approval whose score should be copied.
    gApi.changes().id(r2.getChangeId()).current().review(ReviewInput.recommend());
    // Rebase the second change
    gApi.changes().id(r2.getChangeId()).rebase();
    List<PatchSetApproval> patchSetApprovals = r2.getChange().notes().getApprovalsWithCopied().values().stream().sorted(comparing(a -> a.patchSetId().get())).collect(toImmutableList());
    PatchSetApproval nonCopied = patchSetApprovals.get(0);
    PatchSetApproval copied = patchSetApprovals.get(1);
    assertCopied(nonCopied, 1, LabelId.CODE_REVIEW, (short) 1, /* copied= */
    false);
    assertCopied(copied, 2, LabelId.CODE_REVIEW, (short) 1, /* copied= */
    true);
}
Also used : RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 2 with RevisionApi

use of com.google.gerrit.extensions.api.changes.RevisionApi in project gerrit by GerritCodeReview.

the class RevisionIT method cherryPickToSameBranchWithRebase.

@Test
public void cherryPickToSameBranchWithRebase() throws Exception {
    // Push a new change, then merge it
    PushOneCommit.Result baseChange = createChange();
    String triplet = project.get() + "~master~" + baseChange.getChangeId();
    RevisionApi baseRevision = gApi.changes().id(triplet).current();
    baseRevision.review(ReviewInput.approve());
    baseRevision.submit();
    // Push a new change (change 1)
    PushOneCommit.Result r1 = createChange();
    // Push another new change (change 2)
    String subject = "Test change\n\nChange-Id: Ideadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
    PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo, subject, "another_file.txt", "another content");
    PushOneCommit.Result r2 = push.to("refs/for/master");
    // Change 2's parent should be change 1
    assertThat(r2.getCommit().getParents()[0].name()).isEqualTo(r1.getCommit().name());
    // Cherry pick change 2 onto the same branch
    triplet = project.get() + "~master~" + r2.getChangeId();
    ChangeApi orig = gApi.changes().id(triplet);
    CherryPickInput in = new CherryPickInput();
    in.destination = "master";
    in.message = subject;
    ChangeApi cherry = orig.revision(r2.getCommit().name()).cherryPick(in);
    ChangeInfo cherryInfo = cherry.get();
    assertThat(cherryInfo.messages).hasSize(2);
    Iterator<ChangeMessageInfo> cherryIt = cherryInfo.messages.iterator();
    assertThat(cherryIt.next().message).isEqualTo("Uploaded patch set 1.");
    assertThat(cherryIt.next().message).isEqualTo("Uploaded patch set 2.");
    // Parent of change 2 should now be the change that was merged, i.e.
    // change 2 is rebased onto the head of the master branch.
    String newParent = cherryInfo.revisions.get(cherryInfo.currentRevision).commit.parents.get(0).commit;
    assertThat(newParent).isEqualTo(baseChange.getCommit().name());
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 3 with RevisionApi

use of com.google.gerrit.extensions.api.changes.RevisionApi in project gerrit by GerritCodeReview.

the class ImpersonationIT method voteOnBehalfOf.

@Test
public void voteOnBehalfOf() throws Exception {
    allowCodeReviewOnBehalfOf();
    PushOneCommit.Result r = createChange();
    RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
    ReviewInput in = ReviewInput.recommend();
    in.onBehalfOf = user.id().toString();
    in.message = "Message on behalf of";
    revision.review(in);
    PatchSetApproval psa = Iterables.getOnlyElement(r.getChange().approvals().values());
    assertThat(psa.patchSetId().get()).isEqualTo(1);
    assertThat(psa.label()).isEqualTo("Code-Review");
    assertThat(psa.accountId()).isEqualTo(user.id());
    assertThat(psa.value()).isEqualTo(1);
    assertThat(psa.realAccountId()).isEqualTo(admin.id());
    ChangeData cd = r.getChange();
    ChangeMessage m = Iterables.getLast(cmUtil.byChange(cd.notes()));
    assertThat(m.getMessage()).endsWith(in.message);
    assertThat(m.getAuthor()).isEqualTo(user.id());
    assertThat(m.getRealAuthor()).isEqualTo(admin.id());
}
Also used : RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) ChangeMessage(com.google.gerrit.entities.ChangeMessage) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) ChangeData(com.google.gerrit.server.query.change.ChangeData) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 4 with RevisionApi

use of com.google.gerrit.extensions.api.changes.RevisionApi in project gerrit by GerritCodeReview.

the class ImpersonationIT method voteOnBehalfOfFailsWhenUserCannotSeeDestinationRef.

@Test
public void voteOnBehalfOfFailsWhenUserCannotSeeDestinationRef() throws Exception {
    blockRead(newGroup);
    allowCodeReviewOnBehalfOf();
    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("on_behalf_of account " + user.id() + " cannot see change");
}
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) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 5 with RevisionApi

use of com.google.gerrit.extensions.api.changes.RevisionApi in project gerrit by GerritCodeReview.

the class ImpersonationIT method voteOnBehalfOfLabelNotPermitted.

@Test
public void voteOnBehalfOfLabelNotPermitted() throws Exception {
    try (ProjectConfigUpdate u = updateProject(project)) {
        LabelType verified = TestLabels.verified();
        u.getConfig().upsertLabelType(verified);
        u.save();
    }
    PushOneCommit.Result r = createChange();
    RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
    ReviewInput in = new ReviewInput();
    in.onBehalfOf = user.id().toString();
    in.label(LabelId.VERIFIED, 1);
    AuthException thrown = assertThrows(AuthException.class, () -> revision.review(in));
    assertThat(thrown).hasMessageThat().contains("not permitted to modify label \"Verified\" on behalf of \"" + in.onBehalfOf + '"');
}
Also used : RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) LabelType(com.google.gerrit.entities.LabelType) 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)

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