Skip to content
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

Add milestone descriptions when creating new milestones #62

Merged
merged 1 commit into from
Aug 31, 2020
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
5 changes: 5 additions & 0 deletions src/Git/Value/SemVerVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ public function isNewMinorRelease(): bool
return $this->patch === 0;
}

public function isNewMajorRelease(): bool
{
return $this->minor === 0 && $this->patch === 0;
}

public function lessThanEqual(self $other): bool
{
return $this->fullReleaseName() <= $other->fullReleaseName();
Expand Down
14 changes: 14 additions & 0 deletions src/Github/Api/V3/CreateMilestoneThroughApiCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function __invoke(RepositoryName $repository, SemVerVersion $version): vo
->getBody()
->write(json_encode([
'title' => $version->fullReleaseName(),
'description' => $this->milestoneDescription($version),
]));

$response = $this->client->sendRequest($request);
Expand Down Expand Up @@ -93,4 +94,17 @@ public function __invoke(RepositoryName $repository, SemVerVersion $version): vo
$version->fullReleaseName()
));
}

private function milestoneDescription(SemVerVersion $version): string
{
if ($version->isNewMajorRelease()) {
return 'Backwards incompatible release (major)';
}

if ($version->isNewMinorRelease()) {
return 'Feature release (minor)';
}

return sprintf('%s bugfix release (patch)', $version->targetReleaseBranchName()->name());
}
}
32 changes: 32 additions & 0 deletions test/unit/Git/Value/SemVerVersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,38 @@ public function newMinorReleasesProvider(): array
];
}

/**
* @dataProvider newMajorReleasesProvider
*/
public function testIsNewMajorRelease(string $milestoneName, bool $expected): void
{
self::assertSame(
$expected,
SemVerVersion::fromMilestoneName($milestoneName)
->isNewMajorRelease()
);
}

/**
* @return array<int, array<int, string|bool>>
*
* @psalm-return array<int, array{0: string, 1: bool}>
*/
public function newMajorReleasesProvider(): array
{
return [
['3.0.1', false],
['3.0.0', true],
['2.0.10', false],
['2.0.0', true],
['1.0.0', true],
['1.1.0', false],
['1.1.1', false],
['1.1.2', false],
['1.1.90', false],
];
}

/**
* @dataProvider lessThanEqualProvider
*/
Expand Down
58 changes: 56 additions & 2 deletions test/unit/Github/Api/V3/CreateMilestoneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public function testSuccessfulRequest(): void
self::assertJsonStringEqualsJsonString(
<<<'JSON'
{
"description": "1.2.x bugfix release (patch)",
"title": "1.2.3"
}
JSON,
Expand Down Expand Up @@ -146,7 +147,8 @@ public function testExistingMilestone(): void
self::assertJsonStringEqualsJsonString(
<<<'JSON'
{
"title": "1.2.3"
"description": "Feature release (minor)",
"title": "2.1.0"
}
JSON,
$request->getBody()->__toString()
Expand All @@ -160,7 +162,59 @@ public function testExistingMilestone(): void

$this->createMilestone->__invoke(
RepositoryName::fromFullName('foo/bar'),
SemVerVersion::fromMilestoneName('1.2.3')
SemVerVersion::fromMilestoneName('2.1.0')
);
}

public function testMajorMilestone(): void
{
$this->messageFactory
->expects(self::any())
->method('createRequest')
->with('POST', 'https://api.github.com/repos/foo/bar/milestones')
->willReturn(new Request('https://the-domain.com/the-path'));

$validResponse = (new Response())->withStatus(201);

$validResponse->getBody()->write(
<<<'JSON'
{
"html_url": "http://another-domain.com/the-pr"
}
JSON
);

$this->httpClient
->expects(self::once())
->method('sendRequest')
->with(self::callback(function (RequestInterface $request): bool {
self::assertSame(
[
'Host' => ['the-domain.com'],
'Content-Type' => ['application/json'],
'User-Agent' => ['Ocramius\'s minimal API V3 client'],
'Authorization' => ['token ' . $this->apiToken],
],
$request->getHeaders()
);

self::assertJsonStringEqualsJsonString(
<<<'JSON'
{
"description": "Backwards incompatible release (major)",
"title": "3.0.0"
}
JSON,
$request->getBody()->__toString()
);

return true;
}))
->willReturn($validResponse);

$this->createMilestone->__invoke(
RepositoryName::fromFullName('foo/bar'),
SemVerVersion::fromMilestoneName('3.0.0')
);
}
}