Source code for semantic_release.commit_parser.emoji
"""Commit parser which looks for emojis to determine the type of commit"""importloggingfromtypingimportTuplefromgit.objects.commitimportCommitfrompydantic.dataclassesimportdataclassfromsemantic_release.commit_parser._baseimportCommitParser,ParserOptionsfromsemantic_release.commit_parser.tokenimportParsedCommit,ParseResultfromsemantic_release.commit_parser.utilimportparse_paragraphsfromsemantic_release.enumsimportLevelBumplogger=logging.getLogger(__name__)
[docs]classEmojiCommitParser(CommitParser[ParseResult,EmojiParserOptions]):""" Parse a commit using an emoji in the subject line. When multiple emojis are encountered, the one with the highest bump level is used. If there are multiple emojis on the same level, the we use the one listed earliest in the configuration. If the message does not contain any known emojis, then the level to bump will be 0 and the type of change "Other". This parser never raises UnknownCommitMessageStyleError. Emojis are not removed from the description, and will appear alongside the commit subject in the changelog. """# TODO: Deprecate in lieu of get_default_options()parser_options=EmojiParserOptions
[docs]defparse(self,commit:Commit)->ParseResult:all_emojis=(self.options.major_tags+self.options.minor_tags+self.options.patch_tags)message=str(commit.message)subject=message.split("\n")[0]# Loop over emojis from most important to least important# Therefore, we find the highest level emoji firstprimary_emoji="Other"foremojiinall_emojis:ifemojiinsubject:primary_emoji=emojibreaklogger.debug("Selected %s as the primary emoji",primary_emoji)# Find which level this commit was fromlevel_bump=LevelBump.NO_RELEASEifprimary_emojiinself.options.major_tags:level_bump=LevelBump.MAJORelifprimary_emojiinself.options.minor_tags:level_bump=LevelBump.MINORelifprimary_emojiinself.options.patch_tags:level_bump=LevelBump.PATCH# All emojis will remain part of the returned descriptiondescriptions=parse_paragraphs(message)returnParsedCommit(bump=level_bump,type=primary_emoji,scope="",descriptions=descriptions,breaking_descriptions=(descriptions[1:]iflevel_bumpisLevelBump.MAJORelse[]),commit=commit,)