Skip to content

Better default branch rules #210

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

Merged
merged 3 commits into from
Sep 19, 2022
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
13 changes: 13 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,18 @@
"psr-4": {
"Laminas\\AutomaticReleases\\Test\\Unit\\": "test/unit"
}
},
"scripts": {
"check": [
"@cs-check",
"@static-analysis",
"@test"
],
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"static-analysis": "psalm --shepherd --stats",
"update-baseline": "psalm --update-baseline",
"test": "phpunit --colors=always",
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml"
}
}
50 changes: 25 additions & 25 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 43 additions & 1 deletion feature/default-branch-switching.feature
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,49 @@ Feature: Default branch switching
| 1.3.x |
And the default branch should be "1.3.x"

Scenario: A pre-existing branch of a greater major release is set as default branch on release
Scenario: A new minor branch on a pre-existing major branch is created and set as default branch on release
Given following existing branches:
| branch |
| 1.0.x |
| 1.1.x |
| 1.2.x |
| 2.0.x |
And following open milestones:
| name |
| 2.0.0 |
And the default branch is "1.0.x"
When I close milestone "2.0.0"
Then these should be the existing branches:
| branch |
| 1.0.x |
| 1.1.x |
| 1.2.x |
| 2.0.x |
| 2.1.x |
And the default branch should be "2.1.x"

Scenario: A pre-existing branch of a new major release is not set as default branch on release
Given following existing branches:
| branch |
| 1.0.x |
| 1.1.x |
| 1.2.x |
| 2.0.x |
And following open milestones:
| name |
| 1.2.0 |
And the default branch is "1.0.x"
When I close milestone "1.2.0"
Then these should be the existing branches:
| branch |
| 1.0.x |
| 1.1.x |
| 1.2.x |
| 1.3.x |
| 2.0.x |
And the default branch should be "1.3.x"

Scenario: A pre-existing minor branch of a greater major release is set as default branch on release
Given following existing branches:
| branch |
| 1.0.x |
Expand Down
4 changes: 3 additions & 1 deletion src/Git/Value/MergeTargetCandidateBranches.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ public function newestFutureReleaseBranchAfter(SemVerVersion $version): BranchNa
$futureReleaseBranch = Vec\filter(
Vec\reverse($this->sortedBranches),
static function (BranchName $branch) use ($nextMinor): bool {
return $nextMinor->lessThanEqual($branch->targetMinorReleaseVersion());
$targetVersion = $branch->targetMinorReleaseVersion();

return ! $targetVersion->isNewMajorRelease() && $nextMinor->lessThanEqual($targetVersion);
},
);

Expand Down
47 changes: 47 additions & 0 deletions test/unit/Git/Value/MergeTargetCandidateBranchesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,53 @@ public function testWillComputeFutureReleaseBranchFromCurrentRelease(): void
);
}

public function testWillIgnoreNewMajorBranchesWhenComputingFutureReleaseBranchName(): void
{
$branches = MergeTargetCandidateBranches::fromAllBranches(
BranchName::fromName('2.0.x'),
BranchName::fromName('1.1.x'),
BranchName::fromName('1.4.x'),
BranchName::fromName('1.2.x'),
);

self::assertEquals(
BranchName::fromName('1.4.x'),
$branches->newestFutureReleaseBranchAfter(SemVerVersion::fromMilestoneName('1.0.0')),
);
self::assertEquals(
BranchName::fromName('1.4.x'),
$branches->newestFutureReleaseBranchAfter(SemVerVersion::fromMilestoneName('1.1.0')),
);
self::assertEquals(
BranchName::fromName('1.4.x'),
$branches->newestFutureReleaseBranchAfter(SemVerVersion::fromMilestoneName('1.1.1')),
);
self::assertEquals(
BranchName::fromName('1.4.x'),
$branches->newestFutureReleaseBranchAfter(SemVerVersion::fromMilestoneName('1.2.0')),
);
self::assertEquals(
BranchName::fromName('1.4.x'),
$branches->newestFutureReleaseBranchAfter(SemVerVersion::fromMilestoneName('1.3.0')),
);
self::assertEquals(
BranchName::fromName('1.4.x'),
$branches->newestFutureReleaseBranchAfter(SemVerVersion::fromMilestoneName('1.3.1')),
);
self::assertEquals(
BranchName::fromName('1.5.x'),
$branches->newestFutureReleaseBranchAfter(SemVerVersion::fromMilestoneName('1.4.0')),
);
self::assertEquals(
BranchName::fromName('1.6.x'),
$branches->newestFutureReleaseBranchAfter(SemVerVersion::fromMilestoneName('1.5.0')),
);
self::assertEquals(
BranchName::fromName('2.1.x'),
$branches->newestFutureReleaseBranchAfter(SemVerVersion::fromMilestoneName('2.0.0')),
);
}

public function testWillIgnoreMasterBranchWhenComputingFutureReleaseBranchName(): void
{
$branches = MergeTargetCandidateBranches::fromAllBranches(
Expand Down