Search in sources :

Example 11 with ActionInfo

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

the class ListBranches method createBranchInfo.

private BranchInfo createBranchInfo(PermissionBackend.ForRef perm, Ref ref, ProjectState projectState, CurrentUser user, Set<String> targets) {
    BranchInfo info = new BranchInfo();
    info.ref = ref.getName();
    info.revision = ref.getObjectId() != null ? ref.getObjectId().name() : null;
    if (isConfigRef(ref.getName())) {
        // Never allow to delete the meta config branch.
        info.canDelete = null;
    } else {
        info.canDelete = !targets.contains(ref.getName()) && perm.testOrFalse(RefPermission.DELETE) && projectState.statePermitsWrite() ? true : null;
    }
    BranchResource rsrc = new BranchResource(projectState, user, ref);
    for (UiAction.Description d : uiActions.from(branchViews, rsrc)) {
        if (info.actions == null) {
            info.actions = new TreeMap<>();
        }
        info.actions.put(d.getId(), new ActionInfo(d));
    }
    ImmutableList<WebLinkInfo> links = webLinks.getBranchLinks(projectState.getName(), ref.getName());
    info.webLinks = links.isEmpty() ? null : links;
    return info;
}
Also used : BranchInfo(com.google.gerrit.extensions.api.projects.BranchInfo) WebLinkInfo(com.google.gerrit.extensions.common.WebLinkInfo) BranchResource(com.google.gerrit.server.project.BranchResource) ActionInfo(com.google.gerrit.extensions.common.ActionInfo) UiAction(com.google.gerrit.extensions.webui.UiAction)

Example 12 with ActionInfo

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

the class ActionJson method toActionMap.

private Map<String, ActionInfo> toActionMap(ChangeData changeData, List<ActionVisitor> visitors, ChangeInfo changeInfo) {
    CurrentUser user = userProvider.get();
    Map<String, ActionInfo> out = new LinkedHashMap<>();
    if (!user.isIdentifiedUser()) {
        return out;
    }
    Iterable<UiAction.Description> descs = uiActions.from(changeViews, changeResourceFactory.create(changeData, user));
    // resulting action map.
    if (!changeData.change().isAbandoned()) {
        UiAction.Description descr = new UiAction.Description();
        PrivateInternals_UiActionDescription.setId(descr, "followup");
        PrivateInternals_UiActionDescription.setMethod(descr, "POST");
        descr.setTitle("Create follow-up change");
        descr.setLabel("Follow-Up");
        descs = Iterables.concat(descs, Collections.singleton(descr));
    }
    ACTION: for (UiAction.Description d : descs) {
        ActionInfo actionInfo = new ActionInfo(d);
        for (ActionVisitor visitor : visitors) {
            if (!visitor.visit(d.getId(), actionInfo, changeInfo)) {
                continue ACTION;
            }
        }
        out.put(d.getId(), actionInfo);
    }
    return out;
}
Also used : PrivateInternals_UiActionDescription(com.google.gerrit.extensions.webui.PrivateInternals_UiActionDescription) CurrentUser(com.google.gerrit.server.CurrentUser) ActionVisitor(com.google.gerrit.extensions.api.changes.ActionVisitor) ActionInfo(com.google.gerrit.extensions.common.ActionInfo) UiAction(com.google.gerrit.extensions.webui.UiAction) LinkedHashMap(java.util.LinkedHashMap)

Example 13 with ActionInfo

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

the class SubmitRequirementIT method submitRequirementThatOverridesParentSubmitRequirementTakesEffectImmediately.

