Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX Handle double underscored PR titles in changelog #250

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 escaped if it contains markdown
*
* @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
Loading