Skip to content

Commit

Permalink
Fixed ADO on-prem workItem issue (#1400)
Browse files Browse the repository at this point in the history
* Fixed ADO on-prem workItem issue

* Update Dockerfile
  • Loading branch information
itsKedar authored Dec 10, 2024
1 parent 90062ca commit dd11a9a
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/main/java/com/checkmarx/flow/custom/ADOIssueTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import com.checkmarx.flow.utils.ScanUtils;
import com.checkmarx.sdk.config.Constants;
import com.checkmarx.sdk.dto.ScanResults;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.json.JSONArray;
Expand Down Expand Up @@ -281,7 +283,7 @@ else if(!ScanUtils.empty(request.getApplication())){
}

log.debug("Request body: {}", body);
HttpEntity<List<CreateWorkItemAttr>> httpEntity = new HttpEntity<>(body, ADOUtils.createPatchAuthHeaders(scmConfigOverrider.determineConfigToken(properties, request.getScmInstance())));
HttpEntity<String> httpEntity = new HttpEntity<>(getWorkItemObjectToString(body), ADOUtils.createPatchAuthHeaders(scmConfigOverrider.determineConfigToken(properties, request.getScmInstance())));
try {
ResponseEntity<String> response = restTemplate.exchange(endpoint, HttpMethod.POST, httpEntity, String.class);
String url = new JSONObject(response.getBody()).getJSONObject("_links").getJSONObject("self").getString("href");
Expand All @@ -293,6 +295,17 @@ else if(!ScanUtils.empty(request.getApplication())){
}
}

private String getWorkItemObjectToString(List<CreateWorkItemAttr> body){
ObjectMapper mapper = new ObjectMapper();
String requestBody = null;
try {
requestBody = mapper.writeValueAsString(body);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
return requestBody;
}

private StringBuilder getNamespaceTag(String namespace) {
return new StringBuilder().append(properties.getOwnerTagPrefix()).append(":").append(namespace);
}
Expand Down Expand Up @@ -382,7 +395,7 @@ public void closeIssue(Issue issue, ScanRequest request) {

List<CreateWorkItemAttr> body = new ArrayList<>(Collections.singletonList(state));

HttpEntity<List<CreateWorkItemAttr>> httpEntity = new HttpEntity<>(body, ADOUtils.createPatchAuthHeaders(scmConfigOverrider.determineConfigToken(properties, request.getScmInstance())));
HttpEntity<String> httpEntity = new HttpEntity<>(getWorkItemObjectToString(body), ADOUtils.createPatchAuthHeaders(scmConfigOverrider.determineConfigToken(properties, request.getScmInstance())));
try {
restTemplate.exchange(endpoint, HttpMethod.PATCH, httpEntity, String.class);
} catch (HttpClientErrorException e) {
Expand Down Expand Up @@ -410,7 +423,7 @@ public Issue updateIssue(Issue issue, ScanResults.XIssue resultIssue, ScanReques

List<CreateWorkItemAttr> body = new ArrayList<>(Arrays.asList(state, description));

HttpEntity<List<CreateWorkItemAttr>> httpEntity = new HttpEntity<>(body, ADOUtils.createPatchAuthHeaders(scmConfigOverrider.determineConfigToken(properties, request.getScmInstance())));
HttpEntity<String> httpEntity = new HttpEntity<>(getWorkItemObjectToString(body), ADOUtils.createPatchAuthHeaders(scmConfigOverrider.determineConfigToken(properties, request.getScmInstance())));
try {
restTemplate.exchange(endpoint, HttpMethod.PATCH, httpEntity, String.class);
} catch (HttpClientErrorException e) {
Expand Down

0 comments on commit dd11a9a

Please sign in to comment.