[docs]classTagCommitParser(CommitParser[ParseResult,TagParserOptions]):""" Parse a commit message according to the 1.0 version of python-semantic-release. It expects a tag of some sort in the commit message and will use the rest of the first line as changelog content. """# TODO: Deprecate in lieu of get_default_options()parser_options=TagParserOptions
[docs]defparse(self,commit:Commit)->ParseResult:message=str(commit.message)# Attempt to parse the commit message with a regular expressionparsed=re_parser.match(message)ifnotparsed:return_logged_parse_error(commit,error=f"Unable to parse the given commit message: {message!r}")subject=parsed.group("subject")# Check tags for minor or patchifself.options.minor_taginmessage:level="feature"level_bump=LevelBump.MINORifsubject:subject=subject.replace(self.options.minor_tag,"")elifself.options.patch_taginmessage:level="fix"level_bump=LevelBump.PATCHifsubject:subject=subject.replace(self.options.patch_tag,"")else:# We did not find any tags in the commit messagereturn_logged_parse_error(commit,error=f"Unable to parse the given commit message: {message!r}")ifparsed.group("text"):descriptions=parse_paragraphs(parsed.group("text"))else:descriptions=[]descriptions.insert(0,subject.strip())# Look for descriptions of breaking changesbreaking_descriptions=[match.group(1)formatchin(breaking_re.match(p)forpindescriptions[1:])ifmatch]ifbreaking_descriptions:level="breaking"level_bump=LevelBump.MAJORlog.debug("commit %s upgraded to a %s level_bump due to breaking_descriptions",commit.hexsha,level_bump,)returnParsedCommit(bump=level_bump,type=level,scope="",descriptions=descriptions,breaking_descriptions=breaking_descriptions,commit=commit,)