better way to find last push

This commit is contained in:
Sebastian Frank 2019-06-13 12:39:12 +02:00
parent a1015c2db7
commit 7ad311892c
Signed by: apairon
GPG Key ID: 7270D06DDA7FE8C3

View File

@ -43,17 +43,18 @@ if (COCKPIT_ADMIN && !COCKPIT_API_REQUEST) {
curl_close($ch);
$unfiltered_deploys = json_decode($unfiltered_deploys);
$build = $settings['build'];
$last_push = '';
$last_promote = '';
if ($unfiltered_deploys && is_array($unfiltered_deploys)) {
foreach($unfiltered_deploys as $deploy) {
if ($deploy->{target} == $branch && ($deploy->event == 'push' || ($deploy->event == 'promote' && $deploy->deploy_to == $settings['target']))) {
// find latest successful build
if (!$build) {
if ($deploy->event == 'push' && $deploy->status == 'success') {
$build = $deploy->number;
} else {
$build = $deploy->parent;
}
if (!$last_push && $deploy->event == 'push' && $deploy->status == 'success') {
$last_push = $deploy->number;
} elseif (!$last_promote) {
$last_promote = $deploy->parent;
}
$limit--;
if ($limit>0) {
$deploys[] = $deploy;
@ -62,6 +63,10 @@ if (COCKPIT_ADMIN && !COCKPIT_API_REQUEST) {
}
}
if (!$build) {
$build = $last_push ? $last_push : $last_promote;
}
// Parse dates and check if any deploy is on building status.
$building = false;
foreach ($deploys as $idx => $deploy) {