use of jetbrains.buildServer.vcs.VcsRootInstance in project teamcity-rest by JetBrains.
the class ChangeStatusTest method testSuccessfulRunning.
public void testSuccessfulRunning() {
final BuildTypeImpl buildConf = registerBuildType("buildConf1", "project");
VcsRootInstance root1 = prepareSingleVscRoot(buildConf);
SVcsModification m20 = myFixture.addModification(modification().in(root1).version("20").parentVersions("10"));
RunningBuildEx runningBuildEx = build().in(buildConf).onModifications(m20).run();
ChangeStatus status = new ChangeStatus(myFixture.getChangeStatusProvider().getMergedChangeStatus(m20), Fields.ALL_NESTED, getBeanContext(myFixture));
myFixture.finishBuild(runningBuildEx, false);
assertEquals(0, (int) status.getFinished());
assertEquals(1, (int) status.getRunning());
assertEquals(0, (int) status.getSuccessful());
assertEquals(1, (int) status.getRunningSuccessfuly());
}
use of jetbrains.buildServer.vcs.VcsRootInstance in project teamcity-rest by JetBrains.
the class ChangeStatusTest method prepareSingleVscRoot.
private VcsRootInstance prepareSingleVscRoot(@NotNull BuildTypeImpl buildConf) {
SVcsRootEx parentRoot1 = myFixture.addVcsRoot(myVcs.getName(), "", buildConf);
VcsRootInstance root1 = buildConf.getVcsRootInstanceForParent(parentRoot1);
assert root1 != null;
setBranchSpec(root1, "+:*");
final BuildFinderTestBase.MockCollectRepositoryChangesPolicy changesPolicy = new BuildFinderTestBase.MockCollectRepositoryChangesPolicy();
myVcs.setCollectChangesPolicy(changesPolicy);
return root1;
}
use of jetbrains.buildServer.vcs.VcsRootInstance 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);
}
use of jetbrains.buildServer.vcs.VcsRootInstance in project teamcity-rest by JetBrains.
the class BuildTypeTest method testBranches.
@Test
public void testBranches() throws ExecutionException, InterruptedException {
final BuildTypeEx bt = getRootProject().createProject("Project1", "Project test 1").createBuildType("testBT", "My test build type");
final BuildTypeRequest buildTypeRequest = new BuildTypeRequest();
buildTypeRequest.setInTests(myBuildTypeFinder, myBranchFinder, myBeanContext);
Branches branches = buildTypeRequest.serveBranches("id:testBT", null, null);
ProjectRequestTest.assertBranchesEquals(branches.branches, "<default>", true, null);
branches = buildTypeRequest.serveBranches("id:testBT", null, Fields.ALL_NESTED.getFieldsSpec());
ProjectRequestTest.assertBranchesEquals(branches.branches, "<default>", true, false);
MockVcsSupport vcs = vcsSupport().withName("vcs").dagBased(true).register();
BuildFinderTestBase.MockCollectRepositoryChangesPolicy collectChangesPolicy = new BuildFinderTestBase.MockCollectRepositoryChangesPolicy();
vcs.setCollectChangesPolicy(collectChangesPolicy);
final SVcsRoot vcsRoot = bt.getProject().createVcsRoot("vcs", "extId", "name");
bt.addVcsRoot(vcsRoot);
final VcsRootInstance vcsRootInstance = bt.getVcsRootInstances().get(0);
collectChangesPolicy.setCurrentState(vcsRootInstance, createVersionState("master", map("master", "1", "branch1", "2", "branch2", "3")));
setBranchSpec(vcsRootInstance, "+:*");
branches = buildTypeRequest.serveBranches("id:testBT", null, null);
// why default before checking for changes???
ProjectRequestTest.assertBranchesEquals(branches.branches, "<default>", true, null);
myFixture.getVcsModificationChecker().checkForModifications(bt.getVcsRootInstances(), OperationRequestor.UNKNOWN);
branches = buildTypeRequest.serveBranches("id:testBT", null, null);
ProjectRequestTest.assertBranchesEquals(branches.branches, "master", true, null);
branches = buildTypeRequest.serveBranches("id:testBT", "policy:ALL_BRANCHES", null);
ProjectRequestTest.assertBranchesEquals(branches.branches, "master", true, null, "branch1", null, null, "branch2", null, null);
assertNull(branches.branches.get(0).getInternalName());
branches = buildTypeRequest.serveBranches("id:testBT", "policy:ALL_BRANCHES", Fields.ALL_NESTED.getFieldsSpec());
assertEquals("<default>", branches.branches.get(0).getInternalName());
assertEquals("branch1", branches.branches.get(1).getInternalName());
assertEquals("branch2", branches.branches.get(2).getInternalName());
branches = buildTypeRequest.serveBranches("id:testBT", "policy:all_branches", null);
ProjectRequestTest.assertBranchesEquals(branches.branches, "master", true, null, "branch1", null, null, "branch2", null, null);
branches = buildTypeRequest.serveBranches("id:testBT", "default:true", null);
ProjectRequestTest.assertBranchesEquals(branches.branches, "master", true, null);
bt.addVcsRoot(bt.getProject().createVcsRoot("vcs", "extId2", "name2"));
final VcsRootInstance vcsRootInstance2 = bt.getVcsRootInstances().get(1);
collectChangesPolicy.setCurrentState(vcsRootInstance2, createVersionState("master2", map("master2", "1", "branch1", "2", "branch2", "3")));
setBranchSpec(vcsRootInstance2, "+:*");
myFixture.getVcsModificationChecker().checkForModifications(bt.getVcsRootInstances(), OperationRequestor.UNKNOWN);
branches = buildTypeRequest.serveBranches("id:testBT", "policy:ALL_BRANCHES", Fields.ALL_NESTED.getFieldsSpec());
ProjectRequestTest.assertBranchesEquals(branches.branches, "<default>", true, false, "branch1", false, false, "branch2", false, false);
assertEquals("<default>", branches.branches.get(0).getInternalName());
checkException(LocatorProcessException.class, new Runnable() {
public void run() {
buildTypeRequest.serveBranches("id:testBT", "changesFromDependencies:any", null);
}
}, "searching with wrong changesFromDependencies");
checkException(BadRequestException.class, new Runnable() {
public void run() {
buildTypeRequest.serveBranches("id:testBT", "policy:INVALID_POLICY", null);
}
}, "searching with wrong changesFromDependencies");
// can also add test for branches from builds
// can also add test for "changesFromDependencies:true" locator and several defaults in different branches
}
use of jetbrains.buildServer.vcs.VcsRootInstance in project teamcity-rest by JetBrains.
the class BuildRequest method setVcsLabel.
/**
* Adds a label to build VCS roots.
* @param buildLocator specifies build to label.
* @param vcsRootLocator optional, specifies a VCS root to put a label on. If not present, label will be applied to all VCS roots.
* @param fields specifies result representation
* @param labelValue text of the label.
* @return added labels.
*/
@POST
@Path("/{buildLocator}/vcsLabels")
@Consumes("text/plain")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Add a VCS label to the matching build.", nickname = "addBuildVcsLabel")
public VcsLabels setVcsLabel(@ApiParam(format = LocatorName.BUILD) @PathParam("buildLocator") String buildLocator, @ApiParam(format = LocatorName.VCS_ROOT_INSTANCE) @QueryParam("locator") String vcsRootLocator, @QueryParam("fields") String fields, String labelValue) {
if (StringUtil.isEmpty(labelValue)) {
throw new BadRequestException("Label can not empty.");
}
SBuild build = getBuild(myBuildFinder.getBuildPromotion(null, buildLocator));
if (build == null) {
throw new NotFoundException("Cannot find a build using locator: " + buildLocator);
}
VcsLabelManager labelManager = myBeanContext.getSingletonService(VcsLabelManager.class);
List<VcsRootInstance> roots;
if (vcsRootLocator == null) {
roots = build.getVcsRootEntries().stream().map(VcsRootInstanceEntry::getVcsRoot).collect(Collectors.toList());
} else {
VcsRootInstanceFinder rootInstanceFinder = myBeanContext.getSingletonService(VcsRootInstanceFinder.class);
roots = Collections.singletonList(rootInstanceFinder.getItem(vcsRootLocator));
}
try {
labelManager.setLabel(build, labelValue, roots);
} catch (VcsException e) {
LOG.warn("Couldn't set a vcs label.", e);
}
Fields returnFields = new Fields(fields);
return new VcsLabels(labelManager.getLabels(build).stream().filter(l -> l.getLabelText().equals(labelValue)).map(l -> new VcsLabel(l, returnFields, myBeanContext)).collect(Collectors.toList()), returnFields);
}
Aggregations