protected function RoboFile::updateChangelog in Panopoly 7
Updates a CHANGELOG.txt file for a new release.
Parameters
string $filename: The file to update.
string $name: The human-readable name of the project.
string $version: The new version.
string $entry: The text content of the changelog (from `drush rn --changelog`).
1 call to RoboFile::updateChangelog()
- RoboFile::releaseCreate in ./
RoboFile.php - Release Stage 1: results in local tag and commit for the new version.
File
- ./
RoboFile.php, line 622
Class
- RoboFile
- This is project's console commands configuration for Robo task runner.
Code
protected function updateChangelog($filename, $name, $version, $entry) {
$changelog = file_exists($filename) ? file_get_contents($filename) : '';
$version_line = "{$name} {$version}, " . date('Y-m-d') . "\n";
if (strpos($changelog, $version_line) !== FALSE) {
$this
->say("Changes for {$version} already present in {$filename} - skipping!");
return;
}
// Do word wrapping.
$entry_parts = array_slice(explode("\n", str_replace("\r", "", wordwrap($entry))), 1);
$entry_parts = array_map(function ($line) {
return empty($line) || strpos($line, '-') === 0 ? $line : ' ' . $line;
}, $entry_parts);
$entry = implode("\n", $entry_parts);
// Add header and deal with empty data.
$entry = $version_line . $entry;
if (strpos($entry, '- ') === FALSE) {
$entry = str_replace("\n\n", "\n- No changes since last release.\n\n", $entry);
}
// Prepend the new entry to the changelog file.
$changelog = $entry . $changelog;
file_put_contents($filename, $changelog);
}