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);
}
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);
}
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());
}
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);
}
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());
}
Aggregations