22
33import os
44import re
5+ import typing as t
56from collections import OrderedDict
67from textwrap import dedent
78
1213
1314from commitizen import defaults , git
1415from commitizen .cz .base import BaseCommitizen
15- from commitizen .defaults import Questions
1616
1717from cz_version_bump .git import repo_name_from_git_remote
1818from cz_version_bump .thanks import Thanker
1919
20+ if t .TYPE_CHECKING :
21+ from commitizen .defaults import Questions
22+
2023issue_id_pattern = re .compile (r"\s+\(#(\d+)\)$" )
2124
2225
2326class MeltanoCommitizen (BaseCommitizen ):
24- bump_pattern = defaults .bump_pattern
25- bump_map = defaults .bump_map
26- bump_pattern = r"^(feat|fix|refactor|perf|break|docs|ci|chore|style|revert|test|build|packaging)(\(.+\))?(!)?"
27- bump_map = OrderedDict (
27+ bump_pattern = r"^(feat|fix|refactor|perf|break|docs|ci|chore|style|revert|test|build|packaging)(\(.+\))?(!)?" # noqa: E501
28+ bump_map : t .ClassVar = OrderedDict (
2829 (
2930 (
3031 r"^break" ,
@@ -44,8 +45,8 @@ class MeltanoCommitizen(BaseCommitizen):
4445 (r"^packaging" , defaults .PATCH ),
4546 )
4647 )
47- commit_parser = r"^(?P<change_type>feat|fix|refactor|perf|break|docs|packaging)(?:\((?P<scope>[^()\r\n]*)\)|\()?(?P<breaking>!)?:\s(?P<message>.*)?"
48- schema_pattern = r"(feat|fix|refactor|perf|break|docs|ci|chore|style|revert|test|build|packaging)(?:\((?P<scope>[^()\r\n]*)\)|\()?(?P<breaking>!)?:(\s.*)"
48+ commit_parser = r"^(?P<change_type>feat|fix|refactor|perf|break|docs|packaging)(?:\((?P<scope>[^()\r\n]*)\)|\()?(?P<breaking>!)?:\s(?P<message>.*)?" # noqa: E501
49+ schema_pattern = r"(feat|fix|refactor|perf|break|docs|ci|chore|style|revert|test|build|packaging)(?:\((?P<scope>[^()\r\n]*)\)|\()?(?P<breaking>!)?:(\s.*)" # noqa: E501
4950 schema = dedent (
5051 """
5152 <type>(<scope>): <subject>
@@ -55,7 +56,7 @@ class MeltanoCommitizen(BaseCommitizen):
5556 (BREAKING CHANGE: )<footer>
5657 """
5758 ).strip ("\n " )
58- change_type_order = [
59+ change_type_order = [ # noqa: RUF012
5960 "BREAKING CHANGES" ,
6061 "✨ New" ,
6162 "🐛 Fixes" ,
@@ -64,7 +65,7 @@ class MeltanoCommitizen(BaseCommitizen):
6465 "📚 Documentation Improvements" ,
6566 "📦 Packaging changes" ,
6667 ]
67- change_type_map = {
68+ change_type_map = { # noqa: RUF012
6869 "break" : "BREAKING CHANGES" ,
6970 "feat" : "✨ New" ,
7071 "fix" : "🐛 Fixes" ,
@@ -74,14 +75,14 @@ class MeltanoCommitizen(BaseCommitizen):
7475 "packaging" : "📦 Packaging changes" ,
7576 }
7677
77- def __init__ (self , * args , ** kwargs ) :
78+ def __init__ (self : MeltanoCommitizen , * args : t . Any , ** kwargs : t . Any ) -> None :
7879 super ().__init__ (* args , ** kwargs )
7980 self .repo_name = os .environ .get (
8081 "GITHUB_REPOSITORY" , repo_name_from_git_remote ()
8182 )
8283 self .thanker = Thanker (self .repo_name )
8384
84- def questions (self ) -> Questions :
85+ def questions (self : MeltanoCommitizen ) -> Questions :
8586 """Questions regarding the commit message."""
8687 return [
8788 {
@@ -92,7 +93,7 @@ def questions(self) -> Questions:
9293 {"value" : "fix" , "name" : "fix: A bug fix." },
9394 {
9495 "value" : "refactor" ,
95- "name" : "refactor: A code change that neither fixes a bug nor adds a feature." ,
96+ "name" : "refactor: A code change that neither fixes a bug nor adds a feature." , # noqa: E501
9697 },
9798 {
9899 "value" : "perf" ,
@@ -102,7 +103,7 @@ def questions(self) -> Questions:
102103 {"value" : "break" , "name" : "break: A breaking change." },
103104 {
104105 "value" : "chore" ,
105- "name" : "chore: A change that doesn't affect the meaning of the codebase." ,
106+ "name" : "chore: A change that doesn't affect the meaning of the codebase." , # noqa: E501
106107 },
107108 {"value" : "style" , "name" : "style: A code style change." },
108109 {"value" : "revert" , "name" : "revert: Revert to a commit." },
@@ -111,7 +112,7 @@ def questions(self) -> Questions:
111112 {"value" : "ci" , "name" : "ci: A change to CI/CD." },
112113 {
113114 "value" : "packaging" ,
114- "name" : "packaging: A change to how the project is packaged or distributed." ,
115+ "name" : "packaging: A change to how the project is packaged or distributed." , # noqa: E501
115116 },
116117 ],
117118 "message" : "Select the type of change you are committing" ,
@@ -123,15 +124,15 @@ def questions(self) -> Questions:
123124 },
124125 ]
125126
126- def message (self , answers : dict ) -> str :
127+ def message (self : MeltanoCommitizen , answers : dict ) -> str :
127128 """Format the git message."""
128129 message_template = Template ("{{change_type}}: {{message}}" )
129130 if getattr (Template , "substitute" , None ):
130131 return message_template .substitute (** answers )
131132 return message_template .render (** answers )
132133
133134 def changelog_message_builder_hook (
134- self ,
135+ self : MeltanoCommitizen ,
135136 parsed_message : dict [str , str ],
136137 commit : git .GitCommit ,
137138 ) -> dict :
@@ -154,13 +155,13 @@ def changelog_message_builder_hook(
154155 # Convert to int then back to str to validate that it is an integer:
155156 issue_id = str (int (issue_id_pattern .findall (message )[0 ]))
156157 message = issue_id_pattern .sub ("" , message )
157- except Exception :
158+ except Exception : # noqa: BLE001, S110
158159 pass
159160 else :
160- # NOTE: The "issue ID" will usually be for a pull request. GitHub considers PRs to be
161- # issues in their APIs, but not vice versa.
161+ # NOTE: The "issue ID" will usually be for a pull request. GitHub considers
162+ # PRs to be issues in their APIs, but not vice versa.
162163 parsed_message ["message" ] = (
163- f"[#{ issue_id } ](https://github.com/{ self .repo_name } /issues/{ issue_id } ) { message } "
164+ f"[#{ issue_id } ](https://github.com/{ self .repo_name } /issues/{ issue_id } ) { message } " # noqa: E501
164165 )
165166
166167 # Remove the scope because we are too inconsistent with them.
@@ -169,13 +170,17 @@ def changelog_message_builder_hook(
169170 # Thank third-party contributors:
170171 parsed_message ["message" ] += self .thanker .thanks_message (commit )
171172
172- # Remove the commit message body because is isn't needed for the changelog, and can cause
173- # formatting issues if present.
173+ # Remove the commit message body because is isn't needed for the changelog, and
174+ # can cause formatting issues if present.
174175 commit .body = ""
175176
176177 return parsed_message
177178
178- def changelog_hook (self , full_changelog : str , partial_changelog : str | None ) -> str :
179+ def changelog_hook (
180+ self : MeltanoCommitizen ,
181+ full_changelog : str ,
182+ partial_changelog : str | None ,
183+ ) -> str :
179184 """Perform custom action at the end of changelog generation.
180185
181186 full_changelog: The full changelog about to being written into the file.
0 commit comments