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;
}
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());
}
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;
}
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;
}
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;
}
Aggregations