Skip to content

Commit b92e8d5

Browse files
committed
Improve mile stone failed detection
Signed-off-by: Geert Eltink <[email protected]>
1 parent 652b820 commit b92e8d5

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

src/Application/Command/CreateMilestones.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Laminas\AutomaticReleases\Git\Value\SemVerVersion;
99
use Laminas\AutomaticReleases\Github\Api\GraphQL\Query\GetGithubMilestone;
1010
use Laminas\AutomaticReleases\Github\Api\V3\CreateMilestone;
11+
use Laminas\AutomaticReleases\Github\Api\V3\CreateMilestoneFailed;
1112
use Laminas\AutomaticReleases\Github\Event\Factory\LoadCurrentGithubEvent;
1213
use Laminas\AutomaticReleases\Github\Value\RepositoryName;
1314
use Symfony\Component\Console\Command\Command;
@@ -41,19 +42,19 @@ public function execute(InputInterface $input, OutputInterface $output): int
4142

4243
$milestone->assertAllIssuesAreClosed();
4344

44-
$this->createMilestoneIfNotExists($repositoryName, $releaseVersion->nextPatch());
45-
$this->createMilestoneIfNotExists($repositoryName, $releaseVersion->nextMinor());
46-
$this->createMilestoneIfNotExists($repositoryName, $releaseVersion->nextMajor());
45+
$this->createMilestoneIfNotExists($repositoryName, $releaseVersion->nextPatch(), $output);
46+
$this->createMilestoneIfNotExists($repositoryName, $releaseVersion->nextMinor(), $output);
47+
$this->createMilestoneIfNotExists($repositoryName, $releaseVersion->nextMajor(), $output);
4748

4849
return 0;
4950
}
5051

51-
private function createMilestoneIfNotExists(RepositoryName $repositoryName, SemVerVersion $version): bool
52+
private function createMilestoneIfNotExists(RepositoryName $repositoryName, SemVerVersion $version, OutputInterface $output): bool
5253
{
5354
try {
5455
($this->createMilestone)($repositoryName, $version->nextPatch());
55-
} catch (InvalidArgumentException $e) {
56-
// Log that the milestone exists?
56+
} catch (CreateMilestoneFailed $e) {
57+
$output->writeln($e->getMessage());
5758
return false;
5859
}
5960

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Laminas\AutomaticReleases\Github\Api\V3;
6+
7+
use RuntimeException;
8+
9+
class CreateMilestoneFailed extends RuntimeException
10+
{
11+
public static function forVersion(string $version, string $error): self
12+
{
13+
return new self(sprintf('Milestone "%s" creation failed: %s', $version, $error));
14+
}
15+
}

src/Github/Api/V3/CreateMilestoneThroughApiCall.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,13 @@ public function __invoke(
7777
->getBody()
7878
->__toString();
7979

80-
Assert::greaterThanEq($response->getStatusCode(), 200);
81-
Assert::lessThanEq($response->getStatusCode(), 299);
80+
if ($response->getStatusCode() !== 201) {
81+
throw CreateMilestoneFailed::forVersion($version->fullReleaseName(), $responseBody);
82+
}
8283

83-
$responseData = json_decode($responseBody, true);
84+
Assert::eq($response->getStatusCode(), 201);
8485

86+
$responseData = json_decode($responseBody, true);
8587
Assert::isMap($responseData);
8688
Assert::keyExists($responseData, 'html_url');
8789
Assert::stringNotEmpty($responseData['html_url']);

0 commit comments

Comments
 (0)