Search in sources :

Example 1 with SVcsModificationOrChangeDescriptor

use of jetbrains.buildServer.server.rest.data.change.SVcsModificationOrChangeDescriptor in project teamcity-rest by JetBrains.

the class ChangeFinder method getPrefilteredItems.

@NotNull
@Override
public ItemHolder<SVcsModificationOrChangeDescriptor> getPrefilteredItems(@NotNull final Locator locator) {
    final String internalVersion = locator.getSingleDimensionValue(INTERNAL_VERSION);
    if (internalVersion != null) {
        return wrapModifications(((VcsModificationHistoryEx) myVcsModificationHistory).findModificationsByVersion(internalVersion));
    }
    ValueCondition displayVersionCondition = ParameterCondition.createValueCondition(locator.lookupSingleDimensionValue(VERSION));
    final String displayVersion = displayVersionCondition != null ? displayVersionCondition.getConstantValueIfSimpleEqualsCondition() : null;
    if (displayVersion != null) {
        locator.markUsed(Collections.singleton(VERSION));
        return wrapModifications(((VcsModificationHistoryEx) myVcsModificationHistory).findModificationsByDisplayVersion(displayVersion));
    }
    Boolean personal = locator.lookupSingleDimensionValueAsBoolean(PERSONAL);
    if (personal != null && personal) {
        if (locator.lookupSingleDimensionValue(BUILD) == null && locator.lookupSingleDimensionValue(USER) == null) {
            throw new BadRequestException("Filtering personal changes is supported only when '" + DIMENSION_ID + "', '" + USER + "' or '" + BUILD + "' dimensions are specified");
        }
    }
    final String buildLocator = locator.getSingleDimensionValue(BUILD);
    if (buildLocator != null) {
        BuildPromotion buildFromBuildFinder;
        try {
            buildFromBuildFinder = myBuildPromotionFinder.getItem(buildLocator);
        } catch (Exception e) {
            if (!TeamCityProperties.getBoolean("rest.request.changes.legacySingleBuildSearch")) {
                throw e;
            }
            // support for finished builds
            // todo: use buildPromotionFinder here (ensure it also supports finished builds)
            // THIS SHOULD NEVER HAPPEN
            buildFromBuildFinder = myBuildFinder.getBuildPromotion(null, buildLocator);
        }
        return wrapDescriptors(getBuildChangeDescriptors(buildFromBuildFinder, locator));
    }
    // pre-9.0 compatibility
    final Long promotionLocator = locator.getSingleDimensionValueAsLong(PROMOTION);
    if (promotionLocator != null) {
        // noinspection ConstantConditions
        return wrapDescriptors(getBuildChangeDescriptors(BuildFinder.getBuildPromotion(promotionLocator, myServiceLocator.findSingletonService(BuildPromotionManager.class)), locator));
    }
    final String parentChangeLocator = locator.getSingleDimensionValue(CHILD_CHANGE);
    if (parentChangeLocator != null) {
        final SVcsModification parentChange = getItem(parentChangeLocator).getSVcsModification();
        return wrapModifications(getChangesWhichHasChild(parentChange, locator.getSingleDimensionValueAsLong(DIMENSION_LOOKUP_LIMIT)));
    // todo: return iterator instead of processing lookup limit here
    }
    final String childChangeLocator = locator.getSingleDimensionValue(PARENT_CHANGE);
    if (childChangeLocator != null) {
        final SVcsModification parentChange = getItem(childChangeLocator).getSVcsModification();
        return wrapModifications(getChangesWhichHasParent(parentChange, locator.getSingleDimensionValueAsLong(DIMENSION_LOOKUP_LIMIT)));
    }
    final String graphLocator = locator.getSingleDimensionValue(DAG_TRAVERSE);
    if (graphLocator != null) {
        final GraphFinder<SVcsModification> graphFinder = new GraphFinder<SVcsModification>(locatorText -> getItems(locatorText).myEntries.stream().map(SVcsModificationOrChangeDescriptor::getSVcsModification).collect(Collectors.toList()), new ChangesGraphTraverser());
        graphFinder.setDefaultLookupLimit(1000L);
        return wrapModifications(graphFinder.getItems(graphLocator).myEntries);
    }
    final String userLocator = locator.getSingleDimensionValue(USER);
    if (userLocator != null) {
        final SUser user = myUserFinder.getItem(userLocator);
        return wrapModifications(myServiceLocator.getSingletonService(UserChangesFacade.class).getAllVcsModifications(user));
    }
    final String username = locator.getSingleDimensionValue(USERNAME);
    if (username != null) {
        return wrapModifications(myServiceLocator.getSingletonService(VcsModificationsStorage.class).findModificationsByUsername(username));
    }
    Long sinceChangeId = null;
    final String sinceChangeLocator = locator.getSingleDimensionValue(SINCE_CHANGE);
    if (sinceChangeLocator != null) {
        sinceChangeId = getChangeIdBySinceChangeLocator(sinceChangeLocator);
    }
    final String vcsRootInstanceLocator = locator.getSingleDimensionValue(VCS_ROOT_INSTANCE);
    if (vcsRootInstanceLocator != null) {
        final VcsRootInstance vcsRootInstance = myVcsRootInstanceFinder.getItem(vcsRootInstanceLocator);
        if (sinceChangeId != null) {
            // todo: use lookupLimit here or otherwise limit processing
            return wrapModifications(myVcsModificationHistory.getModificationsInRange(vcsRootInstance, sinceChangeId, null));
        } else {
            // todo: highly inefficient!
            return wrapModifications(myVcsModificationHistory.getAllModifications(vcsRootInstance));
        }
    }
    SBuildType buildType = null;
    // todo: support multiple buildTypes here
    final String buildTypeLocator = locator.getSingleDimensionValue(BUILD_TYPE);
    if (buildTypeLocator != null) {
        buildType = myBuildTypeFinder.getBuildType(null, buildTypeLocator, false);
    }
    Boolean pending = locator.getSingleDimensionValueAsBoolean(PENDING);
    if (pending != null) {
        if (pending) {
            Stream<SVcsModificationOrChangeDescriptor> changes = getPendingChanges(buildType, locator);
            return processor -> changes.allMatch(processor::processItem);
        } else {
            locator.markUnused(PENDING);
        }
    }
    if (buildType != null) {
        Stream<SVcsModificationOrChangeDescriptor> changes = getBranchChanges(buildType, SelectPrevBuildPolicy.SINCE_NULL_BUILD, locator);
        return processor -> changes.allMatch(processor::processItem);
    }
    if (locator.lookupSingleDimensionValue(BRANCH) != null) {
        throw new BadRequestException("Filtering changes by branch is only supported when buildType is specified.");
    }
    final String projectLocator = locator.getSingleDimensionValue(PROJECT);
    if (projectLocator != null) {
        return wrapModifications(getProjectChanges(myProjectFinder.getItem(projectLocator), sinceChangeId));
    }
    if (sinceChangeId != null) {
        // todo: use lookupLimit here or otherwise limit processing
        return wrapModifications(myVcsModificationHistory.getModificationsInRange(null, sinceChangeId, null));
    }
    // ItemHolder
    return wrapModifications(((VcsModificationHistoryEx) myVcsModificationHistory)::processModifications);
}
Also used : LocatorProcessException(jetbrains.buildServer.server.rest.errors.LocatorProcessException) WrappingItemHolder(jetbrains.buildServer.server.rest.data.util.WrappingItemHolder) java.util(java.util) SVcsModificationOrChangeDescriptor(jetbrains.buildServer.server.rest.data.change.SVcsModificationOrChangeDescriptor) LocatorName(jetbrains.buildServer.server.rest.swagger.constants.LocatorName) DuplicateChecker(jetbrains.buildServer.server.rest.data.util.DuplicateChecker) LocatorResource(jetbrains.buildServer.server.rest.swagger.annotations.LocatorResource) AuthorityHolder(jetbrains.buildServer.serverSide.auth.AuthorityHolder) UnwrappingFilter(jetbrains.buildServer.server.rest.data.util.UnwrappingFilter) Function(java.util.function.Function) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) LocatorDimensionDataType(jetbrains.buildServer.server.rest.swagger.constants.LocatorDimensionDataType) BuildTypeDescriptor(jetbrains.buildServer.BuildTypeDescriptor) UserChangesFacade(jetbrains.buildServer.serverSide.userChanges.UserChangesFacade) KeyDuplicateChecker(jetbrains.buildServer.server.rest.data.util.KeyDuplicateChecker) StringUtil(jetbrains.buildServer.util.StringUtil) SecurityContext(jetbrains.buildServer.serverSide.auth.SecurityContext) CollectionsUtil(jetbrains.buildServer.util.CollectionsUtil) PagerData(jetbrains.buildServer.server.rest.model.PagerData) Constants(jetbrains.buildServer.server.rest.request.Constants) ServiceLocator(jetbrains.buildServer.ServiceLocator) jetbrains.buildServer.serverSide(jetbrains.buildServer.serverSide) RemoteBuildTypeIdUtil(jetbrains.buildServer.serverSide.impl.RemoteBuildTypeIdUtil) BFSVisitorAdapter(jetbrains.buildServer.util.graph.BFSVisitorAdapter) Predicate(java.util.function.Predicate) VcsModificationEx(jetbrains.buildServer.vcs.impl.VcsModificationEx) DAGIterator(jetbrains.buildServer.util.graph.DAGIterator) jetbrains.buildServer.vcs(jetbrains.buildServer.vcs) Collectors(java.util.stream.Collectors) RemoteBuildType(jetbrains.buildServer.serverSide.impl.RemoteBuildType) Nullable(org.jetbrains.annotations.Nullable) DAG(jetbrains.buildServer.util.graph.DAG) Stream(java.util.stream.Stream) LocatorDimension(jetbrains.buildServer.server.rest.swagger.annotations.LocatorDimension) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) AuthUtil(jetbrains.buildServer.serverSide.auth.AuthUtil) NotNull(org.jetbrains.annotations.NotNull) SUser(jetbrains.buildServer.users.SUser) SUser(jetbrains.buildServer.users.SUser) SVcsModificationOrChangeDescriptor(jetbrains.buildServer.server.rest.data.change.SVcsModificationOrChangeDescriptor) LocatorProcessException(jetbrains.buildServer.server.rest.errors.LocatorProcessException) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with SVcsModificationOrChangeDescriptor

