Skip to content

Commit

Permalink
Don't pass the directory to each method.
Browse files Browse the repository at this point in the history
Pass a configuration object once to the constructor instead.
  • Loading branch information
yunosh committed Oct 25, 2017
1 parent 8fb8cfa commit 3eb12b1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
4 changes: 2 additions & 2 deletions data/distribute/openSUSE/components.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,6 @@ function processDependencies($component) {
}
// build a text containing only the last change. Use dash instead of *

$changes = "updated to version $package_version\n- [xxx] something changed\n- [yyy] This changed too" . $component->getChangelog(new Components_Helper_ChangeLog($this->_output));
$changes = "updated to version $package_version\n- [xxx] something changed\n- [yyy] This changed too" . $component->getChangelog(new Components_Helper_ChangeLog($this->_output, $this->_config));
//$changes = $component->getInstallationFileList();
shell_exec("cd $destination && mv package.spec $package_name.spec && osc vc -m \"$changes\" &> file");
shell_exec("cd $destination && mv package.spec $package_name.spec && osc vc -m \"$changes\" &> file");
41 changes: 24 additions & 17 deletions lib/Components/Helper/ChangeLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,29 @@ class Components_Helper_ChangeLog
/**
* The output handler.
*
* @param Component_Output
* @var Component_Output
*/
private $_output;
protected $_output;

/**
* The path to the component directory.
*
* @var string
*/
protected $_directory;

/**
* Constructor.
*
* @param Component_Output $output The output handler.
* @param Component_Output $output The output handler.
* @param Components_Config $config The configuration.
*/
public function __construct(Components_Output $output)
public function __construct(
Components_Output $output, Components_Config $config
)
{
$this->_output = $output;
$this->_directory = $config->getPath();
}

/**
Expand Down Expand Up @@ -83,15 +94,13 @@ public function packageXml($log, $xml, $file, $options)
* Update CHANGES file.
*
* @param string $log The log entry.
* @param string $directory The path to the component directory.
* @param array $options Additional options.
*
* @return NULL
* @return string Path to the updated CHANGES file.
*/
public function changes($log, $directory, $options)
public function changes($log, $options)
{
$changes = false;
if ($changes = $this->changesFileExists($directory)) {
if ($changes = $this->changesFileExists($this->_directory)) {
if (empty($options['pretend'])) {
$this->addChange($log, $changes);
$this->_output->ok(
Expand All @@ -116,21 +125,20 @@ public function changes($log, $directory, $options)
* Returns the link to the change log.
*
* @param string $root The root of the component in the repository.
* @param string $directory The working directory.
*
* @return string|null The link to the change log.
*/
public function getChangelog($root, $directory)
public function getChangelog($root)
{
if ($changes = $this->changesFileExists($directory)) {
if ($changes = $this->changesFileExists($this->_directory)) {
$blob = trim(
$this->systemInDirectory(
'git log --format="%H" HEAD^..HEAD',
$directory,
$this->_directory,
array()
)
);
$changes = preg_replace('#^' . $directory . '#', '', $changes);
$changes = preg_replace('#^' . $this->_directory . '#', '', $changes);
return 'https://github.com/horde/horde/blob/' . $blob . $root . $changes;
}
return '';
Expand Down Expand Up @@ -175,15 +183,14 @@ protected function system($call, $options)
/**
* Indicates if there is a CHANGES file for this component.
*
* @param string $dir The basic component directory.
*
* @return string|boolean The path to the CHANGES file if it exists, false
* otherwise.
*/
public function changesFileExists($dir)
public function changesFileExists()
{
foreach (array(self::CHANGES, self::CHANGES_H5) as $path) {
$changes = $dir . $path;
$changes = $this->_directory . $path;
if (file_exists($changes)) {
return $changes;
}
Expand Down
7 changes: 5 additions & 2 deletions lib/Components/Release/Task/Announce.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ public function run(&$options)
'The full list of changes can be viewed here:' .
"\n\n" .
$this->getComponent()->getChangelog(
new Components_Helper_ChangeLog($this->getOutput())
new Components_Helper_ChangeLog(
$this->getOutput(),
$this->getComponent()->getConfig()
)
) .
"\n\n" .
'Have fun!' .
Expand Down Expand Up @@ -122,4 +125,4 @@ public function run(&$options)
$this->getOutput()->info($info);
}
}
}
}

0 comments on commit 3eb12b1

Please sign in to comment.