use of com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails in project hub-alert by blackducksoftware.
the class AzureBoardsIssueCreator method extractIssueDetails.
private ExistingIssueDetails<Integer> extractIssueDetails(WorkItemResponseModel workItem, IssueCreationModel alertIssueCreationModel) {
WorkItemFieldsWrapper workItemFields = workItem.createFieldsWrapper(gson);
String workItemKey = Objects.toString(workItem.getId());
String workItemTitle = workItemFields.getField(WorkItemResponseFields.System_Title).orElse("Unknown Title");
String workItemUILink = AzureBoardsUILinkUtils.extractUILink(organizationName, workItem);
IssueCategory issueCategory = alertIssueCreationModel.getSource().map(issueCategoryRetriever::retrieveIssueCategoryFromProjectIssueModel).orElse(IssueCategory.BOM);
return new ExistingIssueDetails<>(workItem.getId(), workItemKey, workItemTitle, workItemUILink, IssueStatus.RESOLVABLE, issueCategory);
}
use of com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails in project hub-alert by blackducksoftware.
the class AzureBoardsExistingIssueDetailsCreator method createIssueDetails.
public ExistingIssueDetails<Integer> createIssueDetails(WorkItemResponseModel workItem, WorkItemFieldsWrapper workItemFields, ProjectIssueModel projectIssueModel) {
Integer workItemId = workItem.getId();
String workItemTitle = workItemFields.getField(WorkItemResponseFields.System_Title).orElse("Unknown Title");
String workItemUILink = AzureBoardsUILinkUtils.extractUILink(organizationName, workItem);
IssueCategory issueCategory = issueCategoryRetriever.retrieveIssueCategoryFromProjectIssueModel(projectIssueModel);
String workItemState = workItemFields.getField(WorkItemResponseFields.System_State).orElse("Unknown");
IssueStatus issueStatus = issueStatusResolver.resolveIssueStatus(workItemState);
return new ExistingIssueDetails<>(workItemId, Objects.toString(workItemId), workItemTitle, workItemUILink, issueStatus, issueCategory);
}
use of com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails in project hub-alert by blackducksoftware.
the class AzureBoardsComponentIssueFinderTest method findExistingIssuesByProjectIssueModelTest.
@Test
public void findExistingIssuesByProjectIssueModelTest() throws AlertException {
Gson gson = new Gson();
String organizationName = "orgName";
AzureBoardsIssueTrackerQueryManager queryManager = Mockito.mock(AzureBoardsIssueTrackerQueryManager.class);
IssueCategoryRetriever issueCategoryRetriever = new IssueCategoryRetriever();
AzureBoardsExistingIssueDetailsCreator issueDetailsCreator = new AzureBoardsExistingIssueDetailsCreator(organizationName, issueCategoryRetriever, azureBoardsIssueStatusResolver);
AzureBoardsWorkItemFinder workItemFinder = new AzureBoardsWorkItemFinder(queryManager, "test proj");
AzureBoardsComponentIssueFinder componentIssueFinder = new AzureBoardsComponentIssueFinder(gson, workItemFinder, issueDetailsCreator);
IssuePolicyDetails testPolicy = new IssuePolicyDetails("Test Policy", ItemOperation.ADD, ComponentConcernSeverity.UNSPECIFIED_UNKNOWN);
ProjectIssueModel projectIssueModel = ProjectIssueModel.policy(PROVIDER_DETAILS, PROJECT_ITEM, PROJECT_VERSION_ITEM, ISSUE_BOM_COMPONENT_DETAILS, testPolicy);
WorkItemResponseModel workItemResponseModel = createWorkItemResponseModel(workItemReopenState);
Mockito.when(queryManager.executeQueryAndRetrieveWorkItems(Mockito.any())).thenReturn(List.of(workItemResponseModel));
List<ExistingIssueDetails<Integer>> existingIssueDetailsList = componentIssueFinder.findExistingIssuesByProjectIssueModel(projectIssueModel);
assertEquals(1, existingIssueDetailsList.size());
ExistingIssueDetails<Integer> existingIssueDetails = existingIssueDetailsList.get(0);
assertEquals(IssueStatus.RESOLVABLE, existingIssueDetails.getIssueStatus());
assertEquals(IssueCategory.POLICY, existingIssueDetails.getIssueCategory());
}
use of com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails in project hub-alert by blackducksoftware.
the class AzureBoardsComponentIssueFinder method findExistingIssuesByProjectIssueModel.
@Override
public List<ExistingIssueDetails<Integer>> findExistingIssuesByProjectIssueModel(ProjectIssueModel projectIssueModel) throws AlertException {
LinkableItem projectVersion = projectIssueModel.getProjectVersion().orElseThrow(() -> new AlertRuntimeException("Missing project-version"));
String categoryKey = AzureBoardsAlertIssuePropertiesManager.CATEGORY_TYPE_VULNERABILITY_COMPATIBILITY_LABEL;
AzureSearchFieldMappingBuilder fieldRefNameToValue = createBomFieldReferenceToValueMap(projectVersion, projectIssueModel.getBomComponentDetails());
Optional<IssuePolicyDetails> policyDetails = projectIssueModel.getPolicyDetails();
Optional<String> optionalPolicyName = policyDetails.map(IssuePolicyDetails::getName);
if (optionalPolicyName.isPresent()) {
categoryKey = AzureBoardsAlertIssuePropertiesManager.CATEGORY_TYPE_POLICY_COMPATIBILITY_LABEL;
String additionalInfoKey = AzureBoardsAlertIssuePropertiesManager.POLICY_ADDITIONAL_KEY_COMPATIBILITY_LABEL + optionalPolicyName.get();
fieldRefNameToValue.addAdditionalInfoKey(additionalInfoKey);
}
if (projectIssueModel.getComponentUnknownVersionDetails().isPresent()) {
categoryKey = AzureBoardsAlertIssuePropertiesManager.CATEGORY_TYPE_COMPONENT_UNKNOWN_VERSION_COMPATIBILITY_LABEL;
}
fieldRefNameToValue.addCategoryKey(categoryKey);
return workItemFinder.findWorkItems(projectIssueModel.getProvider(), projectIssueModel.getProject(), fieldRefNameToValue).stream().map(workItemResponseModel -> createIssueDetails(workItemResponseModel, projectIssueModel)).collect(Collectors.toList());
}
use of com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails in project hub-alert by blackducksoftware.
the class IssueTrackerTestAction method testConfig.
@Override
public MessageResult testConfig(DistributionJobModel testJobModel, String jobName, @Nullable String customTopic, @Nullable String customMessage) throws AlertException {
D distributionDetails = (D) testJobModel.getDistributionJobDetails();
IssueTrackerMessageSender<T> messageSender = messageSenderFactory.createMessageSender(distributionDetails);
String topicString = Optional.ofNullable(customTopic).orElse("Alert Test Topic");
String messageString = Optional.ofNullable(customMessage).orElse("Alert Test Message");
// TODO determine if source should be required everywhere
ProjectIssueModel testProjectIssueModel = createPlaceholderProjectIssueModel(testJobModel.getBlackDuckGlobalConfigId());
String postCreateComment = String.format("Created by [ Test Configuration ] in the Alert Distribution Job: %s", testJobModel.getName());
IssueCreationModel creationRequest = IssueCreationModel.simple(topicString, messageString, List.of(postCreateComment), testProjectIssueModel.getProvider());
IssueTrackerModelHolder<T> creationRequestModelHolder = new IssueTrackerModelHolder<>(List.of(creationRequest), List.of(), List.of());
IssueTrackerTestActionFieldStatusCreator fieldStatusCreator = new IssueTrackerTestActionFieldStatusCreator();
List<IssueTrackerIssueResponseModel<T>> createdIssues;
try {
createdIssues = messageSender.sendMessages(creationRequestModelHolder);
} catch (AlertFieldException e) {
logger.error("Failed to create test issue", e);
return new MessageResult("Failed to create issue: " + e.getMessage(), e.getFieldErrors());
} catch (AlertException e) {
logger.error("Failed to create test issue", e);
return new MessageResult("Failed to create issue: " + e.getMessage(), fieldStatusCreator.createWithoutField(e.getMessage()));
}
int createdIssuesSize = createdIssues.size();
if (createdIssuesSize != 1) {
String errorMessage = String.format("Expected [1] issue to be created, but there were actually [%d]", createdIssuesSize);
return new MessageResult(errorMessage, fieldStatusCreator.createWithoutField(errorMessage));
}
IssueTrackerIssueResponseModel<T> createdIssue = createdIssues.get(0);
ExistingIssueDetails<T> existingIssueDetails = new ExistingIssueDetails<>(createdIssue.getIssueId(), createdIssue.getIssueKey(), createdIssue.getIssueTitle(), createdIssue.getIssueLink(), IssueStatus.RESOLVABLE, IssueCategory.BOM);
if (!hasResolveTransition(distributionDetails)) {
return createSuccessMessageResult(existingIssueDetails);
}
IssueTrackerTransitionTestAction<T> transitionTestAction = new IssueTrackerTransitionTestAction<>(messageSender, fieldStatusCreator);
Optional<MessageResult> optionalResolveFailure = transitionTestAction.transitionTestIssueOrReturnFailureResult(IssueOperation.RESOLVE, existingIssueDetails, testProjectIssueModel);
if (optionalResolveFailure.isPresent()) {
return optionalResolveFailure.get();
}
if (!hasReopenTransition(distributionDetails)) {
return createSuccessMessageResult(existingIssueDetails);
}
return transitionTestAction.transitionTestIssueOrReturnFailureResult(IssueOperation.OPEN, existingIssueDetails, testProjectIssueModel).orElseGet(() -> transitionTestAction.transitionTestIssueOrReturnFailureResult(IssueOperation.RESOLVE, existingIssueDetails, testProjectIssueModel).orElse(createSuccessMessageResult(existingIssueDetails)));
}
Aggregations