Search in sources :

Example 6 with Issue

use of com.checkmarx.flow.dto.Issue in project cx-flow by checkmarx-ltd.

the class GitHubIssueTracker method mapToIssue.

private Issue mapToIssue(com.checkmarx.flow.dto.github.Issue issue) {
    if (issue == null) {
        return null;
    }
    Issue i = new Issue();
    i.setBody(issue.getBody());
    i.setTitle(issue.getTitle());
    i.setId(String.valueOf(issue.getId()));
    List<String> labels = new ArrayList<>();
    for (LabelsItem l : issue.getLabels()) {
        labels.add(l.getName());
    }
    i.setLabels(labels);
    i.setUrl(issue.getUrl());
    i.setState(issue.getState());
    return i;
}
Also used : Issue(com.checkmarx.flow.dto.Issue) LabelsItem(com.checkmarx.flow.dto.github.LabelsItem) ArrayList(java.util.ArrayList)

Example 7 with Issue

use of com.checkmarx.flow.dto.Issue in project cx-flow by checkmarx-ltd.

the class PublishingSteps method azureDevOpsContainsIssue.

@Given("Azure DevOps contains {int} open issue with title: {string} and description containing link: {string}")
public void azureDevOpsContainsIssue(int issueCount, String title, String link) throws IOException {
    List<Issue> issues = getIssues();
    verifyIssueCount(issues, issueCount);
    String linkInHtmlAttribute = HtmlUtils.htmlEscape(link);
    for (Issue issue : issues) {
        assertEquals(adoProperties.getOpenStatus(), issue.getState(), "Invalid issue state.");
        assertEquals(title, issue.getTitle(), "Invalid issue title.");
        String description = issue.getBody();
        assertNotNull(description, "Issue is missing description.");
        assertTrue(description.contains(linkInHtmlAttribute), "Description doesn't contain the link: " + link);
    }
}
Also used : Issue(com.checkmarx.flow.dto.Issue) Given(io.cucumber.java.en.Given)

Example 8 with Issue

use of com.checkmarx.flow.dto.Issue in project cx-flow by checkmarx-ltd.

the class ADOIssueTracker method getIssue.

private Issue getIssue(String uri, String issueBody, ScanRequest scanRequest) {
    HttpEntity<Void> httpEntity = new HttpEntity<>(ADOUtils.createAuthHeaders(scmConfigOverrider.determineConfigToken(properties, scanRequest.getScmInstance())));
    log.debug("Getting issue at uri {}", uri);
    ResponseEntity<String> response = restTemplate.exchange(uri, HttpMethod.GET, httpEntity, String.class);
    String r = response.getBody();
    if (r == null) {
        return null;
    }
    JSONObject o = new JSONObject(r);
    JSONObject fields = o.getJSONObject("fields");
    Issue i = new Issue();
    i.setBody(fields.getString(FIELD_PREFIX.concat(issueBody)));
    i.setTitle(fields.getString(TITLE_FIELD));
    i.setId(String.valueOf(o.getInt("id")));
    String[] tags = fields.getString(TAGS_FIELD).split(";");
    i.setLabels(Arrays.asList(tags));
    i.setUrl(uri);
    i.setState(fields.getString(STATE_FIELD));
    return i;
}
Also used : Issue(com.checkmarx.flow.dto.Issue) JSONObject(org.json.JSONObject)

Example 9 with Issue

use of com.checkmarx.flow.dto.Issue in project cx-flow by checkmarx-ltd.

the class ServiceNowTracker method mapToIssue.

/**
 * Convert Incident object into Issue
 * @param incident
 * @return Issue object.
 */
private Issue mapToIssue(Incident incident) {
    final Issue issue = new Issue();
    issue.setId(incident.getSysId());
    issue.setState(incident.getState());
    issue.setBody(incident.getDescription());
    issue.setTitle(incident.getShortDescription());
    issue.setLabels(Lists.newArrayList());
    issue.setMetadata(Maps.newHashMap());
    issue.setUrl(properties.getUrl());
    return issue;
}
Also used : Issue(com.checkmarx.flow.dto.Issue)

Example 10 with Issue

use of com.checkmarx.flow.dto.Issue in project cx-flow by checkmarx-ltd.

the class ServiceNowTracker method getIncidentByIDConvertToIssue.

/**
 * Find Incident By Sys ID and convert into Issue
 * @return Issue object.
 */
private Optional<Issue> getIncidentByIDConvertToIssue(String sysId) {
    log.debug("Executing getIncidentByIDConvertToIssue");
    try {
        String apiRequest = String.format("%s%s?sys_id=%s", properties.getApiUrl(), INCIDENTS, sysId);
        Optional<Result> res = Optional.ofNullable(restOperations.getForObject(apiRequest, Result.class));
        if (res.isPresent()) {
            return res.get().getIncidents().stream().map(i -> this.mapToIssue(i)).findFirst();
        }
    } catch (RestClientException e) {
        log.error("Error occurred while fetching ServiceNow Issue");
        log.error(ExceptionUtils.getStackTrace(e));
        throw new MachinaRuntimeException();
    }
    return Optional.empty();
}
Also used : Issue(com.checkmarx.flow.dto.Issue) ScanRequest(com.checkmarx.flow.dto.ScanRequest) ScanResults(com.checkmarx.sdk.dto.ScanResults) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) FlowProperties(com.checkmarx.flow.config.FlowProperties) HTMLHelper(com.checkmarx.flow.utils.HTMLHelper) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) Locale(java.util.Locale) URI(java.net.URI) RestClientException(org.springframework.web.client.RestClientException) Result(com.checkmarx.flow.dto.servicenow.Result) Logger(org.slf4j.Logger) RestOperations(org.springframework.web.client.RestOperations) RestTemplateBuilder(org.springframework.boot.web.client.RestTemplateBuilder) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) ServiceNowProperties(com.checkmarx.flow.config.ServiceNowProperties) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) URLEncoder(java.net.URLEncoder) List(java.util.List) Incident(com.checkmarx.flow.dto.servicenow.Incident) MachinaRuntimeException(com.checkmarx.flow.exception.MachinaRuntimeException) ScanUtils(com.checkmarx.flow.utils.ScanUtils) Optional(java.util.Optional) MachinaException(com.checkmarx.flow.exception.MachinaException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JSONArray(org.json.JSONArray) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) MachinaRuntimeException(com.checkmarx.flow.exception.MachinaRuntimeException) RestClientException(org.springframework.web.client.RestClientException) Result(com.checkmarx.flow.dto.servicenow.Result)

Aggregations

Issue (com.checkmarx.flow.dto.Issue)27 MachinaException (com.checkmarx.flow.exception.MachinaException)8 ArrayList (java.util.ArrayList)8 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)6 ScanRequest (com.checkmarx.flow.dto.ScanRequest)5 MachinaRuntimeException (com.checkmarx.flow.exception.MachinaRuntimeException)5 ScanResults (com.checkmarx.sdk.dto.ScanResults)5 URI (java.net.URI)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Test (org.junit.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 FlowProperties (com.checkmarx.flow.config.FlowProperties)2 ServiceNowProperties (com.checkmarx.flow.config.ServiceNowProperties)2 IssueTracker (com.checkmarx.flow.custom.IssueTracker)2 Incident (com.checkmarx.flow.dto.servicenow.Incident)2 Result (com.checkmarx.flow.dto.servicenow.Result)2 HTMLHelper (com.checkmarx.flow.utils.HTMLHelper)2 ScanUtils (com.checkmarx.flow.utils.ScanUtils)2 Lists (com.google.common.collect.Lists)2