Skip to content

Commit

Permalink
Merge pull request #107 from MicroFocus/MTiutiu/DefectOnPrem23.4
Browse files Browse the repository at this point in the history
Fixed issue with on prem id not beeing parsed correctly
  • Loading branch information
TiutiuMadalin authored Jan 18, 2024
2 parents 4119e9c + d56506f commit f31556b
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/main/java/com/microfocus/octane/gitlab/api/EventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,7 @@ private Response handleEvent(JSONObject event) {
OctaneSDK.getClients().forEach(client -> client.getEventsService().publishEvent(scmEvent));
}

String lastJobEvent = event.getJSONArray("builds").toList().stream().max((firstBuild, secondBuild) -> {
if ((Long) ((Map<?, ?>) firstBuild).get("id") > (Long) ((Map<?, ?>) secondBuild).get("id")) {
return 1;
}
return -1;
}).map(build -> (String) ((Map<?, ?>) build).get("name")).orElse("");
lastJobEvents.put(pipelineId, lastJobEvent);
lastJobEvents.put(pipelineId, getLastJobEventNameOfPipeline(event));

sentRoots.add(pipelineId);
} else {
Expand Down Expand Up @@ -782,4 +776,17 @@ private boolean isDeleteBranchEvent(JSONObject event) {
event.isNull("checkout_sha"));

}
private String getLastJobEventNameOfPipeline(JSONObject event) {
String lastJobEvent = "";
long maxId = 0;
JSONArray buildsArray = event.getJSONArray("builds");
for (int i = 0; i < buildsArray.length(); i++) {
if (buildsArray.getJSONObject(i).getLong("id") > maxId) {
maxId = buildsArray.getJSONObject(i).getLong("id");
lastJobEvent = buildsArray.getJSONObject(i).getString("name");
}
}
return lastJobEvent;
}

}

0 comments on commit f31556b

Please sign in to comment.