alessandro_podo/git-changelog-generator
Installation:
composer require alessandro_podo/git-changelog-generator
Add the bundle to config/bundles.php:
return [
AlessandroPodo\GitChangelogGenerator\GitChangelogGenerator::class => ['all' => true],
];
Basic Configuration:
Create config/packages/git_changelog_generator.yaml with minimal scopes:
git_changelog_generator:
scopes:
- feature
- bugfix
- refactor
First Use Case: Generate a changelog for the last 10 commits:
use AlessandroPodo\GitChangelogGenerator\Service\Changelog\Changelog;
public function changelog(Changelog $changelog): Response
{
$content = $changelog->render(['limit' => 10]);
return $this->render('changelog.html.twig', ['content' => $content]);
}
Twig Template:
{% extends 'base.html.twig' %}
{% block body %}
{{ content|raw }}
{% endblock %}
Commit Message Conventions: Use structured commit messages with footers for metadata:
feat: Add user authentication
footer: title: User Auth | description: JWT-based auth | visibility: public
Or use scopes directly:
feature: Add user auth
Dynamic Changelog Routes:
#[Route('/changelog/{scope}', name: 'changelog_by_scope')]
public function changelogByScope(Changelog $changelog, string $scope): Response
{
return $this->render('changelog.html.twig', [
'content' => $changelog->render(['scope' => $scope])
]);
}
CI/CD Integration: Generate changelogs in deployment pipelines:
# .github/workflows/deploy.yml
jobs:
deploy:
steps:
- run: php bin/console git-changelog:generate --limit=50 --output=CHANGELOG.md
Planned Changes:
Use plannedChangesFile.yml for upcoming work:
# plannedChangesFile.yml
- title: "API V2 Migration"
description: "Deprecate V1 endpoints"
ready: false
type: refactor
Validation Rules: Enforce commit message standards via config:
git_changelog_generator:
validateMapping:
'ROLE_*': ['<visibility footer>']
Scope Mismatch:
feature vs feat).php bin/console git-changelog:list-scopes
Visibility Defaults:
visibility is missing in commit footers, the package uses the config default.git_changelog_generator.yaml:
defaultVisibility: public
Twig Auto-escaping:
|raw in Twig to render HTML safely (e.g., Markdown converted to HTML).{{ changelogContent|raw }}
Git Repository Detection:
$changelog = $this->container->get(Changelog::class);
$content = $changelog->render(['repoPath' => '/custom/path/to/repo']);
Planned Changes File:
plannedChangesFile.yml is missing, the package silently skips rendering planned changes.if (file_exists($this->getParameter('planned_changes_file'))) {
// Render planned changes
}
Dry Run: Use the console command to preview changes:
php bin/console git-changelog:generate --dry-run
Log Commit Parsing: Enable debug mode in config:
git_changelog_generator:
debug: true
Check logs for parsed commit metadata.
Commit Message Parsing:
^(title|description|visibility|v): .+$
git log --pretty=format:"%B" to inspect raw commit messages.Custom Renderers:
Extend the Changelog service to modify output:
// src/Service/CustomChangelogRenderer.php
use AlessandroPodo\GitChangelogGenerator\Service\Changelog\Changelog;
class CustomChangelogRenderer extends Changelog
{
public function render(array $options = []): string
{
$content = parent::render($options);
return $this->addCustomFooter($content);
}
private function addCustomFooter(string $content): string
{
return $content . "\n\n---\nGenerated by Custom System";
}
}
Bind it in services.yaml:
services:
AlessandroPodo\GitChangelogGenerator\Service\Changelog\Changelog:
alias: App\Service\CustomChangelogRenderer
Event Listeners: Trigger actions on changelog generation (e.g., notify Slack):
// src/EventListener/ChangelogGeneratedListener.php
use AlessandroPodo\GitChangelogGenerator\Event\ChangelogGeneratedEvent;
class ChangelogGeneratedListener
{
public function onChangelogGenerated(ChangelogGeneratedEvent $event): void
{
$this->notifySlack($event->getContent());
}
}
Register in services.yaml:
services:
App\EventListener\ChangelogGeneratedListener:
tags:
- { name: kernel.event_listener, event: git_changelog.generated, method: onChangelogGenerated }
Dynamic Scopes: Fetch scopes from an external source (e.g., database):
// src/Service/DynamicScopeProvider.php
class DynamicScopeProvider
{
public function getScopes(): array
{
return $this->entityManager->getRepository(Scope::class)->findAll();
}
}
Override the Changelog service to use the provider.
Markdown Customization: Use a templating engine (e.g., Twig) to transform raw output:
{# templates/changelog/markdown.html.twig #}
{% for entry in changelogEntries %}
## {{ entry.title }}
{{ entry.description }}
**Scope**: {{ entry.scope }}
**Visibility**: {{ entry.visibility }}
{% endfor %}
How can I help you explore Laravel packages today?