Search in sources :

Example 26 with SVcsRoot

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

the class BuildTypeRequest method updateVcsRootEntry.

@PUT
@Path("/{btLocator}/vcs-root-entries/{vcsRootLocator}")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Update a VCS root of the matching build configuration.", nickname = "updateBuildTypeVcsRoot")
public VcsRootEntry updateVcsRootEntry(@ApiParam(format = LocatorName.BUILD_TYPE) @PathParam("btLocator") String buildTypeLocator, @ApiParam(format = LocatorName.VCS_ROOT) @PathParam("vcsRootLocator") String vcsRootLocator, VcsRootEntry entry, @QueryParam("fields") String fields) {
    final BuildTypeOrTemplate buildType = myBuildTypeFinder.getBuildTypeOrTemplate(null, buildTypeLocator, true);
    final SVcsRoot vcsRoot = myVcsRootFinder.getItem(vcsRootLocator);
    final SVcsRoot resultVcsRoot = entry.replaceIn(buildType.get(), vcsRoot, myVcsRootFinder);
    buildType.persist("VCS root replaced");
    return new VcsRootEntry(resultVcsRoot, buildType, new Fields(fields), myBeanContext);
}
Also used : BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) ApiOperation(io.swagger.annotations.ApiOperation)

Example 27 with SVcsRoot

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

the class VcsRootRequest method deleteAllProperties.

@DELETE
@Path("/{vcsRootLocator}/properties")
@ApiOperation(value = "Delete all properties of the matching VCS root.", nickname = "deleteAllVcsRootProperties")
public void deleteAllProperties(@ApiParam(format = LocatorName.VCS_ROOT) @PathParam("vcsRootLocator") String vcsRootLocator) {
    final SVcsRoot vcsRoot = myVcsRootFinder.getItem(vcsRootLocator);
    vcsRoot.setProperties(new HashMap<String, String>());
    vcsRoot.schedulePersisting("All VCS root properties removed");
}
Also used : SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) ApiOperation(io.swagger.annotations.ApiOperation)

Example 28 with SVcsRoot

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

the class BuildTypeRequest method deleteVcsRootEntry.

@DELETE
@Path("/{btLocator}/vcs-root-entries/{vcsRootLocator}")
@ApiOperation(value = "Remove a VCS root of the matching build configuration.", nickname = "deleteVcsRoot")
public void deleteVcsRootEntry(@ApiParam(format = LocatorName.BUILD_TYPE) @PathParam("btLocator") String buildTypeLocator, @ApiParam(format = LocatorName.VCS_ROOT) @PathParam("vcsRootLocator") String vcsRootLocator) {
    // todo: extract builType/VCS root id retrieving logic into single method
    final BuildTypeOrTemplate buildType = myBuildTypeFinder.getBuildTypeOrTemplate(null, buildTypeLocator, true);
    // this assumes VCS root id are unique throughout the server
    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.");
    }
    buildType.get().removeVcsRoot(vcsRoot);
    buildType.persist("VCS root detached");
}
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 29 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 30 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)

Aggregations

SVcsRoot (jetbrains.buildServer.vcs.SVcsRoot)38 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)8 NotNull (org.jetbrains.annotations.NotNull)7 Nullable (org.jetbrains.annotations.Nullable)7 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)5 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)5 SProject (jetbrains.buildServer.serverSide.SProject)4 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 SpaceExternalChangeViewerExtension (jetbrains.buildServer.buildTriggers.vcs.git.SpaceExternalChangeViewerExtension)3 PagerData (jetbrains.buildServer.server.rest.model.PagerData)3 LocatorDimension (jetbrains.buildServer.server.rest.swagger.annotations.LocatorDimension)3 LocatorResource (jetbrains.buildServer.server.rest.swagger.annotations.LocatorResource)3