use of jetbrains.buildServer.server.rest.data.change.SVcsModificationOrChangeDescriptor in project teamcity-rest by JetBrains.

the class ChangeFinderTest method check.

private void check(String locator, SVcsModification... modifications) {
    SVcsModificationOrChangeDescriptor[] wrapped = new SVcsModificationOrChangeDescriptor[modifications.length];
    for (int i = 0; i < modifications.length; i++) {
        wrapped[i] = new SVcsModificationOrChangeDescriptor(modifications[i]);
    }
    check(locator, (m1, m2) -> m1.getSVcsModification().equals(m2.getSVcsModification()), wrapped);
}
Also used : SVcsModificationOrChangeDescriptor(jetbrains.buildServer.server.rest.data.change.SVcsModificationOrChangeDescriptor)

Example 3 with SVcsModificationOrChangeDescriptor

use of jetbrains.buildServer.server.rest.data.change.SVcsModificationOrChangeDescriptor in project teamcity-rest by JetBrains.

the class ChangeFinderTest method testDuplicate.

@Test
public void testDuplicate() {
    final BuildTypeImpl buildConf1 = registerBuildType("buildConf1", "project");
    final BuildTypeImpl buildConf2 = registerBuildType("buildConf2", "project");
    MockVcsSupport vcs = new MockVcsSupport("vcs");
    myFixture.getVcsManager().registerVcsSupport(vcs);
    SVcsRootEx parentRoot1 = myFixture.addVcsRoot(vcs.getName(), "", buildConf1);
    SVcsRootEx parentRoot2 = myFixture.addVcsRoot(vcs.getName(), "", buildConf2);
    VcsRootInstance root1 = buildConf1.getVcsRootInstanceForParent(parentRoot1);
    VcsRootInstance root2 = buildConf2.getVcsRootInstanceForParent(parentRoot2);
    assert root1 != null && root2 != null;
    final String version = "12345";
    myFixture.addModification(modification().in(root1).by("user1").version(version));
    myFixture.addModification(modification().in(root2).by("user1").version(version));
    List<SVcsModificationOrChangeDescriptor> result = myChangeFinder.getItems("unique:true").myEntries;
    assertEquals(1, result.size());
    List<SVcsModificationOrChangeDescriptor> resultWithDuplicate = myChangeFinder.getItems("count:10").myEntries;
    assertEquals(2, resultWithDuplicate.size());
}
Also used : MockVcsSupport(jetbrains.buildServer.serverSide.impl.MockVcsSupport) SVcsModificationOrChangeDescriptor(jetbrains.buildServer.server.rest.data.change.SVcsModificationOrChangeDescriptor) BuildTypeImpl(jetbrains.buildServer.serverSide.impl.BuildTypeImpl) Test(org.testng.annotations.Test)

