Skip to content
This repository has been archived by the owner on Dec 3, 2023. It is now read-only.

Commit

Permalink
Merge 0aa2bf2 into aee600e
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Sep 12, 2018
2 parents aee600e + 0aa2bf2 commit f2446fb
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 4 deletions.
9 changes: 8 additions & 1 deletion packages/ChangelogLinker/src/ChangeTree/ChangeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct(
*/
public function createFromPullRequest(array $pullRequest): Change
{
$message = sprintf('- [#%s] %s', $pullRequest['number'], trim($pullRequest['title']));
$message = sprintf('- [#%s] %s', $pullRequest['number'], $this->escapeMarkdown($pullRequest['title']));

$author = $pullRequest['user']['login'] ?? '';

Expand All @@ -76,4 +76,11 @@ private function resolveMessageWithoutPackage(string $message, ?string $package)

return Strings::replace($message, '#\[' . $package . '\]\s+#');
}

private function escapeMarkdown(string $content): string
{
$content = trim($content);

return Strings::replace($content, '#(\*)#', '\\\$1');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public function provideDataForMessageWithoutPackage(): Iterator
{
yield ['[SomePackage] SomeMessage', '- [#10] [SomePackage] SomeMessage', '- [#10] SomeMessage'];
yield ['[coding-standards] SomeMessage', '- [#10] [coding-standards] SomeMessage', '- [#10] SomeMessage'];
yield ['*SomeMessage', '- [#10] \*SomeMessage', '- [#10] \*SomeMessage'];
yield ['*SomeMessage**', '- [#10] \*SomeMessage\*\*', '- [#10] \*SomeMessage\*\*'];
}

public function testTagDetection(): void
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php declare(strict_types=1);

namespace Symplify\ChangelogLinker\Tests\ChangelogDumper;

use PHPUnit\Framework\TestCase;
use Symplify\ChangelogLinker\ChangelogDumper;
use Symplify\ChangelogLinker\ChangelogFormatter;
use Symplify\ChangelogLinker\ChangeTree\Change;
use Symplify\ChangelogLinker\Git\GitCommitDateTagResolver;

final class ChangelogDumperMultipleItemsTest extends TestCase
{
/**
* @var Change[]
*/
private $changes = [];

/**
* @var ChangelogDumper
*/
private $changelogDumper;

protected function setUp(): void
{
$this->changelogDumper = new ChangelogDumper(new GitCommitDateTagResolver(), new ChangelogFormatter());

$this->changes = [
new Change('[SomePackage] Message', 'Added', 'SomePackage', 'Message', 'Unreleased'),
new Change('[AnotherPackage] Message', 'Fixed', 'AnotherPackage', 'Another Message', 'Unreleased'),
];
}

public function testReportBothWithPriority(): void
{
$content = $this->changelogDumper->reportChangesWithHeadlines($this->changes, true, true, 'packages');

$this->assertStringEqualsFile(__DIR__ . '/ChangelogDumperSource/expected-multiple1.md', $content);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

## Unreleased

### SomePackage

#### Added

Message

### AnotherPackage

#### Fixed

Another Message

Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public function testReportChanges(): void
}

/**
* @dataProvider provideDataForReportChangesWithHeadlines()
* @dataProvider provideDataForReportBothWithPriority()
*/
public function testReportBothWithCategoriesPriority(
public function testReportBothWithPriority(
bool $withCategories,
bool $withPackages,
string $priority,
Expand All @@ -54,7 +54,7 @@ public function testReportBothWithCategoriesPriority(
$this->assertStringEqualsFile($expectedOutputFile, $content);
}

public function provideDataForReportChangesWithHeadlines(): Iterator
public function provideDataForReportBothWithPriority(): Iterator
{
yield [true, false, 'categories', __DIR__ . '/ChangelogDumperSource/expected2.md'];
yield [false, true, 'packages', __DIR__ . '/ChangelogDumperSource/expected3.md'];
Expand Down

0 comments on commit f2446fb

Please sign in to comment.