Skip to content

Commit

Permalink
Find the doc directory from libraries too.
Browse files Browse the repository at this point in the history
Libraries have further subdirectories below doc/, and we want to create CHANGES there too now.
  • Loading branch information
yunosh committed Oct 25, 2017
1 parent 012dd45 commit b130085
Showing 1 changed file with 53 additions and 26 deletions.
79 changes: 53 additions & 26 deletions lib/Components/Helper/ChangeLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,10 @@ class Components_Helper_ChangeLog
const HORDE_INFO = '/.horde.yml';

/** Path to the changelog.yml file. */
const CHANGELOG = '/doc/changelog.yml';

/** Path to the changelog.yml file up to Horde 5. */
const CHANGELOG_H5 = '/docs/changelog.yml';
const CHANGELOG = '/changelog.yml';

/** Path to the CHANGES file. */
const CHANGES = '/doc/CHANGES';

/** Path to the CHANGES file up to Horde 5. */
const CHANGES_H5 = '/docs/CHANGES';
const CHANGES = '/CHANGES';

/**
* The output handler.
Expand Down Expand Up @@ -114,11 +108,9 @@ public function changelogYml($log, $options)
*/
public function changelogFileExists()
{
foreach (array(self::CHANGELOG, self::CHANGELOG_H5) as $path) {
$changes = $this->_directory . $path;
if (file_exists($changes)) {
return $changes;
}
$changes = $this->_getDocDirectory() . self::CHANGELOG;
if (file_exists($changes)) {
return $changes;
}
return false;
}
Expand All @@ -137,14 +129,16 @@ public function addChangelog($entry)
throw new Components_Exception('.horde.yml is missing a \'version\' entry');
}
$version = $hordeInfo['version']['release'];
$changelog = Horde_Yaml::loadFile($this->_directory . self::CHANGELOG);
$changelog = Horde_Yaml::loadFile(
$this->_getDocDirectory() . self::CHANGELOG
);
$info = $changelog[$version];
$notes = explode("\n", trim($info['notes']));
array_unshift($notes, $entry);
$info['notes'] = implode("\n", $notes) . "\n";
$changelog[$version] = $info;
file_put_contents(
$this->_directory . self::CHANGELOG,
$this->_getDocDirectory() . self::CHANGELOG,
Horde_Yaml::dump($changelog, array('wordwrap' => 0))
);
return $version;
Expand Down Expand Up @@ -224,9 +218,7 @@ public function migrateToChangelogYml($xml)
}

// Create changelog.yml.
$changelog = is_dir($this->_directory . '/doc')
? $this->_directory . self::CHANGELOG
: $this->_directory . self::CHANGELOG_H5;
$changelog = $this->_getDocDirectory(true) . self::CHANGELOG;
file_put_contents(
$changelog,
Horde_Yaml::dump($changes, array('wordwrap' => 0))
Expand Down Expand Up @@ -359,11 +351,9 @@ public function getChangelog($root)
*/
public function changesFileExists()
{
foreach (array(self::CHANGES, self::CHANGES_H5) as $path) {
$changes = $this->_directory . $path;
if (file_exists($changes)) {
return $changes;
}
$changes = $this->_getDocDirectory() . self::CHANGES;
if (file_exists($changes)) {
return $changes;
}
return false;
}
Expand Down Expand Up @@ -404,17 +394,22 @@ public function addChange($entry, $changes)
public function updateChanges($options)
{
$changelog = $this->changelogFileExists();
$changes = $this->changesFileExists();
if (!$changelog || !$changes) {
if (!$changelog) {
return;
}

$allchanges = Horde_Yaml::loadFile($changelog);
$hordeInfo = $this->_getHordeInfo();
if (!isset($hordeInfo['version'])) {
throw new Components_Exception('.horde.yml is missing a \'version\' entry');
}

$changes = $this->changesFileExists();
if (!$changes) {
$changes = $this->_getDocDirectory(true) . self::CHANGES;
}

$allchanges = Horde_Yaml::loadFile($changelog);

if (empty($options['pretend'])) {
$changesfp = fopen($changes, 'w');
$started = false;
Expand Down Expand Up @@ -472,6 +467,38 @@ protected function _getHordeInfo()
return Horde_Yaml::loadFile($path);
}

/**
* Returns the path to the documenation directory, if it exists.
*
* @param boolean $mkdir Create the directory if it doesn't exist?
*
* @return string|boolean The directory name or false if not found and not
* created.
*/
protected function _getDocDirectory($mkdir = false)
{
if (is_dir($this->_directory . '/doc')) {
$dir = $this->_directory . '/doc';
} elseif (is_dir($this->_directory . '/docs')) {
$dir = $this->_directory . '/docs';
} elseif ($mkdir) {
$dir = $this->_directory . '/doc';
} else {
return false;
}
$info = $this->_getHordeInfo();
if ($info['type'] == 'library') {
$dir .= '/Horde/' . str_replace('_', '/', $info['id']);
}
if (!is_dir($dir)) {
if (!$mkdir) {
return false;
}
mkdir($dir, 0777, true);
}
return $dir;
}

/**
* Run a system call.
*
Expand Down

0 comments on commit b130085

Please sign in to comment.