From 3be319d47ea38b603641cfe35387d27c029d5ba4 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Thu, 22 Feb 2024 12:06:16 +1300 Subject: [PATCH] ENH CMS 6 branch support --- app/src/DataFetcher/Utils/OutputUtil.php | 8 +- app/src/Processors/BuildsProcessor.php | 83 ++++++++--- app/src/Processors/MergeUpsProcessor.php | 169 +++++++++++++++-------- 3 files changed, 181 insertions(+), 79 deletions(-) diff --git a/app/src/DataFetcher/Utils/OutputUtil.php b/app/src/DataFetcher/Utils/OutputUtil.php index 639a09a..f28f2a9 100644 --- a/app/src/DataFetcher/Utils/OutputUtil.php +++ b/app/src/DataFetcher/Utils/OutputUtil.php @@ -63,7 +63,13 @@ public static function outputHtmlTable(string $filename, array $data, string $sc preg_match_all($rx, $html, $m); foreach ($m[0] as $url) { $href = trim($url, '><'); - $html = str_replace($url, ">link<", $html); + $extraText = ''; + // hack for MergeUpsProcessor + if (strpos($href, ':needs-merge-up') !== false) { + $extraText = "needs-merge-up

"; + $href = str_replace(':needs-merge-up', '', $href); + } + $html = str_replace($url, ">$extraTextlink<", $html); } self::writeToFile($filename, $html); } diff --git a/app/src/Processors/BuildsProcessor.php b/app/src/Processors/BuildsProcessor.php index 3c1dfc1..a62fa98 100644 --- a/app/src/Processors/BuildsProcessor.php +++ b/app/src/Processors/BuildsProcessor.php @@ -66,9 +66,10 @@ public function process(bool $refetch): array continue; } - // get minor branches available - $branches = []; + $minorBranches = []; + $majorBranches = []; $minorBrnRx = '#^([1-9])\.([0-9]+)$#'; + $majorBrnRx = '#^([1-9])$#'; $path = "/repos/$account/$repo/branches?paginate=0&per_page=100"; $json = $requester->fetch($path, '', $account, $repo, $refetch); foreach ($json->root ?? [] as $branch) { @@ -77,10 +78,13 @@ public function process(bool $refetch): array } $name = $branch->name; if (preg_match($minorBrnRx, $name)) { - $branches[] = $name; + $minorBranches[] = $name; + } + if (preg_match($majorBrnRx, $name)) { + $majorBranches[] = $name; } } - usort($branches, function ($a, $b) use ($minorBrnRx) { + usort($minorBranches, function ($a, $b) use ($minorBrnRx) { preg_match($minorBrnRx, $a, $ma); preg_match($minorBrnRx, $b, $mb); $n = (int) $ma[1] <=> (int) $mb[1]; @@ -89,25 +93,54 @@ public function process(bool $refetch): array } return (int) $ma[2] <=> (int) $mb[2]; }); - $branches = array_reverse($branches); - // quick hack for linkfield which only has a `4` branch while it's in dev - // delete this onece linkfield is supported and stable - if (count($branches) == 0 && $repo == 'silverstripe-linkfield') { - $branches = ['4.0']; - } - if (count($branches) == 0) { - continue; + usort($majorBranches, function ($a, $b) use ($majorBrnRx) { + preg_match($majorBrnRx, $a, $ma); + preg_match($majorBrnRx, $b, $mb); + return (int) $ma[1] <=> (int) $mb[1]; + }); + $minorBranches = array_reverse($minorBranches); + $majorBranches = array_reverse($majorBranches); + // remove any < 4 minor and major branches for linkfield + if ($repo == 'silverstripe-linkfield') { + $minorBranches = array_filter($minorBranches, function ($branch) { + return (int) $branch >= 4; + }); + $majorBranches = array_filter($majorBranches, function ($branch) { + return (int) $branch >= 4; + }); + // hack for linkfield which only has a `4` branch while it's in dev + // this is done so that `$minorBranches[0]` below passes + if (count($minorBranches) == 0) { + $minorBranches = ['4.0']; + } } - $nextPatBrn = $branches[0]; // 4.7 - $nextMinBrn = $nextPatBrn[0]; // 4 - $pmMinBrn = $nextMinBrn - 1; // 3 + $nextPatBrn = ''; + $nextMinBrn = ''; + $pmMinBrn = ''; $pmPatBrn = ''; + $currMajBrn = ''; + $nextMajBrn = ''; + if (count($minorBranches)) { + $nextPatBrn = count($minorBranches) ? $minorBranches[0] : ''; // 4.7 + $nextMinBrn = substr($nextPatBrn, 0, 1); // 4 + $pmMinBrn = $nextMinBrn - 1; // 3 + $currMajBrn = preg_replace($minorBrnRx, '$1', $nextPatBrn); + if (count($majorBranches) && $currMajBrn != $majorBranches[0]) { + $nextMajBrn = $majorBranches[0]; // 5 + } + } else { + if (count($majorBranches)) { + $currMajBrn = $majorBranches[0]; + } else { + continue; + } + } // see if there are any branches that match the previous minor branch - if (!empty(array_filter($branches, function ($branch) use ($pmMinBrn) { + if (!empty(array_filter($minorBranches, function ($branch) use ($pmMinBrn) { list($major,) = explode('.', $branch); return $major == $pmMinBrn; }))) { - foreach ($branches as $branch) { + foreach ($minorBranches as $branch) { if (strpos($branch, "$pmMinBrn.") === 0) { if ($pmPatBrn == '') { $pmPatBrn = $branch; @@ -118,6 +151,14 @@ public function process(bool $refetch): array } }; + // remove any < 4 branches for linkfield + // note: this is not duplicated code from the other silverstripe-linkfield conditional above + if ($repo == 'silverstripe-linkfield') { + if ($pmMinBrn == '3') { + $pmMinBrn = ''; + } + } + $skipCurrentMajor = false; if (in_array($repo, [ 'silverstripe-postgresql', @@ -135,8 +176,14 @@ public function process(bool $refetch): array 'account' => $account, 'repo' => $repo, - // current major + // next major + 'nextMajBrn' => $nextMajBrn ? ($nextMajBrn . '.x-dev') : '', + 'nextMajGhaStat' => $nextMajBrn == '' + ? $this->buildBlankBadge() + : $this->getGhaStatusBadge($requester, $refetch, $account, $repo, $nextMajBrn, $runName), + // current major + '| ' => '', 'nextMinBrn' => $skipCurrentMajor ? '' : $nextMinBrn . '.x-dev', 'nextMinGhaStat' => $skipCurrentMajor ? $this->buildBlankBadge() diff --git a/app/src/Processors/MergeUpsProcessor.php b/app/src/Processors/MergeUpsProcessor.php index cf39cd3..51993d0 100644 --- a/app/src/Processors/MergeUpsProcessor.php +++ b/app/src/Processors/MergeUpsProcessor.php @@ -27,11 +27,11 @@ public function getHtmlTableScript(): string var tds = document.getElementsByTagName('td'); for (var i = 0; i < tds.length; i++) { var td = tds[i]; - var v = td.innerText; + var v = td.innerHTML; var c = ''; - if (['needs-merge-up'].indexOf(v) != -1) { + if (v.indexOf('needs-merge-up') != -1) { c = 'khaki'; - } else if (['up-to-date'].indexOf(v) != -1) { + } else if (v.indexOf('up-to-date') != -1) { c = 'palegreen'; } if (c) { @@ -74,12 +74,14 @@ public function process(bool $refetch): array } $minorBrnRx = '#^([1-9])\.([0-9]+)$#'; + $majorBrnRx = '#^([1-9])$#'; $rows = []; foreach ($varsList as $vars) { list($account, $repo) = $vars; // get branches available - $branches = []; + $minorBranches = []; + $majorBranches = []; $json = $requester->fetch("/repos/$account/$repo/branches", '', $account, $repo, $refetch); foreach ($json->root ?? [] as $branch) { if (!$branch) { @@ -87,7 +89,10 @@ public function process(bool $refetch): array } $name = $branch->name; if (preg_match($minorBrnRx, $name)) { - $branches[] = $name; + $minorBranches[] = $name; + } + if (preg_match($majorBrnRx, $name)) { + $majorBranches[] = $name; } } $arr = [ @@ -96,9 +101,9 @@ public function process(bool $refetch): array 'muStat' => '', ]; if ($repo == 'silverstripe-frameworktest') { - $branches = ['1', '0.4']; + $minorBranches = ['1', '0.4']; } else { - usort($branches, function ($a, $b) use ($minorBrnRx) { + usort($minorBranches, function ($a, $b) use ($minorBrnRx) { preg_match($minorBrnRx, $a, $ma); preg_match($minorBrnRx, $b, $mb); $n = (int) $ma[1] <=> (int) $mb[1]; @@ -107,32 +112,73 @@ public function process(bool $refetch): array } return (int) $ma[2] <=> (int) $mb[2]; }); - $branches = array_reverse($branches); + usort($majorBranches, function ($a, $b) use ($majorBrnRx) { + preg_match($majorBrnRx, $a, $ma); + preg_match($majorBrnRx, $b, $mb); + return (int) $ma[1] <=> (int) $mb[1]; + }); + $minorBranches = array_reverse($minorBranches); + $majorBranches = array_reverse($majorBranches); } - if (count($branches) == 0) { + // remove any < 4 minor and major branches for linkfield + if ($repo == 'silverstripe-linkfield') { + $minorBranches = array_filter($minorBranches, function ($branch) { + return (int) $branch >= 4; + }); + $majorBranches = array_filter($majorBranches, function ($branch) { + return (int) $branch >= 4; + }); + // hack for linkfield which only has a `4` branch while it's in dev + // this is done so that `$minorBranches[0]` below passes + if (count($minorBranches) == 0) { + $minorBranches = ['4.0']; + } + } + if (count($minorBranches) == 0) { continue; } - $nextPatBrn = $branches[0]; + $nextPatBrn = $minorBranches[0]; $nextMinBrn = substr($nextPatBrn, 0, 1); + $nextMajBrn = $majorBranches[0] != $nextMinBrn ? $majorBranches[0] : ''; $blankMu = 'nothing'; - // 'cm' = current major, 'xm' = cross major, 'pm' = prev major - foreach (['cm', 'xm', 'pm'] as $prefix) { + // 'nm' = next major, + // 'xnm' = cross next major + // 'cm' = current major + // 'xm' = cross major + // 'pm' = prev major + foreach (['nm', 'xnm', 'cm', 'xm', 'pm'] as $prefix) { // cross major - if ($prefix == 'xm') { + if ($prefix == 'xnm') { $arr["|"] = ''; $arr["{$prefix}Mu"] = $blankMu; - $arr["{$prefix}CmpUrl"] = ''; + // $arr["{$prefix}CmpUrl"] = ''; + if ($nextMajBrn == '') { + continue; + } + $mergeInto = $nextMajBrn; + $path = "/repos/$account/$repo/compare/$nextMajBrn...$nextMinBrn"; + $json = $requester->fetch($path, '', $account, $repo, $refetch); + $needsMergeUp = ($json->root->ahead_by ?? 0) > 0; + $cmp = $needsMergeUp + ? "https://github.com/$account/$repo/compare/$nextMajBrn...$nextMinBrn:needs-merge-up" + : ''; + $arr["{$prefix}Mu"] = $needsMergeUp ? $cmp : 'up-to-date'; + continue; + } + if ($prefix == 'xm') { + $arr["| "] = ''; + $arr["{$prefix}Mu"] = $blankMu; // merge into next-patch if it ends in *.0 - e.g. 5.0...4 // else merge into prev-minor e.g. - e.g. 5.1...4, if next-patch is 5.2 - $mergeInto = $branches[0]; + $mergeInto = $minorBranches[0]; if (!preg_match('#\.0$#', $mergeInto)) { $mergeInto -= 0.1; $mergeInto = sprintf('%.1f', $mergeInto); } $lastMajor = $nextMinBrn - 1; - $bs = array_filter($branches, function ($branch) use ($lastMajor) { + $bs = array_filter($minorBranches, function ($branch) use ($lastMajor) { return substr($branch, 0, 1) == $lastMajor; }); $bs = array_values($bs); @@ -142,58 +188,61 @@ public function process(bool $refetch): array $path = "/repos/$account/$repo/compare/$mergeInto...$lastMajor"; $json = $requester->fetch($path, '', $account, $repo, $refetch); $needsMergeUp = ($json->root->ahead_by ?? 0) > 0; - $arr["{$prefix}Mu"] = $needsMergeUp ? 'needs-merge-up' : 'up-to-date'; - $arr["{$prefix}CmpUrl"] = $needsMergeUp - ? "https://github.com/$account/$repo/compare/$mergeInto...$lastMajor" + $cmp = $needsMergeUp + ? "https://github.com/$account/$repo/compare/$mergeInto...$lastMajor:needs-merge-up" : ''; + $arr["{$prefix}Mu"] = $needsMergeUp ? $cmp : 'up-to-date'; continue; } - // current major, previous major - if ($prefix == 'cm') { - $arr["| "] = ''; - } - if ($prefix == 'pm') { - $nextMinBrn = $nextMinBrn - 1; - $arr["| "] = ''; - } - $arr["{$prefix}NextMinBrn"] = ''; - $arr["{$prefix}Mu"] = $blankMu; - $arr["{$prefix}CmpUrl"] = ''; - $arr["{$prefix}NextPatBrn"] = ''; - $arr["{$prefix}MuPrevMin"] = ''; - $arr["{$prefix}CmpUrlPrevMin"] = ''; - $arr["{$prefix}PrevMinBrn"] = ''; - $bs = array_filter($branches, function ($branch) use ($nextMinBrn) { - return substr($branch, 0, 1) == $nextMinBrn; - }); - $bs = array_values($bs); - if (count($bs) == 0) { - continue; + // next major, current major, previous major + if ($prefix == 'nm') { + $arr["nmBrn"] = $nextMajBrn ? "{$nextMajBrn}.x-dev" : ''; } - $nextPatBrn = $bs[0]; - $prevMinBrn = count($bs) > 1 ? $bs[1] : ''; - - // 4...4.12 - $arr["{$prefix}NextMinBrn"] = "{$nextMinBrn}.x-dev"; - $path = "/repos/$account/$repo/compare/$nextMinBrn...$nextPatBrn"; - $json = $requester->fetch($path, '', $account, $repo, $refetch); - $needsMergeUp = ($json->root->ahead_by ?? 0) > 0; - $arr["{$prefix}Mu"] = $needsMergeUp ? 'needs-merge-up' : 'up-to-date'; - $arr["{$prefix}CmpUrl"] = $needsMergeUp - ? "https://github.com/$account/$repo/compare/$nextMinBrn...$nextPatBrn" - : ''; - $arr["{$prefix}NextPatBrn"] = "{$nextPatBrn}.x-dev"; + if ($prefix == 'cm' || $prefix == 'pm') { + if ($prefix == 'cm') { + $arr["| "] = ''; + } + if ($prefix == 'pm') { + $nextMinBrn = $nextMinBrn - 1; + $arr["| "] = ''; + } + $arr["{$prefix}NextMinBrn"] = ''; + $arr["{$prefix}Mu"] = $blankMu; + $arr["{$prefix}NextPatBrn"] = ''; + $arr["{$prefix}MuPrevMin"] = ''; + $arr["{$prefix}PrevMinBrn"] = ''; + $bs = array_filter($minorBranches, function ($branch) use ($nextMinBrn) { + return substr($branch, 0, 1) == $nextMinBrn; + }); + $bs = array_values($bs); + if (count($bs) == 0) { + continue; + } + $nextPatBrn = $bs[0]; + $prevMinBrn = count($bs) > 1 ? $bs[1] : ''; - // 4.12...4.11 - if ($prevMinBrn) { - $path = "/repos/$account/$repo/compare/$nextPatBrn...$prevMinBrn"; + // 4...4.12 + $arr["{$prefix}NextMinBrn"] = "{$nextMinBrn}.x-dev"; + $path = "/repos/$account/$repo/compare/$nextMinBrn...$nextPatBrn"; $json = $requester->fetch($path, '', $account, $repo, $refetch); $needsMergeUp = ($json->root->ahead_by ?? 0) > 0; - $arr["{$prefix}MuPrevMin"] = $needsMergeUp ? 'needs-merge-up' : 'up-to-date'; - $arr["{$prefix}CmpUrlPrevMin"] = $needsMergeUp - ? "https://github.com/$account/$repo/compare/$nextPatBrn...$prevMinBrn" + $cmp = $needsMergeUp + ? "https://github.com/$account/$repo/compare/$nextMinBrn...$nextPatBrn:needs-merge-up" : ''; - $arr["{$prefix}PrevMinBrn"] = "{$prevMinBrn}.x-dev"; + $arr["{$prefix}Mu"] = $needsMergeUp ? $cmp : 'up-to-date'; + $arr["{$prefix}NextPatBrn"] = "{$nextPatBrn}.x-dev"; + + // 4.12...4.11 + if ($prevMinBrn) { + $path = "/repos/$account/$repo/compare/$nextPatBrn...$prevMinBrn"; + $json = $requester->fetch($path, '', $account, $repo, $refetch); + $needsMergeUp = ($json->root->ahead_by ?? 0) > 0; + $cmp = $needsMergeUp + ? "https://github.com/$account/$repo/compare/$nextPatBrn...$prevMinBrn:needs-merge-up" + : ''; + $arr["{$prefix}MuPrevMin"] = $needsMergeUp ? $cmp : 'up-to-date'; + $arr["{$prefix}PrevMinBrn"] = "{$prevMinBrn}.x-dev"; + } } } // get default branch