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