Skip to content

Commit

Permalink
Merge pull request #32 from creative-commoners/pulls/1.0/linkfield
Browse files Browse the repository at this point in the history
ENH Prevent merge-up from linkfield v3
  • Loading branch information
GuySartorelli authored Apr 1, 2024
2 parents e2c573b + 0559e71 commit 16c3a87
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,13 @@ steps:
```
This action has no inputs
## Preventing merge-ups from specific major versions of a repository
update `DO_NOT_MERGE_UP_FROM_MAJOR` in `funcs.php`. For example to prevent merging up from the `3` major version of `silverstripe/silverstripe-linkfield`:

```php
const DO_NOT_MERGE_UP_FROM_MAJOR = [
'silverstripe/silverstripe-linkfield' => '3',
];
```
15 changes: 15 additions & 0 deletions funcs.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
// This should always match default branch of silverstripe/framework
const CURRENT_CMS_MAJOR = 5;

// List of major branches to not merge up from
// Add repos in here where the repo was previously unsupported
// Note these are actual major branches, not CMS major versions
const DO_NOT_MERGE_UP_FROM_MAJOR = [
'silverstripe/silverstripe-linkfield' => '3',
];

function branches(
string $defaultBranch,
string $minimumCmsMajor,
Expand Down Expand Up @@ -152,6 +159,14 @@ function branches(
}
$foundMinorInMajor[$major] = true;
}

// remove any branches less than or equal to DO_NOT_MERGE_UP_FROM_MAJOR
if (isset(DO_NOT_MERGE_UP_FROM_MAJOR[$githubRepository])) {
$doNotMergeUpFromMajor = DO_NOT_MERGE_UP_FROM_MAJOR[$githubRepository];
$branches = array_filter($branches, function($branch) use ($doNotMergeUpFromMajor) {
return version_compare($branch, $doNotMergeUpFromMajor, '>');
});
}

// reverse the array so that oldest is first
$branches = array_reverse($branches);
Expand Down
61 changes: 61 additions & 0 deletions tests/BranchesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,67 @@ public function provideBranches()
]
EOT,
],
'silverstripe-linkfield beta' => [
'expected' => ['4.0', '4', '5'],
'defaultBranch' => '4',
'minimumCmsMajor' => '4',
'githubRepository' => 'silverstripe/silverstripe-linkfield',
'composerJson' => <<<EOT
{
"require": {
"silverstripe/framework": "^5"
}
}
EOT,
'branchesJson' => <<<EOT
[
{"name": "1"},
{"name": "2"},
{"name": "3"},
{"name": "4"},
{"name": "4.0"},
{"name": "5"}
]
EOT,
'tagsJson' => <<<EOT
[
{"name": "3.0.0-beta1"},
{"name": "2.0.0"},
{"name": "1.0.0"}
]
EOT,
],
'silverstripe-linkfield stable' => [
'expected' => ['4.0', '4', '5'],
'defaultBranch' => '4',
'minimumCmsMajor' => '4',
'githubRepository' => 'silverstripe/silverstripe-linkfield',
'composerJson' => <<<EOT
{
"require": {
"silverstripe/framework": "^5"
}
}
EOT,
'branchesJson' => <<<EOT
[
{"name": "1"},
{"name": "2"},
{"name": "3"},
{"name": "4"},
{"name": "4.0"},
{"name": "5"}
]
EOT,
'tagsJson' => <<<EOT
[
{"name": "4.0.0"},
{"name": "3.0.0"},
{"name": "2.0.0"},
{"name": "1.0.0"}
]
EOT,
],
];
}
}

0 comments on commit 16c3a87

Please sign in to comment.