Search in sources :

Example 1 with SVcsRoot

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

the class VcsRootFinder method getPrefilteredItems.

@NotNull
@Override
public ItemHolder<SVcsRoot> getPrefilteredItems(@NotNull Locator locator) {
    final String affectedProjectLocator = locator.getSingleDimensionValue(AFFECTED_PROJECT);
    if (affectedProjectLocator != null) {
        List<SProject> projects = myProjectFinder.getItems(affectedProjectLocator).myEntries;
        projects.forEach(project -> myPermissionChecker.checkProjectPermission(Permission.VIEW_BUILD_CONFIGURATION_SETTINGS, project.getProjectId()));
        return FinderDataBinding.getItemHolder(projects.stream().flatMap(p -> p.getVcsRoots().stream()).collect(Collectors.toSet()));
    }
    final String projectLocator = locator.getSingleDimensionValue(PROJECT);
    if (projectLocator != null) {
        List<SProject> projects = myProjectFinder.getItemsNotEmpty(projectLocator).myEntries;
        projects.forEach(project -> myPermissionChecker.checkProjectPermission(Permission.VIEW_BUILD_CONFIGURATION_SETTINGS, project.getProjectId()));
        // consistent with Project.java:183
        return FinderDataBinding.getItemHolder(projects.stream().flatMap(p -> p.getOwnVcsRoots().stream()));
    }
    final List<SVcsRoot> allRegisteredVcsRoots = myVcsManager.getAllRegisteredVcsRoots();
    final List<SVcsRoot> result = new ArrayList<SVcsRoot>(allRegisteredVcsRoots.size());
    for (SVcsRoot root : allRegisteredVcsRoots) {
        try {
            checkPermission(Permission.VIEW_BUILD_CONFIGURATION_SETTINGS, root);
            result.add(root);
        } catch (AuthorizationFailedException e) {
        // ignore
        }
    }
    return getItemHolder(result);
}
Also used : java.util(java.util) AuthorizationFailedException(jetbrains.buildServer.server.rest.errors.AuthorizationFailedException) LocatorName(jetbrains.buildServer.server.rest.swagger.constants.LocatorName) LocatorResource(jetbrains.buildServer.server.rest.swagger.annotations.LocatorResource) BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) ParametersProvider(jetbrains.buildServer.parameters.ParametersProvider) EntityId(jetbrains.buildServer.serverSide.identifiers.EntityId) AbstractMapParametersProvider(jetbrains.buildServer.parameters.impl.AbstractMapParametersProvider) VcsRoot(jetbrains.buildServer.server.rest.model.change.VcsRoot) ProjectManager(jetbrains.buildServer.serverSide.ProjectManager) LogUtil(jetbrains.buildServer.serverSide.impl.LogUtil) VcsSettings(jetbrains.vcs.api.VcsSettings) Logger(com.intellij.openapi.diagnostic.Logger) VcsSupportCore(jetbrains.buildServer.vcs.VcsSupportCore) PagerData(jetbrains.buildServer.server.rest.model.PagerData) TeamCityProperties(jetbrains.buildServer.serverSide.TeamCityProperties) SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) Constants(jetbrains.buildServer.server.rest.request.Constants) VcsRootIdentifiersManager(jetbrains.buildServer.serverSide.identifiers.VcsRootIdentifiersManager) Collectors(java.util.stream.Collectors) APIController(jetbrains.buildServer.server.rest.APIController) Nullable(org.jetbrains.annotations.Nullable) CommonLocatorDimensionsList(jetbrains.buildServer.server.rest.swagger.constants.CommonLocatorDimensionsList) LocatorDimension(jetbrains.buildServer.server.rest.swagger.annotations.LocatorDimension) Permission(jetbrains.buildServer.serverSide.auth.Permission) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) VcsMappingElement(jetbrains.vcs.api.services.tc.VcsMappingElement) SProject(jetbrains.buildServer.serverSide.SProject) NotNull(org.jetbrains.annotations.NotNull) VcsManager(jetbrains.buildServer.vcs.VcsManager) PersonalSupportBatchService(jetbrains.vcs.api.services.tc.PersonalSupportBatchService) BuildProject(jetbrains.buildServer.BuildProject) SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) AuthorizationFailedException(jetbrains.buildServer.server.rest.errors.AuthorizationFailedException) SProject(jetbrains.buildServer.serverSide.SProject) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with SVcsRoot

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