Example 4 with SVcsModificationOrChangeDescriptor

use of jetbrains.buildServer.server.rest.data.change.SVcsModificationOrChangeDescriptor in project teamcity-rest by JetBrains.

the class ChangeRequest method getUniqueCommiters.

/**
 * Experimental support only!
 * @since 2021.1.1
 */
@GET
@Path("/{changeLocator}/commiters")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Get unique commiters of the matching changes.", nickname = "getUniqueCommiters", hidden = true)
public Commiters getUniqueCommiters(@ApiParam(format = LocatorName.CHANGE) @PathParam("changeLocator") String changeLocator, @QueryParam("fields") String fields) {
    Locator patchedChangeLocator = Locator.createPotentiallyEmptyLocator(changeLocator);
    if (!patchedChangeLocator.isAnyPresent(PagerData.COUNT)) {
        String lookupLimit = TeamCityProperties.getProperty("rest.request.changes.committersLookupLimit", DEFAULT_CHANGES_LOOKUP_LIMIT_FOR_COMMITERS);
        patchedChangeLocator.setDimension(PagerData.COUNT, lookupLimit);
    }
    PagedSearchResult<SVcsModificationOrChangeDescriptor> changes = myChangeFinder.getItems(patchedChangeLocator.getStringRepresentation());
    List<CommiterData> commiters = ChangeUtil.getUniqueCommiters(changes.myEntries.stream().map(modOrDesc -> modOrDesc.getSVcsModification()));
    return new Commiters(commiters, new Fields(fields), myBeanContext);
}
Also used : CommiterData(jetbrains.buildServer.server.rest.data.change.CommiterData) Fields(jetbrains.buildServer.server.rest.model.Fields) Items(jetbrains.buildServer.server.rest.model.Items) BuildTypeFinder(jetbrains.buildServer.server.rest.data.BuildTypeFinder) BuildPromotion(jetbrains.buildServer.serverSide.BuildPromotion) SVcsModificationOrChangeDescriptor(jetbrains.buildServer.server.rest.data.change.SVcsModificationOrChangeDescriptor) LocatorName(jetbrains.buildServer.server.rest.swagger.constants.LocatorName) Issues(jetbrains.buildServer.server.rest.model.issue.Issues) ApiParam(io.swagger.annotations.ApiParam) PagedSearchResult(jetbrains.buildServer.server.rest.data.PagedSearchResult) ArrayList(java.util.ArrayList) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) ApiOperation(io.swagger.annotations.ApiOperation) ChangeStatusProvider(jetbrains.buildServer.vcs.ChangeStatusProvider) HttpServletRequest(javax.servlet.http.HttpServletRequest) CommiterData(jetbrains.buildServer.server.rest.data.change.CommiterData) TestScopeTreeCollector(jetbrains.buildServer.server.rest.data.problem.scope.TestScopeTreeCollector) ChangeFinder(jetbrains.buildServer.server.rest.data.ChangeFinder) UriBuilder(javax.ws.rs.core.UriBuilder) Api(io.swagger.annotations.Api) ProblemOccurrencesTree(jetbrains.buildServer.server.rest.model.problem.scope.ProblemOccurrencesTree) SBuildType(jetbrains.buildServer.serverSide.SBuildType) ChangeStatus(jetbrains.buildServer.vcs.ChangeStatus) PagerData(jetbrains.buildServer.server.rest.model.PagerData) TestScopeTree(jetbrains.buildServer.server.rest.model.problem.scope.TestScopeTree) TeamCityProperties(jetbrains.buildServer.serverSide.TeamCityProperties) Context(javax.ws.rs.core.Context) ServiceLocator(jetbrains.buildServer.ServiceLocator) ProblemOccurrencesTreeCollector(jetbrains.buildServer.server.rest.data.problem.scope.ProblemOccurrencesTreeCollector) StringUtil(com.intellij.openapi.util.text.StringUtil) Builds(jetbrains.buildServer.server.rest.model.build.Builds) ApiUrlBuilder(jetbrains.buildServer.server.rest.ApiUrlBuilder) Locator(jetbrains.buildServer.server.rest.data.Locator) Collectors(java.util.stream.Collectors) BeanFactory(jetbrains.buildServer.server.rest.util.BeanFactory) ChangeUtil(jetbrains.buildServer.server.rest.data.change.ChangeUtil) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Stream(java.util.stream.Stream) javax.ws.rs(javax.ws.rs) jetbrains.buildServer.server.rest.model.change(jetbrains.buildServer.server.rest.model.change) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) BuildTypes(jetbrains.buildServer.server.rest.model.buildType.BuildTypes) Entries(jetbrains.buildServer.server.rest.model.Entries) UriInfo(javax.ws.rs.core.UriInfo) BeanContext(jetbrains.buildServer.server.rest.util.BeanContext) NotNull(org.jetbrains.annotations.NotNull) SVcsModification(jetbrains.buildServer.vcs.SVcsModification) ServiceLocator(jetbrains.buildServer.ServiceLocator) Locator(jetbrains.buildServer.server.rest.data.Locator) Fields(jetbrains.buildServer.server.rest.model.Fields) SVcsModificationOrChangeDescriptor(jetbrains.buildServer.server.rest.data.change.SVcsModificationOrChangeDescriptor) ApiOperation(io.swagger.annotations.ApiOperation)

