Search in sources :

Example 1 with IssueCommentModel

use of com.synopsys.integration.alert.api.channel.issue.model.IssueCommentModel in project hub-alert by blackducksoftware.

the class ProjectIssueModelConverter method toIssueCommentModel.

public <T extends Serializable> IssueCommentModel<T> toIssueCommentModel(ExistingIssueDetails<T> existingIssueDetails, ProjectIssueModel projectIssueModel) {
    ChunkedStringBuilder commentBuilder = new ChunkedStringBuilder(formatter.getMaxCommentLength());
    LinkableItem provider = projectIssueModel.getProvider();
    String commentHeader = String.format("The component was updated in %s[%s]", provider.getLabel(), provider.getValue());
    commentBuilder.append(formatter.encode(commentHeader));
    commentBuilder.append(formatter.getLineSeparator());
    commentBuilder.append(formatter.getSectionSeparator());
    commentBuilder.append(formatter.getLineSeparator());
    createVulnerabilitySeverityStatusSectionPieces(projectIssueModel).forEach(commentBuilder::append);
    createProjectIssueModelConcernSectionPieces(projectIssueModel, true).forEach(commentBuilder::append);
    IssueBomComponentDetails bomComponent = projectIssueModel.getBomComponentDetails();
    List<String> attributeStrings = bomComponentDetailConverter.gatherAttributeStrings(bomComponent);
    for (String attributeString : attributeStrings) {
        commentBuilder.append(formatter.getNonBreakingSpace());
        commentBuilder.append(formatter.encode("-"));
        commentBuilder.append(formatter.getNonBreakingSpace());
        commentBuilder.append(attributeString);
        commentBuilder.append(formatter.getLineSeparator());
    }
    List<String> chunkedComments = commentBuilder.collectCurrentChunks();
    return new IssueCommentModel<>(existingIssueDetails, chunkedComments, projectIssueModel);
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) ChunkedStringBuilder(com.synopsys.integration.alert.common.channel.message.ChunkedStringBuilder) IssueCommentModel(com.synopsys.integration.alert.api.channel.issue.model.IssueCommentModel)

Example 2 with IssueCommentModel

use of com.synopsys.integration.alert.api.channel.issue.model.IssueCommentModel in project hub-alert by blackducksoftware.

the class IssueTrackerIssueTransitioner method transitionIssue.

public final Optional<IssueTrackerIssueResponseModel<T>> transitionIssue(IssueTransitionModel<T> issueTransitionModel) throws AlertException {
    IssueOperation issueOperation = issueTransitionModel.getIssueOperation();
    ExistingIssueDetails<T> existingIssueDetails = issueTransitionModel.getExistingIssueDetails();
    Optional<IssueTrackerIssueResponseModel<T>> transitionResponse = Optional.empty();
    Optional<String> optionalTransitionName = retrieveJobTransitionName(issueOperation);
    if (optionalTransitionName.isPresent()) {
        String transitionName = optionalTransitionName.get();
        boolean shouldAttemptTransition = isTransitionRequired(existingIssueDetails, issueOperation);
        if (shouldAttemptTransition) {
            attemptTransition(issueOperation, existingIssueDetails, transitionName);
            IssueTrackerIssueResponseModel<T> transitionResponseModel = issueResponseCreator.createIssueResponse(issueTransitionModel.getSource(), existingIssueDetails, issueOperation);
            transitionResponse = Optional.of(transitionResponseModel);
        } else {
            logger.debug("The issue is already in the status category that would result from this transition ({}). Issue Details: {}", transitionName, existingIssueDetails);
        }
    } else {
        logger.debug("No transition name was provided so no '{}' transition will be performed. Issue Details: {}", issueOperation.name(), existingIssueDetails);
    }
    IssueCommentModel<T> commentRequestModel = new IssueCommentModel<>(existingIssueDetails, issueTransitionModel.getPostTransitionComments(), issueTransitionModel.getSource());
    commenter.commentOnIssue(commentRequestModel);
    return transitionResponse;
}
Also used : IssueTrackerIssueResponseModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel) IssueOperation(com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation) IssueCommentModel(com.synopsys.integration.alert.api.channel.issue.model.IssueCommentModel)

Aggregations

IssueCommentModel (com.synopsys.integration.alert.api.channel.issue.model.IssueCommentModel)2 IssueBomComponentDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails)1 IssueTrackerIssueResponseModel (com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel)1 IssueOperation (com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation)1 ChunkedStringBuilder (com.synopsys.integration.alert.common.channel.message.ChunkedStringBuilder)1 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)1