Search in sources :

Example 1 with TagsManager

use of jetbrains.buildServer.tags.TagsManager in project teamcity-rest by JetBrains.

the class BuildRequest method addTagsMultipleToBuild.

/**
 * Experimental.
 * Adds a set of tags to multiple builds
 * @return List of error messages with associated entities, if any
 */
@POST
@Path("/multiple/{buildLocator}/tags/")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Add tags to multiple matching builds.", nickname = "addTagsToMultipleBuilds")
public MultipleOperationResult addTagsMultipleToBuild(@ApiParam(format = LocatorName.BUILD) @PathParam("buildLocator") String buildLocator, Tags tags, @QueryParam("fields") String fields) {
    final TagsManager tagsManager = myBeanContext.getSingletonService(TagsManager.class);
    final List<TagData> tagsPosted = tags.getFromPosted(myBeanContext.getSingletonService(UserFinder.class));
    return processMultiple(buildLocator, (build) -> tagsManager.addTagDatas(build, tagsPosted), new Fields(fields));
}
Also used : TagsManager(jetbrains.buildServer.tags.TagsManager) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with TagsManager

use of jetbrains.buildServer.tags.TagsManager in project teamcity-rest by JetBrains.

the class BuildRequest method addTag.

/**
 * Adds a single tag to a build
 *
 * @param buildLocator build locator
 * @param tagName      name of a tag to add
 */
@POST
@Path("/{buildLocator}/tags/")
@Consumes({ "text/plain" })
@Produces({ "text/plain" })
@ApiOperation(hidden = true, value = "Use addTags instead")
public String addTag(@ApiParam(format = LocatorName.BUILD) @PathParam("buildLocator") String buildLocator, String tagName, @Context HttpServletRequest request) {
    if (StringUtil.isEmpty(tagName)) {
        // check for empty tags: http://youtrack.jetbrains.com/issue/TW-34426
        throw new BadRequestException("Cannot apply empty tag, should have non empty request body");
    }
    BuildPromotion build = myBuildFinder.getBuildPromotion(null, buildLocator);
    final TagsManager tagsManager = myBeanContext.getSingletonService(TagsManager.class);
    tagsManager.addTagDatas(build, Collections.singleton(TagData.createPublicTag(tagName)));
    return tagName;
}
Also used : TagsManager(jetbrains.buildServer.tags.TagsManager) ApiOperation(io.swagger.annotations.ApiOperation)

Example 3 with TagsManager

use of jetbrains.buildServer.tags.TagsManager in project teamcity-rest by JetBrains.

the class BuildQueueRequest method addTag.

/**
 * Adds a single tag to a build
 *
 * @param buildLocator build locator
 * @param tagName      name of a tag to add
 */
@POST
@Path("/{buildLocator}/tags/")
@Consumes({ "text/plain" })
@Produces({ "text/plain" })
@ApiOperation(hidden = true, value = "Use addTags instead")
public String addTag(@ApiParam(format = LocatorName.BUILD) @PathParam("buildLocator") String buildLocator, String tagName, @Context HttpServletRequest request) {
    if (StringUtil.isEmpty(tagName)) {
        // check for empty tags: http://youtrack.jetbrains.com/issue/TW-34426
        throw new BadRequestException("Cannot apply empty tag, should have non empty request body");
    }
    BuildPromotion buildPromotion = myBuildPromotionFinder.getItem(Locator.createLocator(buildLocator, getBuildPromotionLocatorDefaults(), null).getStringRepresentation());
    final TagsManager tagsManager = myBeanContext.getSingletonService(TagsManager.class);
    tagsManager.addTagDatas(buildPromotion, Collections.singleton(TagData.createPublicTag(tagName)));
    return tagName;
}
Also used : TagsManager(jetbrains.buildServer.tags.TagsManager) ApiOperation(io.swagger.annotations.ApiOperation)

Example 4 with TagsManager

use of jetbrains.buildServer.tags.TagsManager in project teamcity-rest by JetBrains.

the class BuildRequest method replaceTagsOnBuild.

/**
 * Replaces the build's tags designated by the tags 'locator' to the set of tags passed.
 */
@PUT
@Path("/{buildLocator}/tags/")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Update tags of the matching build.", nickname = "setBuildTags")
public Tags replaceTagsOnBuild(@ApiParam(format = LocatorName.BUILD) @PathParam("buildLocator") String buildLocator, @ApiParam(format = LocatorName.TAG) @QueryParam("locator") String tagLocator, Tags tags, @QueryParam("fields") String fields, @Context HttpServletRequest request) {
    BuildPromotion build = myBuildFinder.getBuildPromotion(null, buildLocator);
    final TagFinder tagFinder = new TagFinder(myBeanContext.getSingletonService(UserFinder.class), build);
    final TagsManager tagsManager = myBeanContext.getSingletonService(TagsManager.class);
    tagsManager.removeTagDatas(build, tagFinder.getItems(tagLocator, TagFinder.getDefaultLocator()).myEntries);
    List<TagData> postedTagDatas = tags.getFromPosted(myBeanContext.getSingletonService(UserFinder.class));
    tagsManager.addTagDatas(build, postedTagDatas);
    // returning the tags posted as the default locator might not match the tags just created
    return new Tags(postedTagDatas, new Fields(fields), myBeanContext);
}
Also used : TagFinder(jetbrains.buildServer.server.rest.data.build.TagFinder) TagsManager(jetbrains.buildServer.tags.TagsManager) ApiOperation(io.swagger.annotations.ApiOperation)

Example 5 with TagsManager

use of jetbrains.buildServer.tags.TagsManager in project teamcity-rest by JetBrains.

the class BuildRequest method removeTagsMultiple.

/**
 * Experimental.
 * Deletes a set of tags from multiple builds
 * @return List of error messages with associated entities, if any
 */
@DELETE
@Path("/multiple/{buildLocator}/tags/")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Remove tags from multiple matching builds.", nickname = "removeMultipleBuildTags")
public MultipleOperationResult removeTagsMultiple(@ApiParam(format = LocatorName.BUILD) @PathParam("buildLocator") String buildLocator, Tags tags, @QueryParam("fields") String fields) {
    final TagsManager tagsManager = myBeanContext.getSingletonService(TagsManager.class);
    final List<TagData> tagsPosted = tags.getFromPosted(myBeanContext.getSingletonService(UserFinder.class));
    return processMultiple(buildLocator, (build) -> tagsManager.removeTagDatas(build, tagsPosted), new Fields(fields));
}
Also used : TagsManager(jetbrains.buildServer.tags.TagsManager) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)8 TagsManager (jetbrains.buildServer.tags.TagsManager)8 TagFinder (jetbrains.buildServer.server.rest.data.build.TagFinder)2 Fields (jetbrains.buildServer.server.rest.model.Fields)1 Tags (jetbrains.buildServer.server.rest.model.build.Tags)1