@Test
public void submitRequirementThatOverridesParentSubmitRequirementTakesEffectImmediately() throws Exception {
    // Define submit requirement in root project that ignores self approvals from the uploader.
    configSubmitRequirement(allProjects, SubmitRequirement.builder().setName("Code-Review").setSubmittabilityExpression(SubmitRequirementExpression.create("label:Code-Review=MAX,user=non_uploader")).setAllowOverrideInChildProjects(true).build());
    PushOneCommit.Result r = createChange();
    String changeId = r.getChangeId();
    // Apply a self approval from the uploader.
    voteLabel(changeId, "Code-Review", 2);
    ChangeInfo change = gApi.changes().id(changeId).get();
    assertThat(change.submitRequirements).hasSize(2);
    // Code-Review+2 is ignored since it's a self approval from the uploader
    assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
    false);
    // Legacy requirement is coming from the label MaxWithBlock function. Already satisfied since it
    // doesn't ignore self approvals.
    assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.SATISFIED, /* isLegacy= */
    true);
    // since the change is not submittable we expect the submit action to be not returned
    assertThat(gApi.changes().id(changeId).current().actions()).doesNotContainKey("submit");
    // Override submit requirement in project (allow uploaders to self approve).
    configSubmitRequirement(project, SubmitRequirement.builder().setName("Code-Review").setSubmittabilityExpression(SubmitRequirementExpression.create("label:Code-Review=MAX")).setAllowOverrideInChildProjects(true).build());
    change = gApi.changes().id(changeId).get();
    assertThat(change.submitRequirements).hasSize(1);
    // the self approval from the uploader is no longer ignored, hence the submit requirement is
    // satisfied now
    assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.SATISFIED, /* isLegacy= */
    false);
    // since the change is submittable now we expect the submit action to be returned
    Map<String, ActionInfo> actions = gApi.changes().id(changeId).current().actions();
    assertThat(actions).containsKey("submit");
    ActionInfo submitAction = actions.get("submit");
    assertThat(submitAction.enabled).isTrue();
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ActionInfo(com.google.gerrit.extensions.common.ActionInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 14 with ActionInfo

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

the class ActionsIT method noSubmitWholeTopicAssertions.

private void noSubmitWholeTopicAssertions(Map<String, ActionInfo> actions, int nrChanges) {
    ActionInfo info = actions.get("submit");
    assertThat(info.enabled).isTrue();
    if (nrChanges == 1) {
        assertThat(info.label).isEqualTo("Submit");
    } else {
        assertThat(info.label).isEqualTo("Submit including parents");
    }
    assertThat(info.method).isEqualTo("POST");
    if (nrChanges == 1) {
        assertThat(info.title).isEqualTo("Submit patch set 1 into master");
    } else {
        assertThat(info.title).isEqualTo(String.format("Submit patch set 1 and ancestors (%d changes altogether) into master", nrChanges));
    }
}
Also used : ActionInfo(com.google.gerrit.extensions.common.ActionInfo)

Example 15 with ActionInfo

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

the class ActionsIT method currentRevisionActionVisitor.

@Test
public void currentRevisionActionVisitor() throws Exception {
    String id = createChange().getChangeId();
    amendChange(id);
    ChangeInfo origChange = gApi.changes().id(id).get(CHANGE_ACTIONS);
    Change.Id changeId = Change.id(origChange._number);
    class Visitor implements ActionVisitor {

        @Override
        public boolean visit(String name, ActionInfo actionInfo, ChangeInfo changeInfo) {
            // Do nothing; implicitly called for CURRENT_ACTIONS.
            return true;
        }

        @Override
        public boolean visit(String name, ActionInfo actionInfo, ChangeInfo changeInfo, RevisionInfo revisionInfo) {
            assertThat(changeInfo).isNotNull();
            assertThat(changeInfo._number).isEqualTo(origChange._number);
            assertThat(revisionInfo).isNotNull();
            assertThat(revisionInfo._number).isEqualTo(2);
            if (name.equals("cherrypick")) {
                return false;
            }
            if (name.equals("rebase")) {
                actionInfo.label = "All Your Base";
            }
            return true;
        }
    }
    Map<String, ActionInfo> origActions = gApi.changes().id(id).current().actions();
    assertThat(origActions.keySet()).containsAtLeast("cherrypick", "rebase");
    assertThat(origActions.get("rebase").label).isEqualTo("Rebase");
    try (Registration registration = extensionRegistry.newRegistration().add(new Visitor())) {
        // Test different codepaths within ActionJson...
        // ...via revision API.
        visitedCurrentRevisionActionsAssertions(origActions, gApi.changes().id(id).current().actions());
        // ...via change API with option.
        EnumSet<ListChangesOption> opts = EnumSet.of(CURRENT_ACTIONS, CURRENT_REVISION);
        ChangeInfo changeInfo = gApi.changes().id(id).get(opts);
        RevisionInfo revisionInfo = Iterables.getOnlyElement(changeInfo.revisions.values());
        visitedCurrentRevisionActionsAssertions(origActions, revisionInfo.actions);
        // ...via ChangeJson directly.
        ChangeData cd = changeDataFactory.create(project, changeId);
        revisionJsonFactory.create(opts).getRevisionInfo(cd, cd.patchSet(PatchSet.id(changeId, 1)));
    }
}
Also used : ListChangesOption(com.google.gerrit.extensions.client.ListChangesOption) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ActionVisitor(com.google.gerrit.extensions.api.changes.ActionVisitor) ActionVisitor(com.google.gerrit.extensions.api.changes.ActionVisitor) ActionInfo(com.google.gerrit.extensions.common.ActionInfo) Change(com.google.gerrit.entities.Change) ChangeData(com.google.gerrit.server.query.change.ChangeData) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

ActionInfo (com.google.gerrit.extensions.common.ActionInfo)18 Test (org.junit.Test)10 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)9 ActionVisitor (com.google.gerrit.extensions.api.changes.ActionVisitor)6 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)6 UiAction (com.google.gerrit.extensions.webui.UiAction)5 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)4 RevisionInfo (com.google.gerrit.extensions.common.RevisionInfo)4 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)3 TreeSet (java.util.TreeSet)3 BranchInfo (com.google.gerrit.extensions.api.projects.BranchInfo)2 ListChangesOption (com.google.gerrit.extensions.client.ListChangesOption)2 WebLinkInfo (com.google.gerrit.extensions.common.WebLinkInfo)2 PrivateInternals_UiActionDescription (com.google.gerrit.extensions.webui.PrivateInternals_UiActionDescription)2 ChangeData (com.google.gerrit.server.query.change.ChangeData)2 LinkedHashMap (java.util.LinkedHashMap)2 BooleanProjectConfig (com.google.gerrit.entities.BooleanProjectConfig)1 Change (com.google.gerrit.entities.Change)1 Project (com.google.gerrit.entities.Project)1 CommentLinkInfo (com.google.gerrit.extensions.api.projects.CommentLinkInfo)1