Skip to content

Commit

Permalink
feat: add hidden configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Cesarato committed Feb 12, 2021
1 parent f3ebeee commit 42c9afe
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/Changelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public function generate(InputInterface $input, SymfonyStyle $output): int
$hash = $commit->getHash();
if (!empty($breakingChanges)) {
foreach ($breakingChanges as $description) {
$breakingType = Configuration::$breakingChangesType;
$breakingType = Configuration::BREAKING_CHANGES_TYPE;
$key = $this->getItemKey($description);
if (empty($description) || $itemKey === $key) {
$commit->setBreakingChange(true);
Expand Down Expand Up @@ -433,10 +433,10 @@ protected function getMarkdownChanges(array $changes): string
$shaGroup[] = '[' . $item->getShortHash() . "]({$url})";
}
}
if (!empty($refsGroup)) {
if (!$this->config->isHiddenReferences() && !empty($refsGroup)) {
$references = implode(', ', $refsGroup);
}
if (!empty($shaGroup)) {
if (!$this->config->isHiddenHash() && !empty($shaGroup)) {
$sha = '(' . implode(', ', $shaGroup) . ')';
}
$changelog .= Formatter::clean("* {$description} {$references} {$sha}");
Expand Down
89 changes: 87 additions & 2 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Configuration
*
* @var string
*/
public static $breakingChangesType = 'breaking_changes';
public const BREAKING_CHANGES_TYPE = 'breaking_changes';

/**
* Preset of breaking changes.
Expand Down Expand Up @@ -117,6 +117,27 @@ class Configuration
*/
protected $skipVerify = false;

/**
* Hidden references.
*
* @var bool
*/
protected $hiddenReferences = false;

/**
* Hidden mentions.
*
* @var bool
*/
protected $hiddenMentions = false;

/**
* Hidden hash.
*
* @var bool
*/
protected $hiddenHash = false;

/**
* Tag suffix.
*
Expand Down Expand Up @@ -211,6 +232,9 @@ public function fromArray(array $array)
'skipBump' => $this->skipBump(),
'skipTag' => $this->skipTag(),
'skipVerify' => $this->skipVerify(),
'hiddenHash' => $this->isHiddenHash(),
'hiddenMentions' => $this->isHiddenMentions(),
'hiddenReferences' => $this->isHiddenReferences(),
'urlProtocol' => $this->getUrlProtocol(),
'commitUrlFormat' => $this->getCommitUrlFormat(),
'compareUrlFormat' => $this->getCompareUrlFormat(),
Expand Down Expand Up @@ -259,6 +283,10 @@ public function fromArray(array $array)
$this->setSkipBump($params['skipBump']);
$this->setSkipTag($params['skipTag']);
$this->setSkipVerify($params['skipVerify']);
// Hidden
$this->setHiddenHash($params['hiddenHash']);
$this->setHiddenMentions($params['hiddenMentions']);
$this->setHiddenReferences($params['hiddenReferences']);
// Formats
$this->setUrlProtocol($params['urlProtocol']);
$this->setCommitUrlFormat($params['commitUrlFormat']);
Expand Down Expand Up @@ -505,7 +533,7 @@ public function setSkipVerify(bool $skipVerify): Configuration
*/
public function getBreakingChangesPreset(): array
{
return [self::$breakingChangesType => $this->breakingChangesPreset];
return [self::BREAKING_CHANGES_TYPE => $this->breakingChangesPreset];
}

public function getCommitUrlFormat(): string
Expand Down Expand Up @@ -579,4 +607,61 @@ public function setUrlProtocol(string $urlProtocol): Configuration

return $this;
}

/**
* @return bool
*/
public function isHiddenReferences() : bool
{
return $this->hiddenReferences;
}

/**
* @param bool $hiddenReferences
* @return Configuration
*/
public function setHiddenReferences(bool $hiddenReferences) : Configuration
{
$this->hiddenReferences = $hiddenReferences;

return $this;
}

/**
* @return bool
*/
public function isHiddenMentions() : bool
{
return $this->hiddenMentions;
}

/**
* @param bool $hiddenMentions
* @return Configuration
*/
public function setHiddenMentions(bool $hiddenMentions) : Configuration
{
$this->hiddenMentions = $hiddenMentions;

return $this;
}

/**
* @return bool
*/
public function isHiddenHash() : bool
{
return $this->hiddenHash;
}

/**
* @param bool $hiddenHash
* @return Configuration
*/
public function setHiddenHash(bool $hiddenHash) : Configuration
{
$this->hiddenHash = $hiddenHash;

return $this;
}
}
2 changes: 1 addition & 1 deletion src/Git/ConventionalCommit.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function getType(): Type
{
$type = $this->type;
if ($this->isBreakingChange()) {
$type = new Type(Configuration::$breakingChangesType);
$type = new Type(Configuration::BREAKING_CHANGES_TYPE);
}

return $type;
Expand Down

0 comments on commit 42c9afe

Please sign in to comment.