Skip to content

Commit 79bffe1

Browse files
schlesseraclaude
andcommitted
Cover the tag checks of release generate with unit tests
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 70f5cc8 commit 79bffe1

3 files changed

Lines changed: 58 additions & 8 deletions

File tree

‎.maintenance/src/Release_Command.php‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ static function ( $tag ) {
188188
},
189189
GitHub::get_tags( $repo )
190190
);
191-
$latest = Release_Plan::latest_version_tag( $tags );
192191

193192
$milestones = GitHub::get_project_milestones( $repo );
194193

@@ -207,23 +206,22 @@ static function ( $milestone ) use ( $only_milestone ) {
207206

208207
$candidates = [];
209208
foreach ( $milestones as $milestone ) {
210-
$version = ltrim( $milestone->title, 'v' );
211-
212209
WP_CLI::log( "Checking milestone '{$milestone->title}'..." );
213210

214-
if ( Release_Plan::has_tag( $releases, $version ) ) {
211+
$tag_status = Release_Plan::get_tag_status( $milestone->title, $releases, $tags );
212+
213+
if ( Release_Plan::RELEASED === $tag_status ) {
215214
WP_CLI::log( "Found a matching release, skipping milestone '{$milestone->title}'..." );
216215
continue;
217216
}
218217

219-
if ( Release_Plan::has_tag( $tags, $version ) ) {
218+
if ( Release_Plan::TAGGED === $tag_status ) {
220219
WP_CLI::warning( "Skipping milestone '{$milestone->title}' as it was already tagged. Its pull requests need a new milestone." );
221220
continue;
222221
}
223222

224-
if ( ! Bundle::is_version( $version )
225-
|| ( null !== $latest && ! version_compare( $version, ltrim( $latest, 'v' ), '>' ) ) ) {
226-
WP_CLI::warning( "Skipping milestone '{$milestone->title}' as it is not a version newer than {$latest}." );
223+
if ( Release_Plan::NOT_NEWER === $tag_status ) {
224+
WP_CLI::warning( "Skipping milestone '{$milestone->title}' as it is not a version newer than the latest tag." );
227225
continue;
228226
}
229227

‎.maintenance/src/Release_Plan.php‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ final class Release_Plan {
1414
const READY = 'ready';
1515
const NEEDS_HUMAN = 'needs_human';
1616

17+
const RELEASED = 'released';
18+
const TAGGED = 'tagged';
19+
const NOT_NEWER = 'not_newer';
20+
const TAGGABLE = 'taggable';
21+
1722
/**
1823
* Authors of routine pull requests that do not call for a release by
1924
* themselves, unless a maintainer added them to a milestone.
@@ -177,6 +182,37 @@ public static function latest_version_tag( array $tags ) {
177182
return $latest;
178183
}
179184

185+
/**
186+
* Tells whether a milestone can still be tagged: not when it has a
187+
* release or a tag already, or when it is not a version newer than the
188+
* latest tag.
189+
*
190+
* @param string $title Milestone title.
191+
* @param string[] $releases Tag names of the published releases.
192+
* @param string[] $tags Names of all tags.
193+
*
194+
* @return string One of RELEASED, TAGGED, NOT_NEWER or TAGGABLE.
195+
*/
196+
public static function get_tag_status( $title, array $releases, array $tags ) {
197+
$version = ltrim( $title, 'v' );
198+
$latest = self::latest_version_tag( $tags );
199+
200+
if ( self::has_tag( $releases, $version ) ) {
201+
return self::RELEASED;
202+
}
203+
204+
if ( self::has_tag( $tags, $version ) ) {
205+
return self::TAGGED;
206+
}
207+
208+
if ( ! Bundle::is_version( $version )
209+
|| ( null !== $latest && ! version_compare( $version, ltrim( $latest, 'v' ), '>' ) ) ) {
210+
return self::NOT_NEWER;
211+
}
212+
213+
return self::TAGGABLE;
214+
}
215+
180216
/**
181217
* Checks whether a version has been tagged, with or without a leading 'v'.
182218
*

‎tests/ReleasePlanTest.php‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,20 @@ public function test_a_repository_without_version_tags_needs_a_decision(): void
162162
$this->assertSame( Release_Plan::NEEDS_HUMAN, $plan['status'] );
163163
$this->assertSame( [ 'no_version_tag' => [] ], $this->blockers( $plan ) );
164164
}
165+
166+
public function test_tag_status_of_a_milestone(): void {
167+
$releases = [ 'v1.0.1' ];
168+
$tags = [ 'v1.0.1', 'v1.0.2', 'v1.0.3' ];
169+
170+
$this->assertSame( Release_Plan::RELEASED, Release_Plan::get_tag_status( '1.0.1', $releases, $tags ) );
171+
$this->assertSame( Release_Plan::TAGGED, Release_Plan::get_tag_status( '1.0.3', $releases, $tags ) );
172+
$this->assertSame( Release_Plan::NOT_NEWER, Release_Plan::get_tag_status( '1.0.0', $releases, $tags ) );
173+
$this->assertSame( Release_Plan::NOT_NEWER, Release_Plan::get_tag_status( 'Future', $releases, $tags ) );
174+
$this->assertSame( Release_Plan::TAGGABLE, Release_Plan::get_tag_status( '1.0.4', $releases, $tags ) );
175+
$this->assertSame( Release_Plan::TAGGABLE, Release_Plan::get_tag_status( 'v1.1.0', $releases, $tags ) );
176+
}
177+
178+
public function test_a_first_release_can_be_tagged(): void {
179+
$this->assertSame( Release_Plan::TAGGABLE, Release_Plan::get_tag_status( '1.0.0', [], [] ) );
180+
}
165181
}

0 commit comments

Comments
 (0)