the class BuildPromotionFinderTest method testSnapshotDependenciesAndBranches.

@Test
public void testSnapshotDependenciesAndBranches() throws Exception {
    final BuildTypeImpl buildConf0 = registerBuildType("buildConf0", "project");
    final BuildTypeImpl buildConf1 = registerBuildType("buildConf1", "project");
    final BuildTypeImpl buildConf2 = registerBuildType("buildConf2", "project");
    addDependency(buildConf2, buildConf1);
    addDependency(buildConf1, buildConf0);
    MockVcsSupport vcs = vcsSupport().withName("vcs").dagBased(true).register();
    BuildFinderTestBase.MockCollectRepositoryChangesPolicy collectChangesPolicy = new BuildFinderTestBase.MockCollectRepositoryChangesPolicy();
    vcs.setCollectChangesPolicy(collectChangesPolicy);
    final SVcsRoot vcsRoot = buildConf0.getProject().createVcsRoot("vcs", "extId", "name");
    buildConf0.addVcsRoot(vcsRoot);
    buildConf1.addVcsRoot(vcsRoot);
    buildConf2.addVcsRoot(vcsRoot);
    final VcsRootInstance vcsRootInstance = buildConf0.getVcsRootInstances().get(0);
    collectChangesPolicy.setCurrentState(vcsRootInstance, createVersionState("master", map("master", "1", "branch1", "2", "branch2", "3")));
    setBranchSpec(vcsRootInstance, "+:*");
    final BuildPromotion build20 = build().in(buildConf2).finish().getBuildPromotion();
    final BuildPromotion build10 = build20.getDependencies().iterator().next().getDependOn();
    final BuildPromotion build00 = build10.getDependencies().iterator().next().getDependOn();
    final BuildPromotion build2_20 = build().in(buildConf2).withBranch("branch1").finish().getBuildPromotion();
    final BuildPromotion build2_10 = build2_20.getDependencies().iterator().next().getDependOn();
    final BuildPromotion build2_00 = build2_10.getDependencies().iterator().next().getDependOn();
    checkBuilds("snapshotDependency:(to:(id:" + build10.getId() + "))", build00);
    checkBuilds("snapshotDependency:(to:(id:" + build2_10.getId() + "))", build2_00);
    final BuildPromotion build3_20 = build().in(buildConf2).withBranch("branch1").finish().getBuildPromotion();
    checkBuilds("snapshotDependency:(from:(id:" + build2_00.getId() + ")),equivalent:(id:" + build3_20.getId() + ")", build2_20);
}
Also used : SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) VcsRootInstance(jetbrains.buildServer.vcs.VcsRootInstance) Test(org.testng.annotations.Test)

Example 3 with SVcsRoot

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

the class BuildPromotionFinderTest method testBranchDimensionWithSeveralRoots.

