Skip to content

Commit

Permalink
FIX Handle double underscored PR titles in changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Mar 5, 2024
1 parent 45d8d1a commit 2a5fa2d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"php-http/guzzle7-adapter": "^1.0.0",
"guzzlehttp/guzzle": "^7.5.0",
"justinrainbow/json-schema": "^5.2.12",
"twig/twig": "^3.5.0"
"twig/twig": "^3.5.0",
"erusev/parsedown": "^1.7"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
Expand Down
13 changes: 12 additions & 1 deletion src/Model/Changelog/ChangelogItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use DateTime;
use Gitonomy\Git\Commit;
use SilverStripe\Cow\Utility\Format;
use Parsedown;

/**
* Represents a line-item in a changelog
Expand Down Expand Up @@ -200,7 +201,7 @@ public function getRawMessage()
}

/**
* Gets message with type tag stripped
* Gets message with type tag stripped and some escaping to pass CI markdown linting
*
* @return string markdown safe string
*/
Expand All @@ -222,6 +223,16 @@ public function getShortMessage()
}
}
}
// Escape the whole string if it contains markdown so that it won't fail CI linting
$parsedown = new Parsedown();
$parsed = $parsedown->text($message);
// remove <p> tags that were just added
$parsed = preg_replace(['#^<p>#', '#</p>#'], '', $parsed);
// compare with original message, if it's changed it means there was markdown in there
if ($message !== $parsed) {
$message = str_replace('`', '', $message);
$message = "`$message`";
}

return $message;
}
Expand Down
3 changes: 3 additions & 0 deletions tests/Model/Changelog/ChangelogItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ public function messageProvider()
'Default fallback doesn\'t categorise commit',
'Other changes'
],
// __CLASS__ and __TRAIT__ will be treated as markdown
['DOC Lorem __CLASS__ ipsum', '`Lorem __CLASS__ ipsum`', 'Documentation'],
['DOC Lorem `__TRAIT__` ipsum', '`Lorem __TRAIT__ ipsum`', 'Documentation'],
];
}

Expand Down

0 comments on commit 2a5fa2d

Please sign in to comment.