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;
}
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;
}
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();
}
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));
}
}
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)));
}
}
Aggregations