Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX Ensure mergeups iterates over inputs in a consistent order #34

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading