Search in sources :

Example 6 with ApprovalInfo

use of com.google.gerrit.extensions.common.ApprovalInfo in project gerrit by GerritCodeReview.

the class ChangeJson method getApprovalInfo.

public static ApprovalInfo getApprovalInfo(Account.Id id, Integer value, VotingRangeInfo permittedVotingRange, String tag, Timestamp date) {
    ApprovalInfo ai = new ApprovalInfo(id.get());
    ai.value = value;
    ai.permittedVotingRange = permittedVotingRange;
    ai.date = date;
    ai.tag = tag;
    return ai;
}
Also used : ApprovalInfo(com.google.gerrit.extensions.common.ApprovalInfo)

Example 7 with ApprovalInfo

use of com.google.gerrit.extensions.common.ApprovalInfo in project gerrit by GerritCodeReview.

the class ChangeJson method approvalInfo.

private ApprovalInfo approvalInfo(Account.Id id, Integer value, VotingRangeInfo permittedVotingRange, String tag, Timestamp date) {
    ApprovalInfo ai = getApprovalInfo(id, value, permittedVotingRange, tag, date);
    accountLoader.put(ai);
    return ai;
}
Also used : ApprovalInfo(com.google.gerrit.extensions.common.ApprovalInfo)

Example 8 with ApprovalInfo

use of com.google.gerrit.extensions.common.ApprovalInfo in project gerrit by GerritCodeReview.

the class ChangeIT method maxPermittedValueBlocked.

@Test
public void maxPermittedValueBlocked() throws Exception {
    ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
    blockLabel(cfg, "Code-Review", REGISTERED_USERS, "refs/heads/*");
    saveProjectConfig(project, cfg);
    PushOneCommit.Result r = createChange();
    String triplet = project.get() + "~master~" + r.getChangeId();
    gApi.changes().id(triplet).addReviewer(user.username);
    ChangeInfo c = gApi.changes().id(triplet).get(EnumSet.of(ListChangesOption.DETAILED_LABELS));
    LabelInfo codeReview = c.labels.get("Code-Review");
    assertThat(codeReview.all).hasSize(1);
    ApprovalInfo approval = codeReview.all.get(0);
    assertThat(approval._accountId).isEqualTo(user.id.get());
    assertThat(approval.permittedVotingRange).isNull();
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) LabelInfo(com.google.gerrit.extensions.common.LabelInfo) ApprovalInfo(com.google.gerrit.extensions.common.ApprovalInfo) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 9 with ApprovalInfo

use of com.google.gerrit.extensions.common.ApprovalInfo in project gerrit by GerritCodeReview.

the class RevisionIT method postSubmitApprovalAfterVoteRemoved.

@Test
public void postSubmitApprovalAfterVoteRemoved() throws Exception {
    PushOneCommit.Result r = createChange();
    String changeId = project.get() + "~master~" + r.getChangeId();
    setApiUser(admin);
    revision(r).review(ReviewInput.approve());
    setApiUser(user);
    revision(r).review(ReviewInput.recommend());
    setApiUser(admin);
    gApi.changes().id(changeId).reviewer(user.username).deleteVote("Code-Review");
    Optional<ApprovalInfo> crUser = get(changeId, DETAILED_LABELS).labels.get("Code-Review").all.stream().filter(a -> a._accountId == user.id.get()).findFirst();
    assertThat(crUser).isPresent();
    assertThat(crUser.get().value).isEqualTo(0);
    revision(r).submit();
    setApiUser(user);
    ReviewInput in = new ReviewInput();
    in.label("Code-Review", 1);
    in.message = "Still LGTM";
    revision(r).review(in);
    ApprovalInfo cr = gApi.changes().id(changeId).get(EnumSet.of(ListChangesOption.DETAILED_LABELS)).labels.get("Code-Review").all.stream().filter(a -> a._accountId == user.getId().get()).findFirst().get();
    assertThat(cr.postSubmit).isTrue();
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) NotifyInfo(com.google.gerrit.extensions.api.changes.NotifyInfo) LabelInfo(com.google.gerrit.extensions.common.LabelInfo) PATCH_FILE_ONLY(com.google.gerrit.acceptance.PushOneCommit.PATCH_FILE_ONLY) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) TestAccount(com.google.gerrit.acceptance.TestAccount) Inject(com.google.inject.Inject) RestResponse(com.google.gerrit.acceptance.RestResponse) REVIEWER(com.google.gerrit.extensions.client.ReviewerState.REVIEWER) REGISTERED_USERS(com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) FILE_CONTENT(com.google.gerrit.acceptance.PushOneCommit.FILE_CONTENT) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) PATCH(com.google.gerrit.acceptance.PushOneCommit.PATCH) DraftApi(com.google.gerrit.extensions.api.changes.DraftApi) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) Locale(java.util.Locale) Map(java.util.Map) AuthException(com.google.gerrit.extensions.restapi.AuthException) Assert.fail(org.junit.Assert.fail) DateFormat(java.text.DateFormat) EnumSet(java.util.EnumSet) ApprovalInfo(com.google.gerrit.extensions.common.ApprovalInfo) FILE_NAME(com.google.gerrit.acceptance.PushOneCommit.FILE_NAME) ImmutableSet(com.google.common.collect.ImmutableSet) PatchSetWebLink(com.google.gerrit.extensions.webui.PatchSetWebLink) ImmutableMap(com.google.common.collect.ImmutableMap) RefSpec(org.eclipse.jgit.transport.RefSpec) SubmitType(com.google.gerrit.extensions.client.SubmitType) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) DETAILED_LABELS(com.google.gerrit.extensions.client.ListChangesOption.DETAILED_LABELS) HEAD(org.eclipse.jgit.lib.Constants.HEAD) Permission(com.google.gerrit.common.data.Permission) RefUpdate(org.eclipse.jgit.lib.RefUpdate) CommitInfo(com.google.gerrit.extensions.common.CommitInfo) MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) NotifyHandling(com.google.gerrit.extensions.api.changes.NotifyHandling) PersonIdent(org.eclipse.jgit.lib.PersonIdent) ChangeData(com.google.gerrit.server.query.change.ChangeData) List(java.util.List) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Optional(java.util.Optional) GitPerson(com.google.gerrit.extensions.common.GitPerson) Joiner(com.google.common.base.Joiner) Branch(com.google.gerrit.reviewdb.client.Branch) MergeableInfo(com.google.gerrit.extensions.common.MergeableInfo) Iterables(com.google.common.collect.Iterables) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) DiffInfo(com.google.gerrit.extensions.common.DiffInfo) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Change(com.google.gerrit.reviewdb.client.Change) COMMIT_MSG(com.google.gerrit.reviewdb.client.Patch.COMMIT_MSG) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) Iterators(com.google.common.collect.Iterators) ArrayList(java.util.ArrayList) MERGE_LIST(com.google.gerrit.reviewdb.client.Patch.MERGE_LIST) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult) ImmutableList(com.google.common.collect.ImmutableList) SUBJECT(com.google.gerrit.acceptance.PushOneCommit.SUBJECT) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) Account(com.google.gerrit.reviewdb.client.Account) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) FileInfo(com.google.gerrit.extensions.common.FileInfo) GetRevisionActions(com.google.gerrit.server.change.GetRevisionActions) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) ListChangesOption(com.google.gerrit.extensions.client.ListChangesOption) Iterator(java.util.Iterator) UTF_8(java.nio.charset.StandardCharsets.UTF_8) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) ObjectId(org.eclipse.jgit.lib.ObjectId) ETagView(com.google.gerrit.extensions.restapi.ETagView) WebLinkInfo(com.google.gerrit.extensions.common.WebLinkInfo) RecipientType(com.google.gerrit.extensions.api.changes.RecipientType) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) RevisionResource(com.google.gerrit.server.change.RevisionResource) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) DynamicSet(com.google.gerrit.extensions.registration.DynamicSet) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) Collections(java.util.Collections) ChangeStatus(com.google.gerrit.extensions.client.ChangeStatus) NameKey(com.google.gerrit.reviewdb.client.Branch.NameKey) ApprovalInfo(com.google.gerrit.extensions.common.ApprovalInfo) 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 10 with ApprovalInfo

