Skip to content

Commit febcfd4

Browse files
authored
Merge pull request #62 from geerteltink/feat/milestone-descriptions
Add milestone descriptions
2 parents bea0628 + 231e6fe commit febcfd4

File tree

4 files changed

+107
-2
lines changed

4 files changed

+107
-2
lines changed

src/Git/Value/SemVerVersion.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ public function isNewMinorRelease(): bool
7979
return $this->patch === 0;
8080
}
8181

82+
public function isNewMajorRelease(): bool
83+
{
84+
return $this->minor === 0 && $this->patch === 0;
85+
}
86+
8287
public function lessThanEqual(self $other): bool
8388
{
8489
return $this->fullReleaseName() <= $other->fullReleaseName();

src/Github/Api/V3/CreateMilestoneThroughApiCall.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public function __invoke(RepositoryName $repository, SemVerVersion $version): vo
6363
->getBody()
6464
->write(json_encode([
6565
'title' => $version->fullReleaseName(),
66+
'description' => $this->milestoneDescription($version),
6667
]));
6768

6869
$response = $this->client->sendRequest($request);
@@ -93,4 +94,17 @@ public function __invoke(RepositoryName $repository, SemVerVersion $version): vo
9394
$version->fullReleaseName()
9495
));
9596
}
97+
98+
private function milestoneDescription(SemVerVersion $version): string
99+
{
100+
if ($version->isNewMajorRelease()) {
101+
return 'Backwards incompatible release (major)';
102+
}
103+
104+
if ($version->isNewMinorRelease()) {
105+
return 'Feature release (minor)';
106+
}
107+
108+
return sprintf('%s bugfix release (patch)', $version->targetReleaseBranchName()->name());
109+
}
96110
}

test/unit/Git/Value/SemVerVersionTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,38 @@ public function newMinorReleasesProvider(): array
119119
];
120120
}
121121

122+
/**
123+
* @dataProvider newMajorReleasesProvider
124+
*/
125+
public function testIsNewMajorRelease(string $milestoneName, bool $expected): void
126+
{
127+
self::assertSame(
128+
$expected,
129+
SemVerVersion::fromMilestoneName($milestoneName)
130+
->isNewMajorRelease()
131+
);
132+
}
133+
134+
/**
135+
* @return array<int, array<int, string|bool>>
136+
*
137+
* @psalm-return array<int, array{0: string, 1: bool}>
138+
*/
139+
public function newMajorReleasesProvider(): array
140+
{
141+
return [
142+
['3.0.1', false],
143+
['3.0.0', true],
144+
['2.0.10', false],
145+
['2.0.0', true],
146+
['1.0.0', true],
147+
['1.1.0', false],
148+
['1.1.1', false],
149+
['1.1.2', false],
150+
['1.1.90', false],
151+
];
152+
}
153+
122154
/**
123155
* @dataProvider lessThanEqualProvider
124156
*/

test/unit/Github/Api/V3/CreateMilestoneTest.php

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public function testSuccessfulRequest(): void
8787
self::assertJsonStringEqualsJsonString(
8888
<<<'JSON'
8989
{
90+
"description": "1.2.x bugfix release (patch)",
9091
"title": "1.2.3"
9192
}
9293
JSON,
@@ -146,7 +147,8 @@ public function testExistingMilestone(): void
146147
self::assertJsonStringEqualsJsonString(
147148
<<<'JSON'
148149
{
149-
"title": "1.2.3"
150+
"description": "Feature release (minor)",
151+
"title": "2.1.0"
150152
}
151153
JSON,
152154
$request->getBody()->__toString()
@@ -160,7 +162,59 @@ public function testExistingMilestone(): void
160162

161163
$this->createMilestone->__invoke(
162164
RepositoryName::fromFullName('foo/bar'),
163-
SemVerVersion::fromMilestoneName('1.2.3')
165+
SemVerVersion::fromMilestoneName('2.1.0')
166+
);
167+
}
168+
169+
public function testMajorMilestone(): void
170+
{
171+
$this->messageFactory
172+
->expects(self::any())
173+
->method('createRequest')
174+
->with('POST', 'https://api.github.com/repos/foo/bar/milestones')
175+
->willReturn(new Request('https://the-domain.com/the-path'));
176+
177+
$validResponse = (new Response())->withStatus(201);
178+
179+
$validResponse->getBody()->write(
180+
<<<'JSON'
181+
{
182+
"html_url": "http://another-domain.com/the-pr"
183+
}
184+
JSON
185+
);
186+
187+
$this->httpClient
188+
->expects(self::once())
189+
->method('sendRequest')
190+
->with(self::callback(function (RequestInterface $request): bool {
191+
self::assertSame(
192+
[
193+
'Host' => ['the-domain.com'],
194+
'Content-Type' => ['application/json'],
195+
'User-Agent' => ['Ocramius\'s minimal API V3 client'],
196+
'Authorization' => ['token ' . $this->apiToken],
197+
],
198+
$request->getHeaders()
199+
);
200+
201+
self::assertJsonStringEqualsJsonString(
202+
<<<'JSON'
203+
{
204+
"description": "Backwards incompatible release (major)",
205+
"title": "3.0.0"
206+
}
207+
JSON,
208+
$request->getBody()->__toString()
209+
);
210+
211+
return true;
212+
}))
213+
->willReturn($validResponse);
214+
215+
$this->createMilestone->__invoke(
216+
RepositoryName::fromFullName('foo/bar'),
217+
SemVerVersion::fromMilestoneName('3.0.0')
164218
);
165219
}
166220
}

0 commit comments

Comments
 (0)