Search in sources :

Example 1 with VcsLabelManager

use of jetbrains.buildServer.serverSide.vcs.VcsLabelManager 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)

Example 2 with VcsLabelManager

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

the class BuildRequest method getVcsLabels.

/**
 * Gets build labels.
 * @param buildLocator given build.
 * @param fields       specifies result representation
 * @return build labels.
 */
@GET
@Path("/{buildLocator}/vcsLabels")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Get VCS labels of the matching build.", nickname = "getBuildVcsLabels")
public VcsLabels getVcsLabels(@ApiParam(format = LocatorName.BUILD) @PathParam("buildLocator") String buildLocator, @QueryParam("fields") String fields) {
    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);
    Fields returnFields = new Fields(fields);
    return new VcsLabels(labelManager.getLabels(build).stream().map(l -> new VcsLabel(l, returnFields, myBeanContext)).collect(Collectors.toList()), returnFields);
}
Also used : VcsLabelManager(jetbrains.buildServer.serverSide.vcs.VcsLabelManager) ApiOperation(io.swagger.annotations.ApiOperation)

Example 3 with VcsLabelManager

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

the class Build method getVcsLabels.

@XmlElement
public List<VcsLabel> getVcsLabels() {
    boolean isIncluded = myFields.isIncluded("vcsLabels", false, true);
    return ValueWithDefault.decideDefault(isIncluded, () -> {
        if (myBuild == null) {
            return Collections.emptyList();
        }
        VcsLabelManager labelManager = myBeanContext.getSingletonService(VcsLabelManager.class);
        Fields labelFields = myFields.getNestedField("vcsLabels");
        return labelManager.getLabels(myBuild).stream().map(l -> new VcsLabel(l, labelFields, myBeanContext)).collect(Collectors.toList());
    });
}
Also used : MetadataStorageEx(jetbrains.buildServer.serverSide.metadata.impl.MetadataStorageEx) BuildProblem(jetbrains.buildServer.serverSide.problems.BuildProblem) Files(jetbrains.buildServer.server.rest.model.files.Files) VcsModificationHistory(jetbrains.buildServer.vcs.VcsModificationHistory) Agent(jetbrains.buildServer.server.rest.model.agent.Agent) AuthorityHolder(jetbrains.buildServer.serverSide.auth.AuthorityHolder) BuildDependency(jetbrains.buildServer.serverSide.dependency.BuildDependency) PasswordReplacer(jetbrains.buildServer.util.PasswordReplacer) BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) ActionTypesFilter(jetbrains.buildServer.serverSide.impl.audit.filters.ActionTypesFilter) jetbrains.buildServer.server.rest.data(jetbrains.buildServer.server.rest.data) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) BuildType(jetbrains.buildServer.server.rest.model.buildType.BuildType) BigDecimal(java.math.BigDecimal) OperationException(jetbrains.buildServer.server.rest.errors.OperationException) ActionType(jetbrains.buildServer.serverSide.audit.ActionType) TestOccurrenceFinder(jetbrains.buildServer.server.rest.data.problem.TestOccurrenceFinder) AccessDeniedException(jetbrains.buildServer.serverSide.auth.AccessDeniedException) RevisionsNotFoundException(jetbrains.buildServer.vcs.impl.RevisionsNotFoundException) SArtifactDependency(jetbrains.buildServer.serverSide.artifacts.SArtifactDependency) StringUtil(jetbrains.buildServer.util.StringUtil) LogUtil(jetbrains.buildServer.serverSide.impl.LogUtil) Logger(com.intellij.openapi.diagnostic.Logger) CollectionsUtil(jetbrains.buildServer.util.CollectionsUtil) ModelDescription(jetbrains.buildServer.server.rest.swagger.annotations.ModelDescription) AuditLogAction(jetbrains.buildServer.serverSide.audit.AuditLogAction) CanceledInfo(jetbrains.buildServer.serverSide.userChanges.CanceledInfo) SelectPrevBuildPolicy(jetbrains.buildServer.vcs.SelectPrevBuildPolicy) WaitReason(jetbrains.buildServer.serverSide.buildDistribution.WaitReason) AgentTypeFinder(jetbrains.buildServer.serverSide.agentTypes.AgentTypeFinder) AgentRestrictor(jetbrains.buildServer.AgentRestrictor) ServiceLocator(jetbrains.buildServer.ServiceLocator) BaseBuild(jetbrains.buildServer.serverSide.impl.BaseBuild) UserModel(jetbrains.buildServer.users.UserModel) jetbrains.buildServer.serverSide(jetbrains.buildServer.serverSide) Changes(jetbrains.buildServer.server.rest.model.change.Changes) BuildProblemImpl(jetbrains.buildServer.serverSide.impl.problems.BuildProblemImpl) TagFinder(jetbrains.buildServer.server.rest.data.build.TagFinder) Revisions(jetbrains.buildServer.server.rest.model.change.Revisions) Collectors(java.util.stream.Collectors) ChangesBean(jetbrains.buildServer.controllers.changes.ChangesBean) ProblemOccurrenceFinder(jetbrains.buildServer.server.rest.data.problem.ProblemOccurrenceFinder) Nullable(org.jetbrains.annotations.Nullable) TestOccurrences(jetbrains.buildServer.server.rest.model.problem.TestOccurrences) InvalidStateException(jetbrains.buildServer.server.rest.errors.InvalidStateException) BuildAgent(jetbrains.buildServer.BuildAgent) RevisionRule(jetbrains.buildServer.artifacts.RevisionRule) PasswordParametersFilterCore(jetbrains.buildServer.parameters.PasswordParametersFilterCore) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) AgentRestrictorType(jetbrains.buildServer.AgentRestrictorType) Branch(jetbrains.buildServer.serverSide.Branch) BuildChangeData(jetbrains.buildServer.server.rest.data.change.BuildChangeData) BeanContext(jetbrains.buildServer.server.rest.util.BeanContext) NotNull(org.jetbrains.annotations.NotNull) SVcsModification(jetbrains.buildServer.vcs.SVcsModification) ChangesPopupUtil(jetbrains.buildServer.controllers.changes.ChangesPopupUtil) java.util(java.util) SVcsModificationOrChangeDescriptor(jetbrains.buildServer.server.rest.data.change.SVcsModificationOrChangeDescriptor) User(jetbrains.buildServer.server.rest.model.user.User) Converter(jetbrains.buildServer.util.Converter) IssueUsages(jetbrains.buildServer.server.rest.model.issue.IssueUsages) Hex(org.apache.commons.codec.binary.Hex) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ParametersProvider(jetbrains.buildServer.parameters.ParametersProvider) jetbrains.buildServer.server.rest.model(jetbrains.buildServer.server.rest.model) Agents(jetbrains.buildServer.server.rest.model.agent.Agents) AgentPool(jetbrains.buildServer.serverSide.agentPools.AgentPool) Element(jetbrains.buildServer.util.browser.Element) PropEntitiesArtifactDep(jetbrains.buildServer.server.rest.model.buildType.PropEntitiesArtifactDep) XmlType(javax.xml.bind.annotation.XmlType) PasswordsSearcher(jetbrains.buildServer.serverSide.parameters.types.PasswordsSearcher) SAgentType(jetbrains.buildServer.serverSide.agentTypes.SAgentType) RevisionRules(jetbrains.buildServer.artifacts.RevisionRules) Revision(jetbrains.buildServer.server.rest.model.change.Revision) ProblemOccurrences(jetbrains.buildServer.server.rest.model.problem.ProblemOccurrences) XmlAttribute(javax.xml.bind.annotation.XmlAttribute) BuildChanges(jetbrains.buildServer.server.rest.model.change.BuildChanges) Properties(jetbrains.buildServer.server.rest.model.Properties) CachingValue(jetbrains.buildServer.server.rest.util.CachingValue) IOException(java.io.IOException) ArtifactDependencyChangesProvider(jetbrains.buildServer.serverSide.impl.changeProviders.ArtifactDependencyChangesProvider) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) ValueWithDefault(jetbrains.buildServer.server.rest.util.ValueWithDefault) DownloadedArtifacts(jetbrains.buildServer.server.rest.model.build.downloadedArtifacts.DownloadedArtifacts) DownloadedArtifactsLoggerImpl(jetbrains.buildServer.serverSide.impl.DownloadedArtifactsLoggerImpl) jetbrains.buildServer.server.rest.request(jetbrains.buildServer.server.rest.request) MapParametersProviderImpl(jetbrains.buildServer.parameters.impl.MapParametersProviderImpl) VcsLabelManager(jetbrains.buildServer.serverSide.vcs.VcsLabelManager) FileApiUrlBuilder(jetbrains.buildServer.server.rest.model.files.FileApiUrlBuilder) Permission(jetbrains.buildServer.serverSide.auth.Permission) BuildMetadataEntry(jetbrains.buildServer.serverSide.metadata.BuildMetadataEntry) SUser(jetbrains.buildServer.users.SUser) XmlElement(javax.xml.bind.annotation.XmlElement) VcsLabelManager(jetbrains.buildServer.serverSide.vcs.VcsLabelManager) XmlElement(javax.xml.bind.annotation.XmlElement)

Aggregations

Logger (com.intellij.openapi.diagnostic.Logger)2 ApiOperation (io.swagger.annotations.ApiOperation)2 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 jetbrains.buildServer.server.rest.data (jetbrains.buildServer.server.rest.data)2 TagFinder (jetbrains.buildServer.server.rest.data.build.TagFinder)2 ProblemOccurrenceFinder (jetbrains.buildServer.server.rest.data.problem.ProblemOccurrenceFinder)2 TestOccurrenceFinder (jetbrains.buildServer.server.rest.data.problem.TestOccurrenceFinder)2 jetbrains.buildServer.server.rest.model (jetbrains.buildServer.server.rest.model)2 Properties (jetbrains.buildServer.server.rest.model.Properties)2 BuildChanges (jetbrains.buildServer.server.rest.model.change.BuildChanges)2 VcsLabelManager (jetbrains.buildServer.serverSide.vcs.VcsLabelManager)2 Api (io.swagger.annotations.Api)1 ApiParam (io.swagger.annotations.ApiParam)1 java.io (java.io)1 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Supplier (java.util.function.Supplier)1