From f41f67582fed9501390676f0c7c2479e3d2e603f Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 20 Feb 2024 12:49:22 +1300 Subject: [PATCH] ENH CMS 6 branch support --- app/src/Processors/BuildsProcessor.php | 82 +++++++++++++++++----- app/src/Processors/MergeUpsProcessor.php | 86 +++++++++++++++++++----- 2 files changed, 134 insertions(+), 34 deletions(-) diff --git a/app/src/Processors/BuildsProcessor.php b/app/src/Processors/BuildsProcessor.php index 3c1dfc1..bce03b2 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,13 @@ public function process(bool $refetch): array } }; + // remove any < 4 branches for linkfield + if ($repo == 'silverstripe-linkfield') { + if ($pmMinBrn == '3') { + $pmMinBrn = ''; + } + } + $skipCurrentMajor = false; if (in_array($repo, [ 'silverstripe-postgresql', @@ -135,8 +175,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..86da116 100644 --- a/app/src/Processors/MergeUpsProcessor.php +++ b/app/src/Processors/MergeUpsProcessor.php @@ -74,12 +74,18 @@ public function process(bool $refetch): array } $minorBrnRx = '#^([1-9])\.([0-9]+)$#'; + $majorBrnRx = '#^([1-9])$#'; $rows = []; foreach ($varsList as $vars) { list($account, $repo) = $vars; + if ($repo != 'silverstripe-admin') { // silverstripe-linkfield + continue; + } + // 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 +93,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 +105,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 +116,74 @@ 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) { + if (count($minorBranches) == 0) { continue; } + // 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]; + $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"] = ''; + 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; + $arr["{$prefix}Mu"] = $needsMergeUp ? 'needs-merge-up' : 'up-to-date'; + $arr["{$prefix}CmpUrl"] = $needsMergeUp + ? "https://github.com/$account/$repo/compare/$nextMajBrn...$nextMinBrn" + : ''; + continue; + } + if ($prefix == 'xm') { + $arr["| "] = ''; + $arr["{$prefix}Mu"] = $blankMu; + $arr["{$prefix}CmpUrl"] = ''; // 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); @@ -148,13 +199,16 @@ public function process(bool $refetch): array : ''; continue; } - // current major, previous major + // next major, current major, previous major + if ($prefix == 'nm') { + $arr["| "] = ''; + } if ($prefix == 'cm') { - $arr["| "] = ''; + $arr["| "] = ''; } if ($prefix == 'pm') { $nextMinBrn = $nextMinBrn - 1; - $arr["| "] = ''; + $arr["| "] = ''; } $arr["{$prefix}NextMinBrn"] = ''; $arr["{$prefix}Mu"] = $blankMu; @@ -163,7 +217,7 @@ public function process(bool $refetch): array $arr["{$prefix}MuPrevMin"] = ''; $arr["{$prefix}CmpUrlPrevMin"] = ''; $arr["{$prefix}PrevMinBrn"] = ''; - $bs = array_filter($branches, function ($branch) use ($nextMinBrn) { + $bs = array_filter($minorBranches, function ($branch) use ($nextMinBrn) { return substr($branch, 0, 1) == $nextMinBrn; }); $bs = array_values($bs);