Skip to content

Commit e5e024e

Browse files
authored
Merge pull request #210 from internalsystemerror/ignore-new-majors-for-default
Better default branch rules
2 parents 5188a07 + 3cdb9f8 commit e5e024e

File tree

4 files changed

+106
-2
lines changed

4 files changed

+106
-2
lines changed

composer.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,18 @@
4848
"psr-4": {
4949
"Laminas\\AutomaticReleases\\Test\\Unit\\": "test/unit"
5050
}
51+
},
52+
"scripts": {
53+
"check": [
54+
"@cs-check",
55+
"@static-analysis",
56+
"@test"
57+
],
58+
"cs-check": "phpcs",
59+
"cs-fix": "phpcbf",
60+
"static-analysis": "psalm --shepherd --stats",
61+
"update-baseline": "psalm --update-baseline",
62+
"test": "phpunit --colors=always",
63+
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml"
5164
}
5265
}

feature/default-branch-switching.feature

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,49 @@ Feature: Default branch switching
4040
| 1.3.x |
4141
And the default branch should be "1.3.x"
4242

43-
Scenario: A pre-existing branch of a greater major release is set as default branch on release
43+
Scenario: A new minor branch on a pre-existing major branch is created and set as default branch on release
44+
Given following existing branches:
45+
| branch |
46+
| 1.0.x |
47+
| 1.1.x |
48+
| 1.2.x |
49+
| 2.0.x |
50+
And following open milestones:
51+
| name |
52+
| 2.0.0 |
53+
And the default branch is "1.0.x"
54+
When I close milestone "2.0.0"
55+
Then these should be the existing branches:
56+
| branch |
57+
| 1.0.x |
58+
| 1.1.x |
59+
| 1.2.x |
60+
| 2.0.x |
61+
| 2.1.x |
62+
And the default branch should be "2.1.x"
63+
64+
Scenario: A pre-existing branch of a new major release is not set as default branch on release
65+
Given following existing branches:
66+
| branch |
67+
| 1.0.x |
68+
| 1.1.x |
69+
| 1.2.x |
70+
| 2.0.x |
71+
And following open milestones:
72+
| name |
73+
| 1.2.0 |
74+
And the default branch is "1.0.x"
75+
When I close milestone "1.2.0"
76+
Then these should be the existing branches:
77+
| branch |
78+
| 1.0.x |
79+
| 1.1.x |
80+
| 1.2.x |
81+
| 1.3.x |
82+
| 2.0.x |
83+
And the default branch should be "1.3.x"
84+
85+
Scenario: A pre-existing minor branch of a greater major release is set as default branch on release
4486
Given following existing branches:
4587
| branch |
4688
| 1.0.x |

src/Git/Value/MergeTargetCandidateBranches.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ public function newestFutureReleaseBranchAfter(SemVerVersion $version): BranchNa
8282
$futureReleaseBranch = Vec\filter(
8383
Vec\reverse($this->sortedBranches),
8484
static function (BranchName $branch) use ($nextMinor): bool {
85-
return $nextMinor->lessThanEqual($branch->targetMinorReleaseVersion());
85+
$targetVersion = $branch->targetMinorReleaseVersion();
86+
87+
return ! $targetVersion->isNewMajorRelease() && $nextMinor->lessThanEqual($targetVersion);
8688
},
8789
);
8890

test/unit/Git/Value/MergeTargetCandidateBranchesTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,53 @@ public function testWillComputeFutureReleaseBranchFromCurrentRelease(): void
159159
);
160160
}
161161

162+
public function testWillIgnoreNewMajorBranchesWhenComputingFutureReleaseBranchName(): void
163+
{
164+
$branches = MergeTargetCandidateBranches::fromAllBranches(
165+
BranchName::fromName('2.0.x'),
166+
BranchName::fromName('1.1.x'),
167+
BranchName::fromName('1.4.x'),
168+
BranchName::fromName('1.2.x'),
169+
);
170+
171+
self::assertEquals(
172+
BranchName::fromName('1.4.x'),
173+
$branches->newestFutureReleaseBranchAfter(SemVerVersion::fromMilestoneName('1.0.0')),
174+
);
175+
self::assertEquals(
176+
BranchName::fromName('1.4.x'),
177+
$branches->newestFutureReleaseBranchAfter(SemVerVersion::fromMilestoneName('1.1.0')),
178+
);
179+
self::assertEquals(
180+
BranchName::fromName('1.4.x'),
181+
$branches->newestFutureReleaseBranchAfter(SemVerVersion::fromMilestoneName('1.1.1')),
182+
);
183+
self::assertEquals(
184+
BranchName::fromName('1.4.x'),
185+
$branches->newestFutureReleaseBranchAfter(SemVerVersion::fromMilestoneName('1.2.0')),
186+
);
187+
self::assertEquals(
188+
BranchName::fromName('1.4.x'),
189+
$branches->newestFutureReleaseBranchAfter(SemVerVersion::fromMilestoneName('1.3.0')),
190+
);
191+
self::assertEquals(
192+
BranchName::fromName('1.4.x'),
193+
$branches->newestFutureReleaseBranchAfter(SemVerVersion::fromMilestoneName('1.3.1')),
194+
);
195+
self::assertEquals(
196+
BranchName::fromName('1.5.x'),
197+
$branches->newestFutureReleaseBranchAfter(SemVerVersion::fromMilestoneName('1.4.0')),
198+
);
199+
self::assertEquals(
200+
BranchName::fromName('1.6.x'),
201+
$branches->newestFutureReleaseBranchAfter(SemVerVersion::fromMilestoneName('1.5.0')),
202+
);
203+
self::assertEquals(
204+
BranchName::fromName('2.1.x'),
205+
$branches->newestFutureReleaseBranchAfter(SemVerVersion::fromMilestoneName('2.0.0')),
206+
);
207+
}
208+
162209
public function testWillIgnoreMasterBranchWhenComputingFutureReleaseBranchName(): void
163210
{
164211
$branches = MergeTargetCandidateBranches::fromAllBranches(

0 commit comments

Comments
 (0)