Search in sources :

Example 6 with ParameterizedString

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));
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) ProjectState(com.google.gerrit.server.project.ProjectState) Change(com.google.gerrit.entities.Change) ParameterizedString(com.google.gerrit.common.data.ParameterizedString) ChangeData(com.google.gerrit.server.query.change.ChangeData) ChangeSet(com.google.gerrit.server.submit.ChangeSet) ParameterizedString(com.google.gerrit.common.data.ParameterizedString)

Example 7 with ParameterizedString

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);
}
Also used : RegExp(dk.brics.automaton.RegExp) ParameterizedString(com.google.gerrit.common.data.ParameterizedString) ParameterizedString(com.google.gerrit.common.data.ParameterizedString)

Aggregations

ParameterizedString (com.google.gerrit.common.data.ParameterizedString)7 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)2 ChangeData (com.google.gerrit.server.query.change.ChangeData)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 NamingException (javax.naming.NamingException)2 DirContext (javax.naming.directory.DirContext)2 LoginException (javax.security.auth.login.LoginException)2 LdapSchema (com.google.gerrit.auth.ldap.Helper.LdapSchema)1 GroupReference (com.google.gerrit.common.data.GroupReference)1 Change (com.google.gerrit.entities.Change)1 GroupReference (com.google.gerrit.entities.GroupReference)1 UiAction (com.google.gerrit.extensions.webui.UiAction)1 Change (com.google.gerrit.reviewdb.client.Change)1 RevId (com.google.gerrit.reviewdb.client.RevId)1 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)1 LdapSchema (com.google.gerrit.server.auth.ldap.Helper.LdapSchema)1 ChangeSet (com.google.gerrit.server.git.ChangeSet)1 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)1