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 0fe16d5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/Model/Changelog/ChangelogItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,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 +222,22 @@ public function getShortMessage()
}
}
}
// Escape strings that will be incorrectly identified as markdown
$strings = [
'__CLASS__',
'__TRAIT__',
'__DIR__',
'__FILE__',
'__LINE__',
'__METHOD__',
'__FUNCTION__',
'__NAMESPACE__',
];
foreach ($strings as $string) {
$message = str_replace($string, "`$string`", $message);
// Ensure that strings that were already correctly escaped are not double escaped
$message = str_replace("``$string``", "`$string`", $message);
}

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

Expand Down

0 comments on commit 0fe16d5

Please sign in to comment.