Search in sources :

Example 11 with VcsRootInstance

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());
}
Also used : SVcsModification(jetbrains.buildServer.vcs.SVcsModification) RunningBuildEx(jetbrains.buildServer.serverSide.RunningBuildEx) ChangeStatus(jetbrains.buildServer.server.rest.model.change.ChangeStatus) BuildTypeImpl(jetbrains.buildServer.serverSide.impl.BuildTypeImpl) VcsRootInstance(jetbrains.buildServer.vcs.VcsRootInstance)

Example 12 with VcsRootInstance

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;
}
Also used : SVcsRootEx(jetbrains.buildServer.vcs.SVcsRootEx) BuildFinderTestBase(jetbrains.buildServer.server.rest.data.BuildFinderTestBase) VcsRootInstance(jetbrains.buildServer.vcs.VcsRootInstance)

Example 13 with VcsRootInstance

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);
}
Also used : SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) VcsRootInstance(jetbrains.buildServer.vcs.VcsRootInstance)

Example 14 with VcsRootInstance

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
}
Also used : SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) BuildTypeRequest(jetbrains.buildServer.server.rest.request.BuildTypeRequest) Branches(jetbrains.buildServer.server.rest.model.build.Branches) MockVcsSupport(jetbrains.buildServer.serverSide.impl.MockVcsSupport) BuildFinderTestBase(jetbrains.buildServer.server.rest.data.BuildFinderTestBase) VcsRootInstance(jetbrains.buildServer.vcs.VcsRootInstance) Test(org.testng.annotations.Test) ProjectRequestTest(jetbrains.buildServer.server.rest.request.ProjectRequestTest) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 15 with VcsRootInstance

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);
}
Also used : BuildProblem(jetbrains.buildServer.serverSide.problems.BuildProblem) Loggers(jetbrains.buildServer.log.Loggers) EncryptUtil(jetbrains.buildServer.serverSide.crypt.EncryptUtil) TCStreamUtil(jetbrains.buildServer.util.TCStreamUtil) ApiParam(io.swagger.annotations.ApiParam) jetbrains.buildServer.server.rest.errors(jetbrains.buildServer.server.rest.errors) jetbrains.buildServer.server.rest.data(jetbrains.buildServer.server.rest.data) HttpDownloadProcessor(jetbrains.buildServer.controllers.HttpDownloadProcessor) TimeService(jetbrains.buildServer.util.TimeService) jetbrains.buildServer.serverSide.auth(jetbrains.buildServer.serverSide.auth) ApiOperation(io.swagger.annotations.ApiOperation) FileUtil(jetbrains.buildServer.util.FileUtil) jetbrains.buildServer.server.rest.model.build(jetbrains.buildServer.server.rest.model.build) VcsRootInstanceEntry(jetbrains.buildServer.vcs.VcsRootInstanceEntry) TestOccurrenceFinder(jetbrains.buildServer.server.rest.data.problem.TestOccurrenceFinder) ChangeBuildStatusProcessor(jetbrains.buildServer.controllers.actions.ChangeBuildStatusProcessor) StringUtil(jetbrains.buildServer.util.StringUtil) LogUtil(jetbrains.buildServer.serverSide.impl.LogUtil) Logger(com.intellij.openapi.diagnostic.Logger) RunningBuildState(jetbrains.buildServer.serverSide.impl.RunningBuildState) BaseBuild(jetbrains.buildServer.serverSide.impl.BaseBuild) UserModel(jetbrains.buildServer.users.UserModel) jetbrains.buildServer.serverSide(jetbrains.buildServer.serverSide) ServerProvidedProperties(jetbrains.buildServer.agent.ServerProvidedProperties) ProcessingResult(jetbrains.buildServer.parameters.ProcessingResult) TagFinder(jetbrains.buildServer.server.rest.data.build.TagFinder) SessionUser(jetbrains.buildServer.web.util.SessionUser) Collectors(java.util.stream.Collectors) DefaultMessagesInfo(jetbrains.buildServer.messages.DefaultMessagesInfo) ProblemOccurrenceFinder(jetbrains.buildServer.server.rest.data.problem.ProblemOccurrenceFinder) Nullable(org.jetbrains.annotations.Nullable) TestOccurrences(jetbrains.buildServer.server.rest.model.problem.TestOccurrences) javax.ws.rs(javax.ws.rs) VcsException(jetbrains.buildServer.vcs.VcsException) Pattern(java.util.regex.Pattern) BeanContext(jetbrains.buildServer.server.rest.util.BeanContext) NotNull(org.jetbrains.annotations.NotNull) VcsManager(jetbrains.buildServer.vcs.VcsManager) WebUtil(jetbrains.buildServer.web.util.WebUtil) java.util(java.util) LocatorName(jetbrains.buildServer.server.rest.swagger.constants.LocatorName) TriggeredBy(jetbrains.buildServer.serverSide.TriggeredBy) Status(jetbrains.buildServer.messages.Status) IssueUsages(jetbrains.buildServer.server.rest.model.issue.IssueUsages) jetbrains.buildServer.server.rest.model(jetbrains.buildServer.server.rest.model) Element(jetbrains.buildServer.util.browser.Element) HttpServletRequest(javax.servlet.http.HttpServletRequest) ParametersPersistableEntity(jetbrains.buildServer.server.rest.data.parameters.ParametersPersistableEntity) BuildProblemData(jetbrains.buildServer.BuildProblemData) TagsManager(jetbrains.buildServer.tags.TagsManager) Api(io.swagger.annotations.Api) SecurityContext(jetbrains.buildServer.serverSide.auth.SecurityContext) VcsRootInstance(jetbrains.buildServer.vcs.VcsRootInstance) ProblemOccurrences(jetbrains.buildServer.server.rest.model.problem.ProblemOccurrences) BuildChanges(jetbrains.buildServer.server.rest.model.change.BuildChanges) Properties(jetbrains.buildServer.server.rest.model.Properties) BuildTypeUtil(jetbrains.buildServer.server.rest.model.buildType.BuildTypeUtil) BuildAgentMessagesQueue(jetbrains.buildServer.serverSide.impl.BuildAgentMessagesQueue) HttpServletResponse(javax.servlet.http.HttpServletResponse) javax.ws.rs.core(javax.ws.rs.core) ServerAuthUtil(jetbrains.buildServer.serverSide.impl.auth.ServerAuthUtil) Consumer(java.util.function.Consumer) ProblemOccurrence(jetbrains.buildServer.server.rest.model.problem.ProblemOccurrence) java.io(java.io) VcsLabelManager(jetbrains.buildServer.serverSide.vcs.VcsLabelManager) FileSecurityUtil(jetbrains.buildServer.controllers.FileSecurityUtil) ActionErrors(jetbrains.buildServer.controllers.ActionErrors) WebAuthUtil(jetbrains.buildServer.web.util.WebAuthUtil) ServletContext(javax.servlet.ServletContext) QueuedBuild(jetbrains.buildServer.QueuedBuild) SUser(jetbrains.buildServer.users.SUser) ReferencesResolverUtil(jetbrains.buildServer.parameters.ReferencesResolverUtil) AggregatedBuildArtifactsElementBuilder(jetbrains.buildServer.server.rest.util.AggregatedBuildArtifactsElementBuilder) User(jetbrains.buildServer.users.User) VcsLabelManager(jetbrains.buildServer.serverSide.vcs.VcsLabelManager) VcsRootInstanceEntry(jetbrains.buildServer.vcs.VcsRootInstanceEntry) VcsRootInstance(jetbrains.buildServer.vcs.VcsRootInstance) VcsException(jetbrains.buildServer.vcs.VcsException) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

VcsRootInstance (jetbrains.buildServer.vcs.VcsRootInstance)31 Test (org.testng.annotations.Test)15 SVcsModification (jetbrains.buildServer.vcs.SVcsModification)14 ChangeStatus (jetbrains.buildServer.server.rest.model.change.ChangeStatus)12 BuildTypeImpl (jetbrains.buildServer.serverSide.impl.BuildTypeImpl)12 SVcsRoot (jetbrains.buildServer.vcs.SVcsRoot)9 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)6 RunningBuildEx (jetbrains.buildServer.serverSide.RunningBuildEx)5 BuildFinderTestBase (jetbrains.buildServer.server.rest.data.BuildFinderTestBase)4 Nullable (org.jetbrains.annotations.Nullable)4 SUser (jetbrains.buildServer.users.SUser)3 NotNull (org.jetbrains.annotations.NotNull)3 Logger (com.intellij.openapi.diagnostic.Logger)2 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 ActionErrors (jetbrains.buildServer.controllers.ActionErrors)2 Branches (jetbrains.buildServer.server.rest.model.build.Branches)2 jetbrains.buildServer.serverSide (jetbrains.buildServer.serverSide)2