use of com.atlassian.jira.rest.client.api.domain.input.FieldInput in project cx-flow by checkmarx-ltd.
the class JiraService method createIssue.
public String createIssue(ScanResults.XIssue issue, ScanRequest request) throws JiraClientException {
log.debug("Retrieving issuetype object for project {}, type {}", request.getBugTracker().getProjectKey(), request.getBugTracker().getIssueType());
try {
BugTracker bugTracker = request.getBugTracker();
String assignee = bugTracker.getAssignee();
String projectKey = bugTracker.getProjectKey();
String application = request.getApplication();
String namespace = request.getNamespace();
String repoName = request.getRepoName();
String branch = request.getBranch();
String filename = issue.getFilename();
String vulnerability = issue.getVulnerability();
String severity = issue.getSeverity();
IssueType issueType = this.getIssueType(projectKey, bugTracker.getIssueType());
IssueInputBuilder issueBuilder = new IssueInputBuilder(projectKey, issueType.getId());
String issuePrefix = jiraProperties.getIssuePrefix();
String issuePostfix = jiraProperties.getIssuePostfix();
if (issuePrefix == null) {
issuePrefix = "";
}
if (issuePostfix == null) {
issuePostfix = "";
}
String summary;
boolean useBranch = isUseBranch(request);
List<ScanResults.ScaDetails> scaDetails = issue.getScaDetails();
if (scaDetails != null) {
summary = ScanUtils.getScaSummaryIssueKey(request, issue, issuePrefix, issuePostfix);
} else {
if (useBranch) {
summary = formatSastIssueSummary(jiraProperties.getSastIssueSummaryBranchFormat(), issue, request);
} else {
summary = formatSastIssueSummary(jiraProperties.getSastIssueSummaryFormat(), issue, request);
}
}
String fileUrl = ScanUtils.getFileUrl(request, issue.getFilename());
summary = checkSummaryLength(summary);
issueBuilder.setSummary(HTMLHelper.getScanRequestIssueKeyWithDefaultProductValue(request, summary, jiraProperties.getLabelPrefix()));
issueBuilder.setDescription(this.getBody(issue, request, fileUrl));
if (assignee != null && !assignee.isEmpty()) {
ComplexIssueInputFieldValue jiraAssignee = getAssignee(assignee, projectKey);
if (jiraAssignee != null) {
issueBuilder.setFieldInput(new FieldInput(IssueFieldId.ASSIGNEE_FIELD, jiraAssignee));
}
}
String scannerTypeSeverity = getScannerTypeSeverity(issue, severity, scaDetails);
if (bugTracker.getPriorities() != null && bugTracker.getPriorities().containsKey(scannerTypeSeverity)) {
issueBuilder.setFieldValue(PRIORITY_FIELD_TYPE, ComplexIssueInputFieldValue.with("name", bugTracker.getPriorities().get(scannerTypeSeverity)));
}
/*Add labels for tracking existing issues*/
List<String> labels = new ArrayList<>();
if (useBranch) {
labels.add(request.getProduct().getProduct());
labels.add(jiraProperties.getOwnerLabelPrefix().concat(":").concat(namespace));
labels.add(jiraProperties.getRepoLabelPrefix().concat(":").concat(repoName));
labels.add(jiraProperties.getBranchLabelPrefix().concat(":").concat(branch));
} else if (!ScanUtils.anyEmpty(application, repoName)) {
labels.add(request.getProduct().getProduct());
labels.add(jiraProperties.getAppLabelPrefix().concat(":").concat(application));
labels.add(jiraProperties.getRepoLabelPrefix().concat(":").concat(repoName));
} else if (!ScanUtils.empty(application)) {
labels.add(request.getProduct().getProduct());
labels.add(jiraProperties.getAppLabelPrefix().concat(":").concat(application));
}
if (null != scaDetails) {
labels.add(JIRA_ISSUE_LABEL_SCA);
} else {
labels.add(JIRA_ISSUE_LABEL_SAST);
}
log.debug("Adding tracker labels: {} - {}", jiraProperties.getLabelTracker(), labels);
if (!jiraProperties.getLabelTracker().equals(LABEL_FIELD_TYPE)) {
String customField = getCustomFieldByName(projectKey, bugTracker.getIssueType(), jiraProperties.getLabelTracker());
issueBuilder.setFieldValue(customField, labels);
} else {
issueBuilder.setFieldValue(LABEL_FIELD_TYPE, labels);
}
log.debug("Creating JIRA issue");
mapCustomFields(request, issue, issueBuilder, false);
log.debug("Creating JIRA issue");
BasicIssue basicIssue = this.issueClient.createIssue(issueBuilder.build()).claim();
log.debug("JIRA issue {} created", basicIssue.getKey());
return basicIssue.getKey();
} catch (RestClientException e) {
log.error("Error occurred while creating JIRA issue.", e);
throw new JiraClientException();
}
}
use of com.atlassian.jira.rest.client.api.domain.input.FieldInput in project cx-flow by checkmarx-ltd.
the class JiraService method transitionCloseIssue.
private Issue transitionCloseIssue(String bugId, String transitionName, BugTracker bt, boolean falsePositive) throws JiraClientException {
Issue issue;
try {
issue = this.issueClient.getIssue(bugId).claim();
URI transitionURI = issue.getTransitionsUri();
final Iterable<Transition> transitions = this.issueClient.getTransitions(transitionURI).claim();
final Transition transition = getTransitionByName(transitions, transitionName);
if (transition != null) {
// No input for transition
if (ScanUtils.empty(bt.getCloseTransitionField()) && ScanUtils.empty(bt.getCloseTransitionValue())) {
this.issueClient.transition(issue.getTransitionsUri(), new TransitionInput(transition.getId())).claim();
} else // Input required for transition
{
String transitionValue = bt.getCloseTransitionValue();
if (falsePositive && !ScanUtils.empty(jiraProperties.getCloseFalsePositiveTransitionValue())) {
// Allow for a separate resolution status if any of the issues are false positive
// TODO add to bt?
transitionValue = jiraProperties.getCloseFalsePositiveTransitionValue();
}
this.issueClient.transition(issue.getTransitionsUri(), new TransitionInput(transition.getId(), Collections.singletonList(new FieldInput(bt.getCloseTransitionField(), ComplexIssueInputFieldValue.with("name", transitionValue))))).claim();
}
} else {
log.warn("Issue cannot't be transitioned to {}. Transition is not applicable to issue {}. Available transitions: {}", transitionName, bugId, transitions);
}
} catch (RestClientException e) {
log.error("There was a problem transitioning issue {}. ", bugId, e);
throw new JiraClientException("");
}
return issue;
}
use of com.atlassian.jira.rest.client.api.domain.input.FieldInput in project jira-plugin by jenkinsci.
the class JiraRestService method createIssue.
public BasicIssue createIssue(String projectKey, String description, String assignee, Iterable<String> components, String summary, @NonNull Long issueTypeId, @Nullable Long priorityId) {
IssueInputBuilder builder = new IssueInputBuilder();
builder.setProjectKey(projectKey).setDescription(description).setIssueTypeId(issueTypeId).setSummary(summary);
if (priorityId != null) {
builder.setPriorityId(priorityId);
}
if (StringUtils.isNotBlank(assignee)) {
final Map<String, Object> valuesMap = new HashMap<>(2);
// server
valuesMap.put("name", assignee);
// cloud
valuesMap.put("accountId", assignee);
// Need to use "accountId" as specified here:
// https://developer.atlassian.com/cloud/jira/platform/deprecation-notice-user-privacy-api-migration-guide/
//
// See upstream fix for setAssigneeName:
// https://bitbucket.org/atlassian/jira-rest-java-client/pull-requests/104/change-field-name-from-name-to-id-for/diff
builder.setFieldInput(new FieldInput(IssueFieldId.ASSIGNEE_FIELD, new ComplexIssueInputFieldValue(valuesMap)));
}
if (StreamSupport.stream(components.spliterator(), false).count() > 0) {
builder.setComponentsNames(components);
}
final IssueInput issueInput = builder.build();
try {
return jiraRestClient.getIssueClient().createIssue(issueInput).get(timeout, TimeUnit.SECONDS);
} catch (Exception e) {
LOGGER.log(WARNING, "Jira REST createIssue error: " + e.getMessage(), e);
return null;
}
}
Aggregations