Search in sources :

Example 1 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, ProjectControl pctl, Set<String> targets) {
    BranchInfo info = new BranchInfo();
    info.ref = ref.getName();
    info.revision = ref.getObjectId() != null ? ref.getObjectId().name() : null;
    info.canDelete = !targets.contains(ref.getName()) && perm.testOrFalse(RefPermission.DELETE) ? true : null;
    BranchResource rsrc = new BranchResource(pctl, info);
    for (UiAction.Description d : uiActions.from(branchViews, rsrc)) {
        if (info.actions == null) {
            info.actions = new TreeMap<>();
        }
        info.actions.put(d.getId(), new ActionInfo(d));
    }
    List<WebLinkInfo> links = webLinks.getBranchLinks(pctl.getProject().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) ActionInfo(com.google.gerrit.extensions.common.ActionInfo) UiAction(com.google.gerrit.extensions.webui.UiAction)

Example 2 with ActionInfo

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

the class ActionsIT method visitedRevisionActionsAssertions.

private void visitedRevisionActionsAssertions(Map<String, ActionInfo> origActions, Map<String, ActionInfo> newActions) {
    assertThat(newActions).isNotNull();
    Set<String> expectedNames = new TreeSet<>(origActions.keySet());
    expectedNames.remove("cherrypick");
    assertThat(newActions.keySet()).isEqualTo(expectedNames);
    ActionInfo rebase = newActions.get("rebase");
    assertThat(rebase).isNotNull();
    assertThat(rebase.label).isEqualTo("All Your Base");
}
Also used : TreeSet(java.util.TreeSet) ActionInfo(com.google.gerrit.extensions.common.ActionInfo)

Example 3 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(ChangeControl ctl, List<ActionVisitor> visitors, ChangeInfo changeInfo) {
    Map<String, ActionInfo> out = new LinkedHashMap<>();
    if (!ctl.getUser().isIdentifiedUser()) {
        return out;
    }
    FluentIterable<UiAction.Description> descs = uiActions.from(changeViews, changeResourceFactory.create(ctl));
    // resulting action map.
    if (ctl.getChange().getStatus().isOpen()) {
        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 = descs.append(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) 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 4 with ActionInfo

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

the class SubmitByFastForwardIT method submitFastForwardNotPossible_Conflict.

@Test
public void submitFastForwardNotPossible_Conflict() throws Throwable {
    RevCommit initialHead = projectOperations.project(project).getHead("master");
    PushOneCommit.Result change = createChange("Change 1", "a.txt", "content");
    submit(change.getChangeId());
    RevCommit headAfterFirstSubmit = projectOperations.project(project).getHead("master");
    testRepo.reset(initialHead);
    PushOneCommit.Result change2 = createChange("Change 2", "b.txt", "other content");
    approve(change2.getChangeId());
    Map<String, ActionInfo> actions = gApi.changes().id(change2.getChangeId()).revision(1).actions();
    assertThat(actions).containsKey("submit");
    ActionInfo info = actions.get("submit");
    assertThat(info.enabled).isNull();
    submitWithConflict(change2.getChangeId(), "Failed to submit 1 change due to the following problems:\n" + "Change " + change2.getChange().getId() + ": Project policy requires " + "all submissions to be a fast-forward. Please rebase the change " + "locally and upload again for review.");
    assertThat(projectOperations.project(project).getHead("master")).isEqualTo(headAfterFirstSubmit);
    assertSubmitter(change.getChangeId(), 1);
    assertRefUpdatedEvents(initialHead, headAfterFirstSubmit);
    assertChangeMergedEvents(change.getChangeId(), headAfterFirstSubmit.name());
}
Also used : ActionInfo(com.google.gerrit.extensions.common.ActionInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 5 with ActionInfo

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

the class SubmitRequirementIT method submitRequirementThatOverridesParentSubmitRequirementTakesEffectImmediately_staleIndex.

@Test
public void submitRequirementThatOverridesParentSubmitRequirementTakesEffectImmediately_staleIndex() 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");
    // disable change index writes so that the change in the index gets stale when the new submit
    // requirement is added
    disableChangeIndexWrites();
    try {
        // 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();
    } finally {
        enableChangeIndexWrites();
    }
}
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)

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