use of com.google.gerrit.common.data.ParameterizedString in project gerrit by GerritCodeReview.
the class Submit method getDescription.
@Override
public UiAction.Description getDescription(RevisionResource resource) throws IOException, PermissionBackendException {
Change change = resource.getChange();
if (!change.isNew() || !resource.isCurrent()) {
// submit not visible
return null;
}
if (!projectCache.get(resource.getProject()).map(ProjectState::statePermitsWrite).orElse(false)) {
// submit not visible
return null;
}
ChangeData cd = resource.getChangeResource().getChangeData();
try {
MergeOp.checkSubmitRequirements(cd);
} catch (ResourceConflictException e) {
// submit not visible
return null;
}
ChangeSet cs = mergeSuperSet.get().completeChangeSet(cd.change(), resource.getUser(), /*includingTopicClosure= */
false);
String topic = change.getTopic();
int topicSize = 0;
if (!Strings.isNullOrEmpty(topic)) {
topicSize = queryProvider.get().noFields().byTopicOpen(topic).size();
}
boolean treatWithTopic = submitWholeTopic && !Strings.isNullOrEmpty(topic) && topicSize > 1;
String submitProblems = problemsForSubmittingChangeset(cd, cs, resource.getUser());
if (submitProblems != null) {
return new UiAction.Description().setLabel(treatWithTopic ? submitTopicLabel : (cs.size() > 1) ? labelWithParents : label).setTitle(submitProblems).setVisible(true).setEnabled(false);
}
// Recheck mergeability rather than using value stored in the index, which may be stale.
// TODO(dborowitz): This is ugly; consider providing a way to not read stored fields from the
// index in the first place.
// cd.setMergeable(null);
// That was done in unmergeableChanges which was called by problemsForSubmittingChangeset, so
// now it is safe to read from the cache, as it yields the same result.
Boolean enabled = cd.isMergeable();
if (treatWithTopic) {
Map<String, String> params = ImmutableMap.of("topicSize", String.valueOf(topicSize), "submitSize", String.valueOf(cs.size()));
return new UiAction.Description().setLabel(submitTopicLabel).setTitle(Strings.emptyToNull(submitTopicTooltip.replace(params))).setVisible(true).setEnabled(Boolean.TRUE.equals(enabled));
}
Map<String, String> params = ImmutableMap.of("patchSet", String.valueOf(resource.getPatchSet().number()), "branch", change.getDest().shortName(), "commit", abbreviateName(resource.getPatchSet().commitId()), "submitSize", String.valueOf(cs.size()));
ParameterizedString tp = cs.size() > 1 ? titlePatternWithAncestors : titlePattern;
return new UiAction.Description().setLabel(cs.size() > 1 ? labelWithParents : label).setTitle(Strings.emptyToNull(tp.replace(params))).setVisible(true).setEnabled(Boolean.TRUE.equals(enabled));
}
use of com.google.gerrit.common.data.ParameterizedString in project gerrit by GerritCodeReview.
the class RefPattern method toRegExp.
public static RegExp toRegExp(String refPattern) {
if (isRE(refPattern)) {
refPattern = refPattern.substring(1);
}
ParameterizedString template = new ParameterizedString(refPattern);
String replacement = "_PLACEHOLDER_";
Map<String, String> params = ImmutableMap.of(RefPattern.USERID_SHARDED, replacement, RefPattern.USERNAME, replacement);
return new RegExp(template.replace(params), RegExp.NONE);
}
Aggregations