@Test
public void testBranchDimensionWithSeveralRoots() throws ExecutionException, InterruptedException {
    final BuildTypeImpl buildConf2 = registerBuildType("buildConf2", "project");
    MockVcsSupport vcs = vcsSupport().withName("vcs").dagBased(true).register();
    BuildFinderTestBase.MockCollectRepositoryChangesPolicy collectChangesPolicy = new BuildFinderTestBase.MockCollectRepositoryChangesPolicy();
    vcs.setCollectChangesPolicy(collectChangesPolicy);
    SVcsRoot vcsRoot10 = buildConf2.getProject().createVcsRoot("vcs", "extId10", "name10");
    buildConf2.addVcsRoot(vcsRoot10);
    SVcsRoot vcsRoot20 = buildConf2.getProject().createVcsRoot("vcs", "extId20", "name20");
    buildConf2.addVcsRoot(vcsRoot20);
    final VcsRootInstance vcsRootInstance10 = buildConf2.getVcsRootInstanceForParent(vcsRoot10);
    assert vcsRootInstance10 != null;
    final VcsRootInstance vcsRootInstance20 = buildConf2.getVcsRootInstanceForParent(vcsRoot20);
    assert vcsRootInstance20 != null;
    collectChangesPolicy.setCurrentState(vcsRootInstance10, createVersionState("refs/heads/master", map("refs/heads/master", "a1", "refs/heads/branch1", "a2", "refs/heads/branch2", "a3")));
    collectChangesPolicy.setCurrentState(vcsRootInstance20, createVersionState("refs/heads/master", map("refs/heads/master", "b1", "refs/heads/branch1", "b2", "refs/heads/branch2", "b3")));
    setBranchSpec(vcsRootInstance10, "+:refs/heads/(*)");
    setBranchSpec(vcsRootInstance20, "+:refs/heads/(*)");
    myFixture.getVcsModificationChecker().checkForModifications(buildConf2.getVcsRootInstances(), OperationRequestor.UNKNOWN);
    final BuildPromotion build30 = build().in(buildConf2).finish().getBuildPromotion();
    final BuildPromotion build40 = build().in(buildConf2).withDefaultBranch().finish().getBuildPromotion();
    // not existing branch
    final BuildPromotion build50 = build().in(buildConf2).withBranch("branch").finish().getBuildPromotion();
    final BuildPromotion build60 = build().in(buildConf2).withBranch("branch1").finish().getBuildPromotion();
    // not existing branch
    final BuildPromotion build70 = build().in(buildConf2).withBranch("master").finish().getBuildPromotion();
    checkBuilds(null, build40, build30);
    checkBuilds("branch:(default:any)", build70, build60, build50, build40, build30);
    checkBuilds("branch:(name:<default>)", build40, build30);
    checkBuilds("buildType:(id:" + buildConf2.getExternalId() + "),branch:(name:<default>)", build40, build30);
    checkBuilds("branch:(name:master)", build70, build40, build30);
    checkBuilds("branch:(name:master,default:true)", build40, build30);
    checkBuilds("branch:(name:master,default:false)", build70);
    checkBuilds("buildType:(id:" + buildConf2.getExternalId() + "),branch:(name:master)", build70, build40, build30);
    checkBuilds("branch:(name:branch1)", build60);
    final BuildTypeImpl buildConf3 = registerBuildType("buildConf3", "project");
    SVcsRoot vcsRoot30 = buildConf3.getProject().createVcsRoot("vcs", "extId30", "name30");
    buildConf3.addVcsRoot(vcsRoot30);
    SVcsRoot vcsRoot40 = buildConf3.getProject().createVcsRoot("vcs", "extId40", "name40");
    buildConf3.addVcsRoot(vcsRoot40);
    final VcsRootInstance vcsRootInstance30 = buildConf3.getVcsRootInstanceForParent(vcsRoot30);
    assert vcsRootInstance30 != null;
    final VcsRootInstance vcsRootInstance40 = buildConf3.getVcsRootInstanceForParent(vcsRoot40);
    assert vcsRootInstance40 != null;
    collectChangesPolicy.setCurrentState(vcsRootInstance30, createVersionState("refs/heads/master", map("refs/heads/master", "a1", "refs/heads/branch1", "a2", "refs/heads/branch2", "a3")));
    collectChangesPolicy.setCurrentState(vcsRootInstance40, createVersionState("refs/heads/branch1", map("refs/heads/master", "b1", "refs/heads/branch1", "b2", "refs/heads/branch2", // different default branch
    "b3")));
    setBranchSpec(vcsRootInstance30, "+:refs/heads/(*)");
    setBranchSpec(vcsRootInstance40, "+:refs/heads/(*)");
    myFixture.getVcsModificationChecker().checkForModifications(buildConf3.getVcsRootInstances(), OperationRequestor.UNKNOWN);
    final BuildPromotion build230 = build().in(buildConf3).finish().getBuildPromotion();
    final BuildPromotion build240 = build().in(buildConf3).withDefaultBranch().finish().getBuildPromotion();
    // not existing branch
    final BuildPromotion build250 = build().in(buildConf3).withBranch("branch").finish().getBuildPromotion();
    final BuildPromotion build260 = build().in(buildConf3).withBranch("branch1").finish().getBuildPromotion();
    // not existing branch
    final BuildPromotion build270 = build().in(buildConf3).withBranch("master").finish().getBuildPromotion();
    checkBuilds("buildType:(id:" + buildConf3.getExternalId() + ")", build240, build230);
    checkBuilds("buildType:(id:" + buildConf3.getExternalId() + "),branch:(default:any)", build270, build260, build250, build240, build230);
    checkBuilds("buildType:(id:" + buildConf3.getExternalId() + "),branch:(name:<default>)", build240, build230);
    checkBuilds("buildType:(id:" + buildConf3.getExternalId() + "),branch:(name:<Default>)", build240, build230);
    checkBuilds("buildType:(id:" + buildConf3.getExternalId() + "),branch:(name:(value:<default>))", build240, build230);
    // case sensitive in this syntax
    checkBuilds("buildType:(id:" + buildConf3.getExternalId() + "),branch:(name:(value:<Default>))");
    checkBuilds("buildType:(id:" + buildConf3.getExternalId() + "),branch:(name:master)", build270);
    checkBuilds("buildType:(id:" + buildConf3.getExternalId() + "),branch:(name:Master)", build270);
    checkBuilds("buildType:(id:" + buildConf3.getExternalId() + "),branch:(name:master,default:true)");
    checkBuilds("buildType:(id:" + buildConf3.getExternalId() + "),branch:(name:master,default:false)", build270);
    checkBuilds("buildType:(id:" + buildConf3.getExternalId() + "),branch:(name:(value:master))", build270);
    checkBuilds("buildType:(id:" + buildConf3.getExternalId() + "),branch:(name:(value:Master))");
    checkBuilds("buildType:(id:" + buildConf3.getExternalId() + "),branch:(name:branch)", build250);
    checkBuilds("buildType:(id:" + buildConf3.getExternalId() + "),branch:(name:branch1)", build260);
}
Also used : SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) VcsRootInstance(jetbrains.buildServer.vcs.VcsRootInstance) Test(org.testng.annotations.Test)

