Search in sources :

Example 36 with SVcsRoot

use of jetbrains.buildServer.vcs.SVcsRoot in project teamcity-rest by JetBrains.

the class BuildTypeRequest method getVcsRootEntry.

@GET
@Path("/{btLocator}/vcs-root-entries/{vcsRootLocator}")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Get a VCS root of the matching build configuration.", nickname = "getVcsRoot")
public VcsRootEntry getVcsRootEntry(@ApiParam(format = LocatorName.BUILD_TYPE) @PathParam("btLocator") String buildTypeLocator, @ApiParam(format = LocatorName.VCS_ROOT) @PathParam("vcsRootLocator") String vcsRootLocator, @QueryParam("fields") String fields) {
    final BuildTypeOrTemplate buildType = myBuildTypeFinder.getBuildTypeOrTemplate(null, buildTypeLocator, true);
    final SVcsRoot vcsRoot = myVcsRootFinder.getItem(vcsRootLocator);
    if (!buildType.get().containsVcsRoot(vcsRoot.getId())) {
        throw new NotFoundException("VCS root with id '" + vcsRoot.getExternalId() + "' is not attached to the build type.");
    }
    return new VcsRootEntry(vcsRoot, buildType, new Fields(fields), myBeanContext);
}
Also used : BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) ApiOperation(io.swagger.annotations.ApiOperation)

Example 37 with SVcsRoot

use of jetbrains.buildServer.vcs.SVcsRoot in project teamcity-rest by JetBrains.

the class ProjectFinder method findSingleItem.

@Nullable
@Override
public SProject findSingleItem(@NotNull final Locator locator) {
    if (locator.isSingleValue()) {
        // no dimensions found, assume it's a name or internal id or external id
        SProject project = null;
        @SuppressWarnings("ConstantConditions") @NotNull final String singleValue = locator.getSingleValue();
        project = myProjectManager.findProjectByExternalId(singleValue);
        if (project != null) {
            return project;
        }
        final List<SProject> projectsByName = findProjectsByName(null, singleValue, true);
        if (projectsByName.size() == 1) {
            return projectsByName.get(0);
        }
        project = myProjectManager.findProjectById(singleValue);
        if (project != null) {
            return project;
        }
        throw new NotFoundException("No project found by name or internal/external id '" + singleValue + "'.");
    }
    String id = locator.getSingleDimensionValue(DIMENSION_ID);
    if (id != null) {
        SProject project = myProjectManager.findProjectByExternalId(id);
        if (project == null) {
            if (TeamCityProperties.getBoolean(APIController.REST_COMPATIBILITY_ALLOW_EXTERNAL_ID_AS_INTERNAL)) {
                project = myProjectManager.findProjectById(id);
                if (project == null) {
                    throw new NotFoundException("No project found by locator '" + locator.getStringRepresentation() + "' in compatibility mode. Project cannot be found by external or internal id '" + id + "'.");
                }
            } else {
                throw new NotFoundException("No project found by locator '" + locator.getStringRepresentation() + "'. Project cannot be found by external id '" + id + "'.");
            }
        }
        return project;
    }
    String internalId = locator.getSingleDimensionValue(DIMENSION_INTERNAL_ID);
    if (internalId != null) {
        SProject project = myProjectManager.findProjectById(internalId);
        if (project == null) {
            throw new NotFoundException("No project found by locator '" + locator.getStringRepresentation() + "'. Project cannot be found by internal id '" + internalId + "'.");
        }
        return project;
    }
    String uuid = locator.getSingleDimensionValue(DIMENSION_UUID);
    if (!StringUtil.isEmpty(uuid)) {
        SProject project = myProjectManager.findProjectByConfigId(uuid);
        if (project == null) {
            // protecting against brute force uuid guessing
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            // ignore
            }
            throw new NotFoundException("No project found by locator '" + locator.getStringRepresentation() + "'. Project cannot be found by uuid '" + uuid + "'.");
        }
        return project;
    }
    String buildLocator = locator.getSingleDimensionValue(BUILD);
    if (!StringUtil.isEmpty(buildLocator)) {
        BuildPromotion build = myServiceLocator.getSingletonService(BuildPromotionFinder.class).getItem(buildLocator);
        SBuildType buildType = build.getBuildType();
        if (buildType != null) {
            return buildType.getProject();
        }
    }
    String buildTypeLocator = locator.getSingleDimensionValue(BUILD_TYPE);
    if (!StringUtil.isEmpty(buildTypeLocator)) {
        BuildTypeOrTemplate buildType = myServiceLocator.getSingletonService(BuildTypeFinder.class).getItem(buildTypeLocator);
        return buildType.getProject();
    }
    String vcsRootLocator = locator.getSingleDimensionValue(VCS_ROOT);
    if (!StringUtil.isEmpty(vcsRootLocator)) {
        SVcsRoot vcsRoot = myServiceLocator.getSingletonService(VcsRootFinder.class).getItem(vcsRootLocator);
        return vcsRoot.getProject();
    }
    return null;
}
Also used : BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) NotNull(org.jetbrains.annotations.NotNull) SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) Nullable(org.jetbrains.annotations.Nullable)

Example 38 with SVcsRoot

use of jetbrains.buildServer.vcs.SVcsRoot in project teamcity-rest by JetBrains.

the class VcsRootFinder method findSingleItem.

