-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the composer-changelogs project. | ||
* | ||
* (c) Loïck Piera <pyrech@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Pyrech\ComposerChangelogs; | ||
|
||
final class Config | ||
{ | ||
private static $validCommitValues = [ | ||
'never', | ||
'ask', | ||
'always', | ||
]; | ||
|
||
/** @var string */ | ||
private $commit = 'never'; | ||
|
||
/** @var string[] */ | ||
private $warnings = []; | ||
|
||
private function __construct() {} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getCommit() | ||
{ | ||
return $this->commit; | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getWarnings() | ||
{ | ||
return $this->warnings; | ||
} | ||
|
||
/** | ||
* @param array $extra | ||
* | ||
* @return Config | ||
*/ | ||
public static function createFromExtra(array $extra) | ||
{ | ||
$config = new Config(); | ||
|
||
if (array_key_exists('commit', $extra)) { | ||
if (in_array($extra['commit'], self::$validCommitValues, true)) { | ||
$config->commit = $extra['commit']; | ||
} else { | ||
$config->warnings[] = self::createWarning( | ||
$extra, | ||
'commit', | ||
$config->commit, | ||
sprintf('Valid options are "%s".', implode('", "', self::$validCommitValues)) | ||
); | ||
} | ||
} | ||
|
||
return $config; | ||
} | ||
|
||
/** | ||
* @param array $extra | ||
* @param string $key | ||
* @param mixed $default | ||
* @param string $additionalMessage | ||
* | ||
* @return string | ||
*/ | ||
private static function createWarning(array $extra, $key, $default, $additionalMessage = '') | ||
{ | ||
$warning = sprintf( | ||
'Invalid value "%s" for option "%s", defaulting to "%s".', | ||
$extra[$key], | ||
$key, | ||
$default | ||
); | ||
|
||
if ($additionalMessage) { | ||
$warning .= ' ' . $additionalMessage; | ||
} | ||
|
||
return $warning; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the composer-changelogs project. | ||
* | ||
* (c) Loïck Piera <pyrech@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Pyrech\ComposerChangelogs\Utils; | ||
|
||
class GitHelper | ||
{ | ||
/** | ||
* @param string $title | ||
* @param string $description | ||
*/ | ||
public function commit($title, $description) | ||
{ | ||
// if (!$this->isGitInstalled()) { | ||
// return; | ||
// } | ||
|
||
exec('git commit ' . escapeshellarg($title.PHP_EOL.PHP_EOL.$description)); | ||
} | ||
} |