Skip to content

Commit

Permalink
fix issue message duplicationg in generate-chnagelog
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Nov 15, 2021
1 parent 4770463 commit 3f3c893
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions bin/generate-changelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
declare(strict_types=1);

use Httpful\Request;
use Nette\Utils\Strings;
use Symfony\Component\Console\Application;

use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -33,6 +34,11 @@ final class GenerateChangelogCommand extends Command
*/
private const DEVELOPMENT_REPOSITORY_NAME = 'rectorphp/rector-src';

/**
* @var string[]
*/
private const EXCLUDED_THANKS_NAMES = ['TomasVotruba'];

/**
* @var string
*/
Expand Down Expand Up @@ -124,12 +130,22 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
}

$output->writeln(
sprintf('* %s (%s)%s%s', $commit['message'], $parenthesis, $issuesToReference !== [] ? ', ' . implode(
', ',
$issuesToReference
) : '', $thanks !== null ? sprintf(', Thanks @%s!', $thanks) : '')
// clean commit from duplicating issue number
$commitMatch = Strings::match($commit['message'], '#(.*?)( \(\#\d+\))?$#ms');

$commit = $commitMatch[1] ?? $commit['message'];

$changelogLine = sprintf(
'* %s (%s)%s%s',
$commit,
$parenthesis,
$issuesToReference !== [] ? ', ' . implode(', ', $issuesToReference) : '',
$this->createThanks($thanks)
);

$output->writeln($changelogLine);

// not to throttle the GitHub API
if ($i > 0 && $i % 8 === 0) {
sleep(60);
}
Expand All @@ -140,6 +156,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return self::SUCCESS;
}

protected function createThanks(string|null $thanks): string
{
if ($thanks === null) {
return '';
}

if (in_array($thanks, self::EXCLUDED_THANKS_NAMES, true)) {
return '';
}

return sprintf(', Thanks @%s!', $thanks);
}

/**
* @param string[] $commandParts
*/
Expand Down

0 comments on commit 3f3c893

Please sign in to comment.