From 10265561d8c0e193a9cfde64f0a230ce7c60ea26 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Sun, 18 Jul 2021 22:49:22 -0400 Subject: [PATCH] Prototype function for RPM changelog --- RoboFile.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/RoboFile.php b/RoboFile.php index fa6885a6..2f000e32 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -643,6 +643,42 @@ class RoboFile extends \Robo\Tasks { return $out; } + protected function changelogRPM(array $log, string $targetVersion): string { + $latest = $log[0]['version']; + $baseVersion = preg_replace('/^(\d+(?:\.\d+)*).*/', "$1", $targetVersion); + if ($baseVersion !== $targetVersion && version_compare($latest, $baseVersion, ">")) { + // if the changelog contains an entry for a future version, change its version number to match the target version instead of using the future version + $log[0]['version'] = $targetVersion; + } elseif ($baseVersion !== $targetVersion) { + // otherwise synthesize a changelog entry for the changes since the last tag + array_unshift($log, ['version' => $targetVersion, 'date' => date("Y-m-d"), 'features' => [], 'fixes' => [], 'changes' => ["Unspecified changes"]]); + } + $out = ""; + foreach ($log as $entry) { + // normalize the version string + preg_match('/^(\d+(?:\.\d+)*(?:-\d+)?).+$/D', $entry['version'], $m); + $version = $m[1]; + // output the entry + $out .= "-------------------------------------------------------------------\n"; + $out .= DateTimeImmutable::createFromFormat("!Y-m-d", $entry['date'], new \DateTimeZone("UTC"))->format("D, M d 00:00:00 \U\T\C Y"); + $out .= " - "; + $out .= "J. King "; + $out .= " - "; + $out .= "$version\n\n"; + foreach ($entry['features'] as $item) { + $out .= "- ".trim(preg_replace("/^/m", " ", $item))."\n"; + } + foreach ($entry['fixes'] as $item) { + $out .= "- ".trim(preg_replace("/^/m", " ", $item))."\n"; + } + foreach ($entry['changes'] as $item) { + $out .= "- ".trim(preg_replace("/^/m", " ", $item))."\n"; + } + $out .= "\n"; + } + return trim($out)."\n"; + } + protected function changelogDebian(array $log, string $targetVersion): string { $latest = $log[0]['version']; $baseVersion = preg_replace('/^(\d+(?:\.\d+)*).*/', "$1", $targetVersion);