2
2
3
3
import os
4
4
import re
5
+ import typing as t
5
6
from collections import OrderedDict
6
7
from textwrap import dedent
7
8
12
13
13
14
from commitizen import defaults , git
14
15
from commitizen .cz .base import BaseCommitizen
15
- from commitizen .defaults import Questions
16
16
17
17
from cz_version_bump .git import repo_name_from_git_remote
18
18
from cz_version_bump .thanks import Thanker
19
19
20
+ if t .TYPE_CHECKING :
21
+ from commitizen .defaults import Questions
22
+
20
23
issue_id_pattern = re .compile (r"\s+\(#(\d+)\)$" )
21
24
22
25
23
26
class 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 (
28
29
(
29
30
(
30
31
r"^break" ,
@@ -44,8 +45,8 @@ class MeltanoCommitizen(BaseCommitizen):
44
45
(r"^packaging" , defaults .PATCH ),
45
46
)
46
47
)
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
49
50
schema = dedent (
50
51
"""
51
52
<type>(<scope>): <subject>
@@ -55,7 +56,7 @@ class MeltanoCommitizen(BaseCommitizen):
55
56
(BREAKING CHANGE: )<footer>
56
57
"""
57
58
).strip ("\n " )
58
- change_type_order = [
59
+ change_type_order = [ # noqa: RUF012
59
60
"BREAKING CHANGES" ,
60
61
"✨ New" ,
61
62
"🐛 Fixes" ,
@@ -64,7 +65,7 @@ class MeltanoCommitizen(BaseCommitizen):
64
65
"📚 Documentation Improvements" ,
65
66
"📦 Packaging changes" ,
66
67
]
67
- change_type_map = {
68
+ change_type_map = { # noqa: RUF012
68
69
"break" : "BREAKING CHANGES" ,
69
70
"feat" : "✨ New" ,
70
71
"fix" : "🐛 Fixes" ,
@@ -74,14 +75,14 @@ class MeltanoCommitizen(BaseCommitizen):
74
75
"packaging" : "📦 Packaging changes" ,
75
76
}
76
77
77
- def __init__ (self , * args , ** kwargs ) :
78
+ def __init__ (self : MeltanoCommitizen , * args : t . Any , ** kwargs : t . Any ) -> None :
78
79
super ().__init__ (* args , ** kwargs )
79
80
self .repo_name = os .environ .get (
80
81
"GITHUB_REPOSITORY" , repo_name_from_git_remote ()
81
82
)
82
83
self .thanker = Thanker (self .repo_name )
83
84
84
- def questions (self ) -> Questions :
85
+ def questions (self : MeltanoCommitizen ) -> Questions :
85
86
"""Questions regarding the commit message."""
86
87
return [
87
88
{
@@ -92,7 +93,7 @@ def questions(self) -> Questions:
92
93
{"value" : "fix" , "name" : "fix: A bug fix." },
93
94
{
94
95
"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
96
97
},
97
98
{
98
99
"value" : "perf" ,
@@ -102,7 +103,7 @@ def questions(self) -> Questions:
102
103
{"value" : "break" , "name" : "break: A breaking change." },
103
104
{
104
105
"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
106
107
},
107
108
{"value" : "style" , "name" : "style: A code style change." },
108
109
{"value" : "revert" , "name" : "revert: Revert to a commit." },
@@ -111,7 +112,7 @@ def questions(self) -> Questions:
111
112
{"value" : "ci" , "name" : "ci: A change to CI/CD." },
112
113
{
113
114
"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
115
116
},
116
117
],
117
118
"message" : "Select the type of change you are committing" ,
@@ -123,15 +124,15 @@ def questions(self) -> Questions:
123
124
},
124
125
]
125
126
126
- def message (self , answers : dict ) -> str :
127
+ def message (self : MeltanoCommitizen , answers : dict ) -> str :
127
128
"""Format the git message."""
128
129
message_template = Template ("{{change_type}}: {{message}}" )
129
130
if getattr (Template , "substitute" , None ):
130
131
return message_template .substitute (** answers )
131
132
return message_template .render (** answers )
132
133
133
134
def changelog_message_builder_hook (
134
- self ,
135
+ self : MeltanoCommitizen ,
135
136
parsed_message : dict [str , str ],
136
137
commit : git .GitCommit ,
137
138
) -> dict :
@@ -154,13 +155,13 @@ def changelog_message_builder_hook(
154
155
# Convert to int then back to str to validate that it is an integer:
155
156
issue_id = str (int (issue_id_pattern .findall (message )[0 ]))
156
157
message = issue_id_pattern .sub ("" , message )
157
- except Exception :
158
+ except Exception : # noqa: BLE001, S110
158
159
pass
159
160
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.
162
163
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
164
165
)
165
166
166
167
# Remove the scope because we are too inconsistent with them.
@@ -169,13 +170,17 @@ def changelog_message_builder_hook(
169
170
# Thank third-party contributors:
170
171
parsed_message ["message" ] += self .thanker .thanks_message (commit )
171
172
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.
174
175
commit .body = ""
175
176
176
177
return parsed_message
177
178
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 :
179
184
"""Perform custom action at the end of changelog generation.
180
185
181
186
full_changelog: The full changelog about to being written into the file.
0 commit comments