Search in sources :

Example 1 with PersonalSupportBatchService

use of jetbrains.vcs.api.services.tc.PersonalSupportBatchService in project teamcity-rest by JetBrains.

the class VcsRootFinder method repositoryIdStringMatches.

static boolean repositoryIdStringMatches(@NotNull final jetbrains.buildServer.vcs.VcsRoot root, @NotNull final String repositoryIdString, final VcsManager vcsManager) {
    String repositoryIdStringWithoutType;
    // see also PersonalPatchUtil.mapPathEx()
    final int index = repositoryIdString.indexOf(VcsMappingElement.SEPARATOR);
    if (index >= 0) {
        final String vcsName = repositoryIdString.substring(0, index);
        if (!vcsName.equals(root.getVcsName()))
            return false;
        repositoryIdStringWithoutType = repositoryIdString.substring(index + VcsMappingElement.SEPARATOR.length());
    } else {
        // pre-TeamCity 10 compatibility
        repositoryIdStringWithoutType = repositoryIdString;
    }
    try {
        final VcsSupportCore vcsSupport = vcsManager.findVcsByName(root.getVcsName());
        if (vcsSupport != null) {
            final PersonalSupportBatchService personalSupportService = vcsManager.getGenericService(root.getVcsName(), PersonalSupportBatchService.class);
            if (personalSupportService != null) {
                // if (null != personalSupportService.mapPath(Arrays.asList(new VcsSettings(root, "")), repositoryIdStringWithoutType, true).getMappedPath())
                // return true;
                List<Boolean> canAffectList = personalSupportService.canAffect(Arrays.asList(new VcsSettings(root, "")), Collections.singletonList(repositoryIdStringWithoutType), true);
                for (Boolean aBoolean : canAffectList) {
                    if (aBoolean)
                        return true;
                }
                return false;
            } else {
                LOG.debug("No personal support for VCS root " + LogUtil.describe(root) + " found, ignoring root in search");
            }
        } else {
            LOG.debug("No VCS support for VCS root " + LogUtil.describe(root) + " found, ignoring root in search");
        }
    } catch (Exception e) {
        LOG.debug("Error while retrieving mapping for VCS root " + LogUtil.describe(root) + " via mapFullPath, ignoring", e);
    }
    try {
        Collection<VcsMappingElement> vcsMappingElements = VcsRoot.getRepositoryMappings(root, vcsManager);
        for (VcsMappingElement vcsMappingElement : vcsMappingElements) {
            if (vcsMappingElement.getTo().startsWith(repositoryIdString) || repositoryIdString.startsWith(vcsMappingElement.getTo())) {
                // if (repositoryIdString.equals(vcsMappingElement.getTo())) {
                return true;
            }
        }
    } catch (Exception e) {
        LOG.debug("Error while retrieving mapping for VCS root " + LogUtil.describe(root) + ", ignoring root in search", e);
    }
    return false;
}
Also used : VcsMappingElement(jetbrains.vcs.api.services.tc.VcsMappingElement) VcsSupportCore(jetbrains.buildServer.vcs.VcsSupportCore) PersonalSupportBatchService(jetbrains.vcs.api.services.tc.PersonalSupportBatchService) VcsSettings(jetbrains.vcs.api.VcsSettings) AuthorizationFailedException(jetbrains.buildServer.server.rest.errors.AuthorizationFailedException) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException)

Aggregations

AuthorizationFailedException (jetbrains.buildServer.server.rest.errors.AuthorizationFailedException)1 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)1 VcsSupportCore (jetbrains.buildServer.vcs.VcsSupportCore)1 VcsSettings (jetbrains.vcs.api.VcsSettings)1 PersonalSupportBatchService (jetbrains.vcs.api.services.tc.PersonalSupportBatchService)1 VcsMappingElement (jetbrains.vcs.api.services.tc.VcsMappingElement)1