@Nullable
@Override
public SVcsRoot findSingleItem(@NotNull final Locator locator) {
    if (locator.isSingleValue()) {
        // no dimensions found, assume it's an internal id or external id
        return getVcsRootByExternalOrInternalId(locator.getSingleValue());
    }
    final String id = locator.getSingleDimensionValue(DIMENSION_ID);
    if (id != null) {
        SVcsRoot root;
        if (TeamCityProperties.getBoolean(APIController.REST_COMPATIBILITY_ALLOW_EXTERNAL_ID_AS_INTERNAL)) {
            root = getVcsRootByExternalOrInternalId(id);
        } else {
            root = myProjectManager.findVcsRootByExternalId(id);
            if (root == null) {
                throw new NotFoundException("No VCS root can be found by id '" + id + "'.");
            }
            // todo: this and other invocations except for in getFilter can be removed as the filter is applied to all items
            checkPermission(Permission.VIEW_BUILD_CONFIGURATION_SETTINGS, root);
        }
        return root;
    }
    Long internalId = locator.getSingleDimensionValueAsLong(INTERNAL_ID);
    if (internalId != null) {
        SVcsRoot root = myVcsManager.findRootById(internalId);
        if (root == null) {
            throw new NotFoundException("No VCS root can be found by internal id '" + internalId + "'.");
        }
        checkPermission(Permission.VIEW_BUILD_CONFIGURATION_SETTINGS, root);
        return root;
    }
    String uuid = locator.getSingleDimensionValue(UUID);
    if (uuid != null) {
        final EntityId<Long> internalVCSRootId = myVcsRootIdentifiersManager.findEntityIdByConfigId(uuid);
        if (internalVCSRootId != null) {
            SVcsRoot root = myVcsManager.findRootById(internalVCSRootId.getInternalId());
            if (root != null) {
                checkPermission(Permission.VIEW_BUILD_CONFIGURATION_SETTINGS, root);
                return root;
            }
        }
        // protecting against brute force uuid guessing
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        // ignore
        }
        throw new NotFoundException("No VCS root can be found by uuid '" + uuid + "'.");
    }
    return null;
}
Also used : SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) Nullable(org.jetbrains.annotations.Nullable)

Example 39 with SVcsRoot

use of jetbrains.buildServer.vcs.SVcsRoot in project teamcity-rest by JetBrains.

the class VcsRootRequest method changeProperties.

@PUT
@Path("/{vcsRootLocator}/properties")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Update all properties of the matching VCS root.", nickname = "setVcsRootProperties")
public Properties changeProperties(@ApiParam(format = LocatorName.VCS_ROOT) @PathParam("vcsRootLocator") String vcsRootLocator, Properties properties, @QueryParam("fields") String fields) {
    final SVcsRoot vcsRoot = myVcsRootFinder.getItem(vcsRootLocator);
    vcsRoot.setProperties(properties.getMap());
    vcsRoot.schedulePersisting("VCS root changed");
    return new Properties(vcsRoot.getProperties(), null, new Fields(fields), myBeanContext);
}
Also used : SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) Fields(jetbrains.buildServer.server.rest.model.Fields) Properties(jetbrains.buildServer.server.rest.model.Properties) ApiOperation(io.swagger.annotations.ApiOperation)

Example 40 with SVcsRoot

use of jetbrains.buildServer.vcs.SVcsRoot in project teamcity-rest by JetBrains.

the class VcsRootRequest method setField.

@PUT
@Path("/{vcsRootLocator}/{field}")
@Consumes("text/plain")
@Produces("text/plain")
@ApiOperation(value = "Update a field of the matching VCS root.", nickname = "setVcsRootField")
public String setField(@ApiParam(format = LocatorName.VCS_ROOT) @PathParam("vcsRootLocator") String vcsRootLocator, @PathParam("field") String fieldName, String newValue) {
    @NotNull final SVcsRoot vcsRoot = myVcsRootFinder.getItem(vcsRootLocator);
    VcsRoot.setFieldValue(vcsRoot, fieldName, newValue, myProjectFinder);
    vcsRoot.schedulePersisting("Field with name " + fieldName + " changed in VCS root");
    return VcsRoot.getFieldValue(vcsRoot, fieldName, myDataProvider);
}
Also used : SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) NotNull(org.jetbrains.annotations.NotNull) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

SVcsRoot (jetbrains.buildServer.vcs.SVcsRoot)51 ApiOperation (io.swagger.annotations.ApiOperation)13 BuildTypeOrTemplate (jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate)12 Test (org.testng.annotations.Test)11 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)10 VcsRootInstance (jetbrains.buildServer.vcs.VcsRootInstance)9 Nullable (org.jetbrains.annotations.Nullable)8 NotNull (org.jetbrains.annotations.NotNull)7 SProject (jetbrains.buildServer.serverSide.SProject)6 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)5 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)5 VcsRoot (jetbrains.buildServer.vcs.VcsRoot)5 MockVcsSupport (jetbrains.buildServer.serverSide.impl.MockVcsSupport)4 CheckoutRules (jetbrains.buildServer.vcs.CheckoutRules)4 Logger (com.intellij.openapi.diagnostic.Logger)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 SpaceExternalChangeViewerExtension (jetbrains.buildServer.buildTriggers.vcs.git.SpaceExternalChangeViewerExtension)3