From 5ac88fd6cf9a7293b05ad274ce639823c40d4497 Mon Sep 17 00:00:00 2001 From: Gary Lockett Date: Fri, 16 Sep 2022 00:53:09 +0100 Subject: [PATCH 1/3] add failing test for computing new major release branches as default Signed-off-by: Gary Lockett --- .../MergeTargetCandidateBranchesTest.php | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/test/unit/Git/Value/MergeTargetCandidateBranchesTest.php b/test/unit/Git/Value/MergeTargetCandidateBranchesTest.php index d75b6ee6..875b31dd 100644 --- a/test/unit/Git/Value/MergeTargetCandidateBranchesTest.php +++ b/test/unit/Git/Value/MergeTargetCandidateBranchesTest.php @@ -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( From 45e019537c08e1f7d5f561d6ba256c1c6b437115 Mon Sep 17 00:00:00 2001 From: Gary Lockett Date: Fri, 16 Sep 2022 00:54:52 +0100 Subject: [PATCH 2/3] ignore new majors when computing future release branches Signed-off-by: Gary Lockett --- composer.json | 13 +++++ composer.lock | 50 +++++++++---------- .../Value/MergeTargetCandidateBranches.php | 4 +- 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/composer.json b/composer.json index 9aa8a336..3541b214 100644 --- a/composer.json +++ b/composer.json @@ -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" } } diff --git a/composer.lock b/composer.lock index 584d6856..5b7ffd75 100644 --- a/composer.lock +++ b/composer.lock @@ -5658,16 +5658,16 @@ }, { "name": "sebastian/comparator", - "version": "4.0.6", + "version": "4.0.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "55f4261989e546dc112258c7a75935a81a7ce382" + "reference": "fa0f136dd2334583309d32b62544682ee972b51a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/55f4261989e546dc112258c7a75935a81a7ce382", - "reference": "55f4261989e546dc112258c7a75935a81a7ce382", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/fa0f136dd2334583309d32b62544682ee972b51a", + "reference": "fa0f136dd2334583309d32b62544682ee972b51a", "shasum": "" }, "require": { @@ -5720,7 +5720,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/comparator/issues", - "source": "https://github.com/sebastianbergmann/comparator/tree/4.0.6" + "source": "https://github.com/sebastianbergmann/comparator/tree/4.0.8" }, "funding": [ { @@ -5728,7 +5728,7 @@ "type": "github" } ], - "time": "2020-10-26T15:49:45+00:00" + "time": "2022-09-14T12:41:17+00:00" }, { "name": "sebastian/complexity", @@ -5918,16 +5918,16 @@ }, { "name": "sebastian/exporter", - "version": "4.0.4", + "version": "4.0.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "65e8b7db476c5dd267e65eea9cab77584d3cfff9" + "reference": "ac230ed27f0f98f597c8a2b6eb7ac563af5e5b9d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/65e8b7db476c5dd267e65eea9cab77584d3cfff9", - "reference": "65e8b7db476c5dd267e65eea9cab77584d3cfff9", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/ac230ed27f0f98f597c8a2b6eb7ac563af5e5b9d", + "reference": "ac230ed27f0f98f597c8a2b6eb7ac563af5e5b9d", "shasum": "" }, "require": { @@ -5983,7 +5983,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/exporter/issues", - "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.4" + "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.5" }, "funding": [ { @@ -5991,7 +5991,7 @@ "type": "github" } ], - "time": "2021-11-11T14:18:36+00:00" + "time": "2022-09-14T06:03:37+00:00" }, { "name": "sebastian/global-state", @@ -6346,16 +6346,16 @@ }, { "name": "sebastian/type", - "version": "3.1.0", + "version": "3.2.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/type.git", - "reference": "fb44e1cc6e557418387ad815780360057e40753e" + "reference": "fb3fe09c5f0bae6bc27ef3ce933a1e0ed9464b6e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/fb44e1cc6e557418387ad815780360057e40753e", - "reference": "fb44e1cc6e557418387ad815780360057e40753e", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/fb3fe09c5f0bae6bc27ef3ce933a1e0ed9464b6e", + "reference": "fb3fe09c5f0bae6bc27ef3ce933a1e0ed9464b6e", "shasum": "" }, "require": { @@ -6367,7 +6367,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.1-dev" + "dev-master": "3.2-dev" } }, "autoload": { @@ -6390,7 +6390,7 @@ "homepage": "https://github.com/sebastianbergmann/type", "support": { "issues": "https://github.com/sebastianbergmann/type/issues", - "source": "https://github.com/sebastianbergmann/type/tree/3.1.0" + "source": "https://github.com/sebastianbergmann/type/tree/3.2.0" }, "funding": [ { @@ -6398,7 +6398,7 @@ "type": "github" } ], - "time": "2022-08-29T06:55:37+00:00" + "time": "2022-09-12T14:47:03+00:00" }, { "name": "sebastian/version", @@ -6824,16 +6824,16 @@ }, { "name": "thecodingmachine/safe", - "version": "v2.2.3", + "version": "v2.3.0", "source": { "type": "git", "url": "https://github.com/thecodingmachine/safe.git", - "reference": "e454a3142d2197694d1fda291a4462ccd3f66e12" + "reference": "dc8df8f5047e7d3021a3f41f492dc99f8b3dc475" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thecodingmachine/safe/zipball/e454a3142d2197694d1fda291a4462ccd3f66e12", - "reference": "e454a3142d2197694d1fda291a4462ccd3f66e12", + "url": "https://api.github.com/repos/thecodingmachine/safe/zipball/dc8df8f5047e7d3021a3f41f492dc99f8b3dc475", + "reference": "dc8df8f5047e7d3021a3f41f492dc99f8b3dc475", "shasum": "" }, "require": { @@ -6956,9 +6956,9 @@ "description": "PHP core functions that throw exceptions instead of returning FALSE on error", "support": { "issues": "https://github.com/thecodingmachine/safe/issues", - "source": "https://github.com/thecodingmachine/safe/tree/v2.2.3" + "source": "https://github.com/thecodingmachine/safe/tree/v2.3.0" }, - "time": "2022-08-04T14:05:49+00:00" + "time": "2022-09-13T15:49:48+00:00" }, { "name": "theseer/tokenizer", diff --git a/src/Git/Value/MergeTargetCandidateBranches.php b/src/Git/Value/MergeTargetCandidateBranches.php index c8c2f610..1df65e22 100644 --- a/src/Git/Value/MergeTargetCandidateBranches.php +++ b/src/Git/Value/MergeTargetCandidateBranches.php @@ -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); }, ); From 3cdb9f8e3c8a519783e2feeb3d831a223c5d641b Mon Sep 17 00:00:00 2001 From: Gary Lockett Date: Fri, 16 Sep 2022 01:04:57 +0100 Subject: [PATCH 3/3] cover more default branch switching scenarios Signed-off-by: Gary Lockett --- feature/default-branch-switching.feature | 44 +++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/feature/default-branch-switching.feature b/feature/default-branch-switching.feature index f169a83f..d70aba3b 100644 --- a/feature/default-branch-switching.feature +++ b/feature/default-branch-switching.feature @@ -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 |