use of com.google.gerrit.extensions.common.ApprovalInfo in project gerrit by GerritCodeReview.

the class ChangeReviewersIT method addSelfAsCc.

@Test
public void addSelfAsCc() throws Exception {
    // Create change owned by admin.
    PushOneCommit.Result r = createChange();
    // user adds self as CC.
    ReviewInput input = new ReviewInput().reviewer(user.username, CC, false);
    RestResponse resp = userRestSession.post("/changes/" + r.getChangeId() + "/revisions/" + r.getCommit().getName() + "/review", input);
    ReviewResult result = readContentFromJson(resp, 200, ReviewResult.class);
    assertThat(result.labels).isNull();
    assertThat(result.reviewers).isNotNull();
    assertThat(result.reviewers).hasSize(1);
    // Verify reviewer state.
    ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
    if (notesMigration.readChanges()) {
        assertReviewers(c, REVIEWER);
        assertReviewers(c, CC, user);
        // Verify no approvals were added.
        assertThat(c.labels).isNotNull();
        LabelInfo label = c.labels.get("Code-Review");
        assertThat(label).isNotNull();
        assertThat(label.all).isNull();
    } else {
        // When approvals are stored in ReviewDb, we still create a label for
        // the reviewing user, and force them into the REVIEWER state.
        assertReviewers(c, REVIEWER, user);
        assertReviewers(c, CC);
        LabelInfo label = c.labels.get("Code-Review");
        assertThat(label).isNotNull();
        assertThat(label.all).isNotNull();
        assertThat(label.all).hasSize(1);
        ApprovalInfo approval = label.all.get(0);
        assertThat(approval._accountId).isEqualTo(user.getId().get());
    }
}
Also used : LabelInfo(com.google.gerrit.extensions.common.LabelInfo) ApprovalInfo(com.google.gerrit.extensions.common.ApprovalInfo) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RestResponse(com.google.gerrit.acceptance.RestResponse) ReviewResult(com.google.gerrit.extensions.api.changes.ReviewResult) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

ApprovalInfo (com.google.gerrit.extensions.common.ApprovalInfo)16 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)10 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)10 Test (org.junit.Test)10 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)9 LabelInfo (com.google.gerrit.extensions.common.LabelInfo)9 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)5 RestResponse (com.google.gerrit.acceptance.RestResponse)4 ReviewResult (com.google.gerrit.extensions.api.changes.ReviewResult)3 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)3 Account (com.google.gerrit.reviewdb.client.Account)3 Change (com.google.gerrit.reviewdb.client.Change)3 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)3 HashMap (java.util.HashMap)3 ObjectId (org.eclipse.jgit.lib.ObjectId)3 Joiner (com.google.common.base.Joiner)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Iterables (com.google.common.collect.Iterables)2 ListChangesOption (com.google.gerrit.extensions.client.ListChangesOption)2