Skip to content

Commit

Permalink
ENH CMS 6 branch support
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Feb 20, 2024
1 parent ce20fd6 commit 7491dee
Show file tree
Hide file tree
Showing 2 changed files with 169 additions and 71 deletions.
82 changes: 64 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,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',
Expand All @@ -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()
Expand Down
158 changes: 105 additions & 53 deletions app/src/Processors/MergeUpsProcessor.php
Original file line number Diff line number Diff line change
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,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);
}
// 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($branches) == 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"] = '';
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);
Expand All @@ -148,52 +195,57 @@ public function process(bool $refetch): array
: '';
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}CmpUrl"] = '';
$arr["{$prefix}NextPatBrn"] = '';
$arr["{$prefix}MuPrevMin"] = '';
$arr["{$prefix}CmpUrlPrevMin"] = '';
$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"
$arr["{$prefix}Mu"] = $needsMergeUp ? 'needs-merge-up' : 'up-to-date';
$arr["{$prefix}CmpUrl"] = $needsMergeUp
? "https://github.com/$account/$repo/compare/$nextMinBrn...$nextPatBrn"
: '';
$arr["{$prefix}PrevMinBrn"] = "{$prevMinBrn}.x-dev";
$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;
$arr["{$prefix}MuPrevMin"] = $needsMergeUp ? 'needs-merge-up' : 'up-to-date';
$arr["{$prefix}CmpUrlPrevMin"] = $needsMergeUp
? "https://github.com/$account/$repo/compare/$nextPatBrn...$prevMinBrn"
: '';
$arr["{$prefix}PrevMinBrn"] = "{$prevMinBrn}.x-dev";
}
}
}
// get default branch
Expand Down

0 comments on commit 7491dee

Please sign in to comment.