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

Commit

Permalink
Merge d1c21c0 into 6f3372f
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Sep 1, 2018
2 parents 6f3372f + d1c21c0 commit e40d031
Show file tree
Hide file tree
Showing 23 changed files with 238 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ script:
fi
# validate monorepo <=> packages composer dependencies
- packages/MonorepoBuilder/bin/monorepo-builder validate-versions
- packages/MonorepoBuilder/bin/monorepo-builder validate

after_script:
# upload coverage.xml to Coveralls
Expand Down
45 changes: 0 additions & 45 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1142,13 +1142,11 @@ This change was finished in [Statie](https://github.com/Symplify/Statie) and [Ea
[#474]: https://github.com/Symplify/Symplify/pull/474
[#473]: https://github.com/Symplify/Symplify/pull/473
[#472]: https://github.com/Symplify/Symplify/pull/472
[#471]: https://github.com/Symplify/Symplify/pull/471
[#466]: https://github.com/Symplify/Symplify/pull/466
[#437]: https://github.com/Symplify/Symplify/pull/437
[#487]: https://github.com/Symplify/Symplify/issues/487
[#483]: https://github.com/Symplify/Symplify/issues/483
[#477]: https://github.com/Symplify/Symplify/issues/477
[v3.0.1]: https://github.com/Symplify/Symplify/compare/v3.0.0...v3.0.1
[v3.0.0]: https://github.com/Symplify/Symplify/compare/v2.5.0...v3.0.0
[#452]: https://github.com/Symplify/Symplify/pull/452
[v2.5.0]: https://github.com/Symplify/Symplify/compare/v2.4.0...v2.5.0
Expand All @@ -1164,7 +1162,6 @@ This change was finished in [Statie](https://github.com/Symplify/Statie) and [Ea
[#431]: https://github.com/Symplify/Symplify/pull/431
[#430]: https://github.com/Symplify/Symplify/pull/430
[#427]: https://github.com/Symplify/Symplify/pull/427
[#422]: https://github.com/Symplify/Symplify/issues/422
[#421]: https://github.com/Symplify/Symplify/pull/421
[#419]: https://github.com/Symplify/Symplify/pull/419
[#417]: https://github.com/Symplify/Symplify/pull/417
Expand Down Expand Up @@ -1235,7 +1232,6 @@ This change was finished in [Statie](https://github.com/Symplify/Statie) and [Ea
[#225]: https://github.com/Symplify/Symplify/pull/225
[#224]: https://github.com/Symplify/Symplify/pull/224
[#223]: https://github.com/Symplify/Symplify/pull/223
[#222]: https://github.com/Symplify/Symplify/pull/222
[#221]: https://github.com/Symplify/Symplify/pull/221
[#217]: https://github.com/Symplify/Symplify/pull/217
[#215]: https://github.com/Symplify/Symplify/pull/215
Expand All @@ -1253,10 +1249,8 @@ This change was finished in [Statie](https://github.com/Symplify/Statie) and [Ea
[#188]: https://github.com/Symplify/Symplify/pull/188
[#186]: https://github.com/Symplify/Symplify/pull/186
[#184]: https://github.com/Symplify/Symplify/pull/184
[#183]: https://github.com/Symplify/Symplify/pull/183
[#182]: https://github.com/Symplify/Symplify/pull/182
[#179]: https://github.com/Symplify/Symplify/pull/179
[#173]: https://github.com/Symplify/Symplify/pull/173
[#170]: https://github.com/Symplify/Symplify/pull/170
[#165]: https://github.com/Symplify/Symplify/pull/165
[#164]: https://github.com/Symplify/Symplify/pull/164
Expand Down Expand Up @@ -1314,18 +1308,14 @@ This change was finished in [Statie](https://github.com/Symplify/Statie) and [Ea
[#577]: https://github.com/Symplify/Symplify/pull/577
[#576]: https://github.com/Symplify/Symplify/pull/576
[#574]: https://github.com/Symplify/Symplify/pull/574
[#573]: https://github.com/Symplify/Symplify/pull/573
[#570]: https://github.com/Symplify/Symplify/pull/570
[#562]: https://github.com/Symplify/Symplify/pull/562
[#560]: https://github.com/Symplify/Symplify/pull/560
[#559]: https://github.com/Symplify/Symplify/pull/559
[@tomasfejfar]: https://github.com/tomasfejfar
[@muglug]: https://github.com/muglug
[#583]: https://github.com/Symplify/Symplify/pull/583
[#578]: https://github.com/Symplify/Symplify/pull/578
[caf08e]: https://github.com/Symplify/Symplify/commit/caf08e93b2627e1e981493349957f4e49d55cd6a
[59bdfc]: https://github.com/Symplify/Symplify/commit/59bdfc3c0d4945f946d17f127e6a329384d5bab8
[257e5b]: https://github.com/Symplify/Symplify/commit/257e5bc68b9341f8fbe1e306d08f736038d6d626
[1fcc92]: https://github.com/Symplify/Symplify/commit/1fcc927258710b0a03a806fa1661ed0179a5aaf7
[#640]: https://github.com/Symplify/Symplify/pull/640
[#638]: https://github.com/Symplify/Symplify/issues/638
Expand Down Expand Up @@ -1359,16 +1349,12 @@ This change was finished in [Statie](https://github.com/Symplify/Statie) and [Ea
[#708]: https://github.com/Symplify/Symplify/pull/708
[#707]: https://github.com/Symplify/Symplify/pull/707
[#705]: https://github.com/Symplify/Symplify/pull/705
[#704]: https://github.com/Symplify/Symplify/pull/704
[#703]: https://github.com/Symplify/Symplify/pull/703
[#700]: https://github.com/Symplify/Symplify/pull/700
[#698]: https://github.com/Symplify/Symplify/pull/698
[#693]: https://github.com/Symplify/Symplify/pull/693
[#692]: https://github.com/Symplify/Symplify/pull/692
[#691]: https://github.com/Symplify/Symplify/pull/691
[#680]: https://github.com/Symplify/Symplify/pull/680
[@OndraM]: https://github.com/OndraM
[v4.0.0alpha3]: https://github.com/Symplify/Symplify/compare/v3.2.0...v4.0.0alpha3
[#722]: https://github.com/Symplify/Symplify/pull/722
[#721]: https://github.com/Symplify/Symplify/pull/721
[#720]: https://github.com/Symplify/Symplify/pull/720
Expand All @@ -1391,14 +1377,12 @@ This change was finished in [Statie](https://github.com/Symplify/Statie) and [Ea
[v4.0.0]: https://github.com/Symplify/Symplify/compare/v3.2.0...v4.0.0
[#755]: https://github.com/Symplify/Symplify/pull/755
[#706]: https://github.com/Symplify/Symplify/pull/706
[v4.0.1]: https://github.com/Symplify/Symplify/compare/v4.0.0...v4.0.1
[#759]: https://github.com/Symplify/Symplify/pull/759
[#758]: https://github.com/Symplify/Symplify/pull/758
[#757]: https://github.com/Symplify/Symplify/pull/757
[#750]: https://github.com/Symplify/Symplify/issues/750
[#764]: https://github.com/Symplify/Symplify/pull/764
[#763]: https://github.com/Symplify/Symplify/pull/763
[v4.0.2]: https://github.com/Symplify/Symplify/compare/v4.0.1...v4.0.2
[#769]: https://github.com/Symplify/Symplify/pull/769
[#768]: https://github.com/Symplify/Symplify/pull/768
[#767]: https://github.com/Symplify/Symplify/pull/767
Expand All @@ -1415,9 +1399,7 @@ This change was finished in [Statie](https://github.com/Symplify/Statie) and [Ea
[#776]: https://github.com/Symplify/Symplify/pull/776
[#771]: https://github.com/Symplify/Symplify/pull/771
[#770]: https://github.com/Symplify/Symplify/pull/770
[v4.1.1]: https://github.com/Symplify/Symplify/compare/v4.1.0...v4.1.1
[#796]: https://github.com/Symplify/Symplify/pull/796
[v4.2.0]: https://github.com/Symplify/Symplify/compare/v4.1.0...v4.2.0
[#811]: https://github.com/Symplify/Symplify/pull/811
[#810]: https://github.com/Symplify/Symplify/pull/810
[#809]: https://github.com/Symplify/Symplify/pull/809
Expand Down Expand Up @@ -1454,13 +1436,11 @@ This change was finished in [Statie](https://github.com/Symplify/Statie) and [Ea
[#867]: https://github.com/Symplify/Symplify/pull/867
[#863]: https://github.com/Symplify/Symplify/pull/863
[#862]: https://github.com/Symplify/Symplify/pull/862
[#861]: https://github.com/Symplify/Symplify/pull/861
[#858]: https://github.com/Symplify/Symplify/pull/858
[#857]: https://github.com/Symplify/Symplify/pull/857
[#855]: https://github.com/Symplify/Symplify/pull/855
[#854]: https://github.com/Symplify/Symplify/pull/854
[#837]: https://github.com/Symplify/Symplify/pull/837
[#833]: https://github.com/Symplify/Symplify/pull/833
[#860]: https://github.com/Symplify/Symplify/pull/860
[#843]: https://github.com/Symplify/Symplify/pull/843
[#727]: https://github.com/Symplify/Symplify/pull/727
Expand All @@ -1479,13 +1459,7 @@ This change was finished in [Statie](https://github.com/Symplify/Statie) and [Ea
[#884]: https://github.com/Symplify/Symplify/pull/884
[#883]: https://github.com/Symplify/Symplify/pull/883
[#881]: https://github.com/Symplify/Symplify/pull/881
[#880]: https://github.com/Symplify/Symplify/pull/880
[#879]: https://github.com/Symplify/Symplify/pull/879
[#878]: https://github.com/Symplify/Symplify/pull/878
[#877]: https://github.com/Symplify/Symplify/pull/877
[#876]: https://github.com/Symplify/Symplify/pull/876
[#875]: https://github.com/Symplify/Symplify/pull/875
[#872]: https://github.com/Symplify/Symplify/pull/872
[#871]: https://github.com/Symplify/Symplify/pull/871
[#870]: https://github.com/Symplify/Symplify/pull/870
[@jankonas]: https://github.com/jankonas
Expand All @@ -1506,13 +1480,7 @@ This change was finished in [Statie](https://github.com/Symplify/Statie) and [Ea
[#884]: https://github.com/Symplify/Symplify/pull/884
[#883]: https://github.com/Symplify/Symplify/pull/883
[#881]: https://github.com/Symplify/Symplify/pull/881
[#880]: https://github.com/Symplify/Symplify/pull/880
[#879]: https://github.com/Symplify/Symplify/pull/879
[#878]: https://github.com/Symplify/Symplify/pull/878
[#877]: https://github.com/Symplify/Symplify/pull/877
[#876]: https://github.com/Symplify/Symplify/pull/876
[#875]: https://github.com/Symplify/Symplify/pull/875
[#872]: https://github.com/Symplify/Symplify/pull/872
[#871]: https://github.com/Symplify/Symplify/pull/871
[#870]: https://github.com/Symplify/Symplify/pull/870
[@jankonas]: https://github.com/jankonas
Expand Down Expand Up @@ -1548,13 +1516,10 @@ This change was finished in [Statie](https://github.com/Symplify/Statie) and [Ea
[#963]: https://github.com/Symplify/Symplify/pull/963
[#962]: https://github.com/Symplify/Symplify/pull/962
[#961]: https://github.com/Symplify/Symplify/pull/961
[#959]: https://github.com/Symplify/Symplify/pull/959
[#958]: https://github.com/Symplify/Symplify/pull/958
[#957]: https://github.com/Symplify/Symplify/pull/957
[#956]: https://github.com/Symplify/Symplify/pull/956
[#955]: https://github.com/Symplify/Symplify/pull/955
[#954]: https://github.com/Symplify/Symplify/pull/954
[#953]: https://github.com/Symplify/Symplify/pull/953
[#952]: https://github.com/Symplify/Symplify/pull/952
[#951]: https://github.com/Symplify/Symplify/pull/951
[#950]: https://github.com/Symplify/Symplify/pull/950
Expand All @@ -1578,9 +1543,7 @@ This change was finished in [Statie](https://github.com/Symplify/Statie) and [Ea
[#1004]: https://github.com/Symplify/Symplify/pull/1004
[#1003]: https://github.com/Symplify/Symplify/pull/1003
[#1002]: https://github.com/Symplify/Symplify/pull/1002
[#999]: https://github.com/Symplify/Symplify/pull/999
[#998]: https://github.com/Symplify/Symplify/pull/998
[#996]: https://github.com/Symplify/Symplify/pull/996
[#995]: https://github.com/Symplify/Symplify/pull/995
[#994]: https://github.com/Symplify/Symplify/pull/994
[#993]: https://github.com/Symplify/Symplify/pull/993
Expand All @@ -1592,14 +1555,10 @@ This change was finished in [Statie](https://github.com/Symplify/Statie) and [Ea
[#984]: https://github.com/Symplify/Symplify/pull/984
[#975]: https://github.com/Symplify/Symplify/pull/975
[v4.6.0]: https://github.com/Symplify/Symplify/compare/v4.5.1...v4.6.0
[#1023]: https://github.com/Symplify/Symplify/pull/1023
[#1020]: https://github.com/Symplify/Symplify/pull/1020
[#1014]: https://github.com/Symplify/Symplify/pull/1014
[#1013]: https://github.com/Symplify/Symplify/pull/1013
[#1010]: https://github.com/Symplify/Symplify/pull/1010
[#1009]: https://github.com/Symplify/Symplify/pull/1009
[#1001]: https://github.com/Symplify/Symplify/pull/1001
[#1000]: https://github.com/Symplify/Symplify/pull/1000
[v4.6.1]: https://github.com/Symplify/Symplify/compare/v4.6.0...v4.6.1
[#1044]: https://github.com/Symplify/Symplify/pull/1044
[#1043]: https://github.com/Symplify/Symplify/pull/1043
Expand All @@ -1612,11 +1571,8 @@ This change was finished in [Statie](https://github.com/Symplify/Statie) and [Ea
[#1036]: https://github.com/Symplify/Symplify/pull/1036
[#1035]: https://github.com/Symplify/Symplify/pull/1035
[#1034]: https://github.com/Symplify/Symplify/pull/1034
[#1033]: https://github.com/Symplify/Symplify/pull/1033
[#1032]: https://github.com/Symplify/Symplify/pull/1032
[#1030]: https://github.com/Symplify/Symplify/pull/1030
[#1027]: https://github.com/Symplify/Symplify/pull/1027
[#1026]: https://github.com/Symplify/Symplify/pull/1026
[#1021]: https://github.com/Symplify/Symplify/pull/1021
[#1016]: https://github.com/Symplify/Symplify/pull/1016
[#1015]: https://github.com/Symplify/Symplify/pull/1015
Expand All @@ -1625,4 +1581,3 @@ This change was finished in [Statie](https://github.com/Symplify/Statie) and [Ea
[#997]: https://github.com/Symplify/Symplify/pull/997
[#973]: https://github.com/Symplify/Symplify/pull/973
[#972]: https://github.com/Symplify/Symplify/pull/972
[@TomasLudvik]: https://github.com/TomasLudvik
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@
"phpstan": "vendor/bin/phpstan analyse packages --level max --configuration phpstan.neon",
"changelog": [
"packages/ChangelogLinker/bin/changelog-linker dump-merges --in-categories --in-packages",
"packages/ChangelogLinker/bin/changelog-linker linkify"
"packages/ChangelogLinker/bin/changelog-linker linkify",
"packages/ChangelogLinker/bin/changelog-linker cleanup"
]
},
"config": {
Expand Down
31 changes: 30 additions & 1 deletion packages/ChangelogLinker/src/Analyzer/LinksAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,46 @@ final class LinksAnalyzer
*/
private $linkedIds = [];

/**
* @var string[]
*/
private $references = [];

public function analyzeContent(string $content): void
{
// [content]: url
$this->linkedIds = [];

foreach (Strings::matchAll($content, RegexPattern::LINK_REFERENCE) as $match) {
$this->linkedIds[] = $match['reference'];
}
$this->linkedIds = array_unique($this->linkedIds);

// [content]
$this->references = [];
foreach (Strings::matchAll($content, '#\[\#?(?<reference>[(-\/@\w\d\.]+)\](?!:)(?!\()#') as $match) {
$this->references[] = $match['reference'];
}
$this->references = array_unique($this->references);
}

public function hasLinkedId(string $id): bool
{
return in_array($id, $this->linkedIds, true);
}

/**
* @return string[]
*/
public function getDeadLinks(): array
{
$deadLinks = array_diff($this->linkedIds, $this->references);

// special link, that needs to be kept
$commentPosition = array_search('comment', $deadLinks, true);
if ($commentPosition !== false) {
unset($deadLinks[$commentPosition]);
}

return array_values($deadLinks);
}
}
32 changes: 32 additions & 0 deletions packages/ChangelogLinker/src/ChangelogCleaner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php declare(strict_types=1);

namespace Symplify\ChangelogLinker;

use Nette\Utils\Strings;
use Symplify\ChangelogLinker\Analyzer\LinksAnalyzer;

final class ChangelogCleaner
{
/**
* @var LinksAnalyzer
*/
private $linksAnalyzer;

public function __construct(LinksAnalyzer $linksAnalyzer)
{
$this->linksAnalyzer = $linksAnalyzer;
}

public function processContent(string $changelogContent): string
{
$this->linksAnalyzer->analyzeContent($changelogContent);

$deadLinks = $this->linksAnalyzer->getDeadLinks();

foreach ($deadLinks as $deadLink) {
$changelogContent = Strings::replace($changelogContent, sprintf('#\[\#?(%s)\]:(.*?)\n#', $deadLink));
}

return $changelogContent;
}
}
48 changes: 48 additions & 0 deletions packages/ChangelogLinker/src/Console/Command/CleanupCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php declare(strict_types=1);

namespace Symplify\ChangelogLinker\Console\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symplify\ChangelogLinker\ChangelogCleaner;
use Symplify\ChangelogLinker\FileSystem\ChangelogFileSystem;
use Symplify\PackageBuilder\Console\Command\CommandNaming;

final class CleanupCommand extends Command
{
/**
* @var ChangelogFileSystem
*/
private $changelogFileSystem;

/**
* @var ChangelogCleaner
*/
private $changelogCleaner;

public function __construct(ChangelogFileSystem $changelogFileSystem, ChangelogCleaner $changelogCleaner)
{
parent::__construct();
$this->changelogFileSystem = $changelogFileSystem;
$this->changelogCleaner = $changelogCleaner;
}

protected function configure(): void
{
$this->setName(CommandNaming::classToName(self::class));
$this->setDescription('Removes dead links from CHANGELOG.md');
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$changelogContent = $this->changelogFileSystem->readChangelog();

$processedChangelogContent = $this->changelogCleaner->processContent($changelogContent);

$this->changelogFileSystem->storeChangelog($processedChangelogContent);

// success
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,13 @@ public function test(): void
$this->assertTrue($this->linksAnalyzer->hasLinkedId('5'));
$this->assertFalse($this->linksAnalyzer->hasLinkedId('10'));
}

public function testDeadLinks(): void
{
$this->linksAnalyzer->analyzeContent(file_get_contents(__DIR__ . '/Source/SomeFileWithDeadlinks.md'));

$deadLinks = $this->linksAnalyzer->getDeadLinks();

$this->assertSame(['5', '15'], $deadLinks);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Added

- [#10] A link

[#5]: Link
[#10]: Deadlink
[#15]: Deadlink
Loading

0 comments on commit e40d031

Please sign in to comment.