Skip to content

Commit

Permalink
Merge pull request #12 from silverstripe/pulls/main/cms6
Browse files Browse the repository at this point in the history
ENH CMS 6 branch support
  • Loading branch information
GuySartorelli authored Feb 22, 2024
2 parents ce20fd6 + 3be319d commit 2aba885
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 79 deletions.
8 changes: 7 additions & 1 deletion app/src/DataFetcher/Utils/OutputUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, "><a href=\"{$href}\" target=\"_blank\">link</a><", $html);
$extraText = '';
// hack for MergeUpsProcessor
if (strpos($href, ':needs-merge-up') !== false) {
$extraText = "needs-merge-up<br><br>";
$href = str_replace(':needs-merge-up', '', $href);
}
$html = str_replace($url, ">$extraText<a href=\"{$href}\" target=\"_blank\">link</a><", $html);
}
self::writeToFile($filename, $html);
}
Expand Down
83 changes: 65 additions & 18 deletions app/src/Processors/BuildsProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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];
Expand All @@ -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;
Expand All @@ -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',
Expand All @@ -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()
Expand Down
169 changes: 109 additions & 60 deletions app/src/Processors/MergeUpsProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -74,20 +74,25 @@ 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) {
continue;
}
$name = $branch->name;
if (preg_match($minorBrnRx, $name)) {
$branches[] = $name;
$minorBranches[] = $name;
}
if (preg_match($majorBrnRx, $name)) {
$majorBranches[] = $name;
}
}
$arr = [
Expand All @@ -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];
Expand All @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit 2aba885

Please sign in to comment.