Search in sources :

Example 11 with Issue

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

the class GitHubIssueTracker method getIssues.

/**
 * Get all issues for a GitHub repository
 *
 * @return List of GitHub Issues
 * @ full name (owner/repo format)
 */
@Override
public List<Issue> getIssues(ScanRequest request) {
    String apiUrl = String.format("%s/%s/%s/issues?state=all&per_page=%s", scmConfigOverrider.determineConfigApiUrl(properties, request), request.getNamespace(), request.getRepoName(), ISSUES_PER_PAGE);
    log.info("Executing getIssues GitHub API call: {}", apiUrl);
    List<Issue> issues = new ArrayList<>();
    HttpEntity<?> httpEntity = new HttpEntity<>(gitHubService.createAuthHeaders(request));
    ResponseEntity<com.checkmarx.flow.dto.github.Issue[]> response = restTemplate.exchange(apiUrl, HttpMethod.GET, httpEntity, com.checkmarx.flow.dto.github.Issue[].class);
    if (response.getBody() == null) {
        log.info("No issues found.");
        return new ArrayList<>();
    }
    for (com.checkmarx.flow.dto.github.Issue issue : response.getBody()) {
        Issue i = mapToIssue(issue);
        if (i != null && i.getTitle().startsWith(request.getProduct().getProduct())) {
            issues.add(i);
        }
    }
    String next = getNextURIFromHeaders(response.getHeaders(), "link", "next");
    while (next != null) {
        log.debug("Getting issue from {}", next);
        ResponseEntity<com.checkmarx.flow.dto.github.Issue[]> responsePage = restTemplate.exchange(next, HttpMethod.GET, httpEntity, com.checkmarx.flow.dto.github.Issue[].class);
        mapIssues(request, issues, responsePage);
        next = getNextURIFromHeaders(responsePage.getHeaders(), "link", "next");
    }
    return issues;
}
Also used : Issue(com.checkmarx.flow.dto.Issue) ArrayList(java.util.ArrayList)

Example 12 with Issue

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

the class GitHubIssueTracker method createIssue.

@Override
public Issue createIssue(ScanResults.XIssue resultIssue, ScanRequest request) {
    log.debug("Executing createIssue GitHub API call");
    String apiUrl = scmConfigOverrider.determineConfigApiUrl(properties, request).concat("/").concat(request.getNamespace().concat("/").concat(request.getRepoName())).concat("/issues");
    ResponseEntity<com.checkmarx.flow.dto.github.Issue> response;
    try {
        HttpEntity<String> httpEntity = new HttpEntity<>(getJSONCreateIssue(resultIssue, request).toString(), gitHubService.createAuthHeaders(request));
        response = restTemplate.exchange(apiUrl, HttpMethod.POST, httpEntity, com.checkmarx.flow.dto.github.Issue.class);
    } catch (HttpClientErrorException e) {
        log.error("Error occurred while creating GitHub Issue", e);
        if (e.getStatusCode().equals(HttpStatus.GONE)) {
            log.error("Issues are not enabled for this repository");
        }
        throw new MachinaRuntimeException(e);
    }
    return mapToIssue(response.getBody());
}
Also used : Issue(com.checkmarx.flow.dto.Issue) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) MachinaRuntimeException(com.checkmarx.flow.exception.MachinaRuntimeException)

Example 13 with Issue

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

the class GitLabIssueTracker method getIssues.

/**
 * Get list of issues associated with the project in GitLab
 */
@Override
public List<Issue> getIssues(ScanRequest request) {
    log.info("Executing getIssues GitLab API call");
    List<Issue> issues = new ArrayList<>();
    HttpEntity<Void> httpEntity = new HttpEntity<>(createAuthHeaders(request));
    String endpoint = scmConfigOverrider.determineConfigApiUrl(properties, request).concat(ISSUES_PATH);
    ResponseEntity<com.checkmarx.flow.dto.gitlab.Issue[]> response = restTemplate.exchange(endpoint, HttpMethod.GET, httpEntity, com.checkmarx.flow.dto.gitlab.Issue[].class, request.getRepoProjectId());
    if (response.getBody() == null) {
        return issues;
    }
    for (com.checkmarx.flow.dto.gitlab.Issue issue : response.getBody()) {
        Issue i = mapToIssue(issue);
        if (i != null && i.getTitle().startsWith(request.getProduct().getProduct())) {
            issues.add(i);
        }
    }
    String next = getNextURIFromHeaders(response.getHeaders(), "link", "next");
    while (next != null) {
        ResponseEntity<com.checkmarx.flow.dto.gitlab.Issue[]> responsePage = restTemplate.exchange(next, HttpMethod.GET, httpEntity, com.checkmarx.flow.dto.gitlab.Issue[].class);
        if (responsePage.getBody() != null) {
            for (com.checkmarx.flow.dto.gitlab.Issue issue : responsePage.getBody()) {
                Issue i = mapToIssue(issue);
                if (i != null && i.getTitle().startsWith(request.getProduct().getProduct())) {
                    issues.add(i);
                }
            }
        }
        next = getNextURIFromHeaders(responsePage.getHeaders(), "link", "next");
    }
    return issues;
}
Also used : Issue(com.checkmarx.flow.dto.Issue) ArrayList(java.util.ArrayList)

Example 14 with Issue

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

the class GitLabIssueTracker method mapToIssue.

private Issue mapToIssue(com.checkmarx.flow.dto.gitlab.Issue issue) {
    if (issue == null) {
        return null;
    }
    Issue i = new Issue();
    i.setBody(issue.getDescription());
    i.setTitle(issue.getTitle());
    i.setId(issue.getIid().toString());
    i.setLabels(issue.getLabels());
    i.setUrl(issue.getWebUrl());
    i.setState(issue.getState());
    return i;
}
Also used : Issue(com.checkmarx.flow.dto.Issue)

Example 15 with Issue

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

the class RallyIssueTracker method updateIssue.

/**
 * @param issue
 * @param resultIssue
 * @param request
 * @return
 * @throws MachinaException
 */
@Override
public Issue updateIssue(Issue issue, ScanResults.XIssue resultIssue, ScanRequest request) throws MachinaException {
    log.info("Executing updateIssue Rally API call");
    String json = getJSONCreateIssue(resultIssue, request);
    HttpEntity httpEntity = new HttpEntity<>(json, createAuthHeaders());
    ResponseEntity<com.checkmarx.flow.dto.rally.Issue> response;
    try {
        restTemplate.exchange(issue.getUrl(), HttpMethod.POST, httpEntity, com.checkmarx.flow.dto.rally.Issue.class);
        this.addComment(issue.getUrl(), "Issue still exists. ");
    } catch (HttpClientErrorException e) {
        log.error("Error updating issue.  This is likely due to the fact that another user has closed this issue. Adding comment");
        if (e.getStatusCode().equals(HttpStatus.GONE)) {
            throw new MachinaRuntimeException();
        }
        this.addComment(issue.getUrl(), "This issue still exists.  Please add label 'false-positive' to remove from scope of SAST results");
    }
    return issue;
}
Also used : Issue(com.checkmarx.flow.dto.Issue) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) MachinaRuntimeException(com.checkmarx.flow.exception.MachinaRuntimeException)

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