Example 4 with SVcsRoot

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

the class ProjectRequestTest method setCurrentBranches.

private void setCurrentBranches(final BuildTypeEx bt, final BuildFinderTestBase.MockCollectRepositoryChangesPolicy collectChangesPolicy, final String defaultBranchName, final Map<String, String> state) {
    if (bt.getVcsRoots().isEmpty()) {
        final SVcsRoot vcsRoot = bt.getProject().createVcsRoot("vcs", "extId_for_" + bt.getId(), "name_for_" + bt.getId());
        bt.addVcsRoot(vcsRoot);
    }
    final VcsRootInstance vcsRootInstance = bt.getVcsRootInstances().get(0);
    collectChangesPolicy.setCurrentState(vcsRootInstance, createVersionState(defaultBranchName, state));
    setBranchSpec(vcsRootInstance, "+:*");
    myFixture.getVcsModificationChecker().checkForModifications(bt.getVcsRootInstances(), OperationRequestor.UNKNOWN);
}
Also used : SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) VcsRootInstance(jetbrains.buildServer.vcs.VcsRootInstance)

Example 5 with SVcsRoot

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

the class VcsRootRequest method deleteParameter.

@DELETE
@Path("/{vcsRootLocator}/properties/{name}")
@ApiOperation(value = "Delete a property of the matching VCS root.", nickname = "deleteVcsRootProperty")
public void deleteParameter(@ApiParam(format = LocatorName.VCS_ROOT) @PathParam("vcsRootLocator") String vcsRootLocator, @PathParam("name") String parameterName) {
    final SVcsRoot vcsRoot = myVcsRootFinder.getItem(vcsRootLocator);
    BuildTypeUtil.deleteParameter(parameterName, VcsRoot.getEntityWithParameters(vcsRoot));
    vcsRoot.schedulePersisting("Property with name " + parameterName + " deleted from VCS root");
}
Also used : SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) ApiOperation(io.swagger.annotations.ApiOperation)

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