Search in sources :

Example 1 with VcsSettings

use of jetbrains.vcs.api.VcsSettings 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)

Example 2 with VcsSettings

use of jetbrains.vcs.api.VcsSettings in project teamcity-rest by JetBrains.

the class VcsRoot method getRepositoryMappings.

public static Collection<VcsMappingElement> getRepositoryMappings(@NotNull final jetbrains.buildServer.vcs.VcsRoot root, @NotNull final VcsManager vcsManager) throws VcsException {
    final VcsSettings vcsSettings = new VcsSettings(root, "");
    final MappingGeneratorService mappingGenerator = vcsManager.getVcsService(vcsSettings, MappingGeneratorService.class);
    if (mappingGenerator == null) {
        return Collections.emptyList();
    }
    return mappingGenerator.generateMapping();
}
Also used : MappingGeneratorService(jetbrains.vcs.api.services.tc.MappingGeneratorService) VcsSettings(jetbrains.vcs.api.VcsSettings)

Aggregations

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