Skip to content

Commit

Permalink
Improve changelog totals to be split by issue and pull requests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwage committed May 19, 2018
1 parent 065f8e9 commit d4f1edd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
24 changes: 23 additions & 1 deletion src/ChangelogGenerator/ChangelogGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace ChangelogGenerator;

use Symfony\Component\Console\Output\OutputInterface;
use function array_filter;
use function count;
use function sprintf;

Expand All @@ -30,7 +31,8 @@ public function generate(string $user, string $repository, string $milestone, Ou
$output->writeln([
sprintf('## %s', $milestone),
'',
sprintf('Total issues resolved: **%s**', count($issues)),
sprintf('Total issues resolved: **%s**', $this->getNumberOfIssues($issues)),
sprintf('Total pull requests resolved: **%s**', $this->getNumberOfPullRequests($issues)),
]);

foreach ($issueGroups as $issueGroup) {
Expand All @@ -45,4 +47,24 @@ public function generate(string $user, string $repository, string $milestone, Ou
}
}
}

/**
* @param Issue[] $issues
*/
private function getNumberOfIssues(array $issues) : int
{
return count(array_filter($issues, function (Issue $issue) : bool {
return ! $issue->isPullRequest();
}));
}

/**
* @param Issue[] $issues
*/
private function getNumberOfPullRequests(array $issues) : int
{
return count(array_filter($issues, function (Issue $issue) : bool {
return $issue->isPullRequest();
}));
}
}
27 changes: 22 additions & 5 deletions tests/ChangelogGenerator/Tests/ChangelogGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ public function testGenerate() : void

$output = $this->createMock(OutputInterface::class);

$issue = $this->createMock(Issue::class);
$issue1 = $this->createMock(Issue::class);
$issue2 = $this->createMock(Issue::class);
$pullRequest1 = $this->createMock(Issue::class);
$pullRequest2 = $this->createMock(Issue::class);

$issueGroup = $this->createMock(IssueGroup::class);

$milestoneIssues = [$issue];
$milestoneIssues = [$issue1, $issue2, $pullRequest1, $pullRequest2];
$issueGroups = [$issueGroup];

$this->issueRepository->expects($this->once())
Expand All @@ -53,18 +57,31 @@ public function testGenerate() : void

$issueGroup->expects($this->once())
->method('getIssues')
->willReturn([$issue]);
->willReturn([$issue1, $issue2]);

$issue->expects($this->once())
$issue1->expects($this->once())
->method('render')
->willReturn('Issue #1');

$issue2->expects($this->once())
->method('render')
->willReturn('Issue #2');

$pullRequest1->expects($this->any())
->method('isPullRequest')
->willReturn(true);

$pullRequest2->expects($this->any())
->method('isPullRequest')
->willReturn(true);

$output->expects($this->at(0))
->method('writeln')
->with([
'## 1.0',
'',
'Total issues resolved: **1**',
'Total issues resolved: **2**',
'Total pull requests resolved: **2**',
]);

$output->expects($this->at(1))
Expand Down

0 comments on commit d4f1edd

Please sign in to comment.