Example 5 with SVcsModificationOrChangeDescriptor

use of jetbrains.buildServer.server.rest.data.change.SVcsModificationOrChangeDescriptor in project teamcity-rest by JetBrains.

the class ChangeFinderTest method testChangesByBuildTypeFromDependenciesHaveDescriptor.

@Test
@TestFor(issues = "TW-72448")
public void testChangesByBuildTypeFromDependenciesHaveDescriptor() {
    final BuildTypeImpl buildConf1 = registerBuildType("buildConf1", "project");
    final BuildTypeImpl buildConf2 = registerBuildType("buildConf2", "project");
    createDependencyChain(buildConf2, buildConf1);
    MockVcsSupport vcs = new MockVcsSupport("vcs");
    vcs.setDAGBased(true);
    myFixture.getVcsManager().registerVcsSupport(vcs);
    SVcsRootEx parentRoot1 = myFixture.addVcsRoot(vcs.getName(), "", buildConf1);
    SVcsRootEx parentRoot2 = myFixture.addVcsRoot(vcs.getName(), "", buildConf2);
    VcsRootInstance root1 = buildConf1.getVcsRootInstanceForParent(parentRoot1);
    VcsRootInstance root2 = buildConf2.getVcsRootInstanceForParent(parentRoot2);
    assert root1 != null;
    assert root2 != null;
    setBranchSpec(root1, "+:*");
    setBranchSpec(root2, "+:*");
    final BuildFinderTestBase.MockCollectRepositoryChangesPolicy changesPolicy = new BuildFinderTestBase.MockCollectRepositoryChangesPolicy();
    vcs.setCollectChangesPolicy(changesPolicy);
    myFixture.addModification(modification().in(root1).version("1").parentVersions("0"));
    myFixture.addModification(modification().in(root2).version("2").parentVersions("0"));
    List<SVcsModificationOrChangeDescriptor> items = getFinder().getItems("buildType:buildConf2,changesFromDependencies:true,vcsRoot:(id:" + root1.getExternalId() + ")").myEntries;
    assertEquals("There is exactly one pending change coming from dependency.", 1, items.size());
    ChangeDescriptor descriptor = items.get(0).getChangeDescriptor();
    assertNotNull("Depency change descriptor must be present when looking for changes using build type.", descriptor);
    assertEquals(ChangeDescriptorConstants.SNAPSHOT_DEPENDENCY_VCS_CHANGE, descriptor.getType());
    SVcsModification modification = items.get(0).getSVcsModification();
    assertEquals("1", modification.getDisplayVersion());
}
Also used : MockVcsSupport(jetbrains.buildServer.serverSide.impl.MockVcsSupport) SVcsModificationOrChangeDescriptor(jetbrains.buildServer.server.rest.data.change.SVcsModificationOrChangeDescriptor) BuildTypeImpl(jetbrains.buildServer.serverSide.impl.BuildTypeImpl) SVcsModificationOrChangeDescriptor(jetbrains.buildServer.server.rest.data.change.SVcsModificationOrChangeDescriptor) Test(org.testng.annotations.Test) TestFor(jetbrains.buildServer.util.TestFor)

