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