Skip to content

Commit

Permalink
FIX Ensure mergeups iterates over inputs in a consistent order
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed May 22, 2024
1 parent f082c91 commit c6b8f0f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/BranchLogic.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ public static function getBranchesForMergeUp(
return [];
}

// Make sure the input is in a consistent order to ensure the following logic always gets the same results
// The order should be highest to lowest, so getMajorDiff correctly checks the highest branch first.
usort($repoBranches, 'version_compare');
$repoBranches = array_reverse($repoBranches);
usort($repoTags, 'version_compare');
$repoTags = array_reverse($repoTags);

$onlyMajorBranches = array_filter($repoBranches, fn ($branch) => ctype_digit((string) $branch));
$majorDiff = static::getMajorDiff($repoMetaData, $onlyMajorBranches, $defaultBranch, $composerJson);

Expand Down
33 changes: 31 additions & 2 deletions tests/BranchLogicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ public function provideGetBranchesForMergeUp(): array
'5.0.4',
'5.1.21',
'4.7.4',
'4.8.6'
'4.8.6',
],
'repoBranches' => [
'8',
Expand All @@ -741,7 +741,36 @@ public function provideGetBranchesForMergeUp(): array
'5.1',
'4',
'4.7',
'4.8'
'4.8',
],
'composerJson' => null,
'expected' => ['6.0', '6', '7.1', '7', '8'],
],
'Fluent with branches in the reverse order, which used to fail' => [
'githubRepository' => 'tractorcow-farm/silverstripe-fluent',
'defaultBranch' => '7',
'repoTags' => [
'4.8.6',
'4.7.4',
'5.1.21',
'5.0.4',
'6.0.5',
'7.1.0',
'7.0.1',
],
'repoBranches' => [
'4.8',
'4.7',
'4',
'5.1',
'5.0',
'5',
'6.0',
'6',
'7.1',
'7.0',
'7',
'8',
],
'composerJson' => null,
'expected' => ['6.0', '6', '7.1', '7', '8'],
Expand Down

0 comments on commit c6b8f0f

Please sign in to comment.