Aggregations

SVcsModificationOrChangeDescriptor (jetbrains.buildServer.server.rest.data.change.SVcsModificationOrChangeDescriptor)8 ServiceLocator (jetbrains.buildServer.ServiceLocator)4 PagerData (jetbrains.buildServer.server.rest.model.PagerData)4 Collectors (java.util.stream.Collectors)3 Stream (java.util.stream.Stream)3 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)3 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)3 LocatorName (jetbrains.buildServer.server.rest.swagger.constants.LocatorName)3 ApiOperation (io.swagger.annotations.ApiOperation)2 java.util (java.util)2 Function (java.util.function.Function)2 Predicate (java.util.function.Predicate)2 UriBuilder (javax.ws.rs.core.UriBuilder)2 BuildTypeDescriptor (jetbrains.buildServer.BuildTypeDescriptor)2 Locator (jetbrains.buildServer.server.rest.data.Locator)2 DuplicateChecker (jetbrains.buildServer.server.rest.data.util.DuplicateChecker)2 KeyDuplicateChecker (jetbrains.buildServer.server.rest.data.util.KeyDuplicateChecker)2 UnwrappingFilter (jetbrains.buildServer.server.rest.data.util.UnwrappingFilter)2 WrappingItemHolder (jetbrains.buildServer.server.rest.data.util.WrappingItemHolder)2 LocatorProcessException (jetbrains.buildServer.server.rest.errors.LocatorProcessException)2