Skip to content

Commit

Permalink
Issue #434: Add changelog command and enhance version command (#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
yorkshire-pudding authored Sep 6, 2024
1 parent a4f6bfb commit d5733e0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ system for each contributed module, theme and layout.
- An implementation of Backdrop's telemetry function.
- A config-clear command.
- A new command to enable and disable the theme debug setting.
- A changelog command to display the current CHANGELOG for the installed version of Bee.

### Changed
- Call the install script using the PHP_BINARY constant to avoid issues if the
Expand All @@ -32,6 +33,7 @@ execute permissions have not been added to the file.
- The Wiki is now edited via the `docs` folder of the main repo. Pages can be edited as part of a pull request.
- Added 'context' of 'Bee' to any translatable strings passed to `t()`.
- Moved 'theme' commands and tests from 'projects' to dedicated files.
- Changed the version command to include the latest "Unreleased" date for dev versions.

### Fixed
- Unhandled Error if the executables called in the database commands does
Expand Down
3 changes: 3 additions & 0 deletions box.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"commands",
"includes"
],
"files": [
"CHANGELOG.md"
],
"compactors": [
"KevinGH\\Box\\Compactor\\Php"
],
Expand Down
46 changes: 45 additions & 1 deletion commands/version.bee.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
* The command for displaying the current version of Bee.
*/

/**
* Define the path for the CHANGELOG.
*/
define('BEE_CHANGELOG_PATH', __DIR__ . '/../CHANGELOG.md');

/**
* Implements hook_bee_command().
*/
Expand All @@ -17,16 +22,48 @@ function version_bee_command() {
'bee version' => bt('Output the current version.'),
),
),
'changelog' => array(
'description' => bt('Display the current CHANGELOG of Bee.'),
'callback' => 'changelog_bee_callback',
'group' => 'information',
'examples' => array(
'bee changelog' => bt('Output the current CHANGELOG.'),
),
),
);
}

/**
* Command callback: Run cron.
* Command callback: Version.
*/
function version_bee_callback($arguments, $options) {
$current_version = BEE_VERSION;
$latest_release = BEE_LATEST_RELEASE;

// If the version is the dev version, then we also want the date of the last
// change.
$dev_version = FALSE;
// Current version will only match latest release for the actual release
// packages so any difference will indicate the dev version is in use.
if ($current_version != $latest_release) {
$dev_version = TRUE;
// Get the CHANGELOG lines as an array so we can check each line.
$changelog_lines = file(BEE_CHANGELOG_PATH);
// Define the search string to identify the line.
$search_string = "## [Unreleased] - ";
// Loop through each line and look for the search string.
foreach ($changelog_lines as $line) {
if (strpos($line, $search_string) !== FALSE) {
// Extract the latest date from this line.
$unreleased_date = substr($line, 18, 10);
// Append it to the current version.
$current_version .= ' - ' . $unreleased_date;
// Stop processing more lines.
break;
}
}
}

$output = array();
$output[] = array(
'type' => 'text',
Expand All @@ -48,3 +85,10 @@ function version_bee_callback($arguments, $options) {
);
return $output;
}

/**
* Command callback: Changelog.
*/
function changelog_bee_callback($arguments, $options) {
echo file_get_contents(BEE_CHANGELOG_PATH);
}

0 comments on commit d5733e0

Please sign in to comment.