Parser
Parsing utilities for commit messages.
MatchLike
Bases: Protocol
Protocol for objects that behave like re.Match.
Source code in src/codemap/git/commit_linter/parser.py
16 17 18 19 20 21 22 23 24 25 |
|
groupdict
groupdict() -> dict[str, Any]
Return the dictionary mapping group names to the matched values.
Source code in src/codemap/git/commit_linter/parser.py
19 20 21 |
|
group
group(group_id: int | str = 0) -> str | None
Return the match group by number or name.
Source code in src/codemap/git/commit_linter/parser.py
23 24 25 |
|
CommitParser
Parser for conventional commit messages.
This parser handles parsing and validation of commit messages following the Conventional Commits specification. It supports extracting commit type, scope, description, body, and footers.
Source code in src/codemap/git/commit_linter/parser.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
|
__init__
__init__() -> None
Initialize the commit parser.
Source code in src/codemap/git/commit_linter/parser.py
35 36 37 38 39 |
|
parse_commit
parse_commit(message: str) -> MatchLike | None
Parse a commit message using the main regex pattern.
This method parses the commit message according to the Conventional Commits specification, extracting the header, body, and footers. It handles cases where footers might not be immediately detected by the main regex pattern.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message
|
str
|
The raw commit message string to parse. |
required |
Returns:
Type | Description |
---|---|
MatchLike | None
|
A MatchLike object containing the parsed commit components (type, scope, description, |
MatchLike | None
|
body, footers) if successful, or None if the message doesn't match the expected format. |
MatchLike | None
|
The returned object provides access to match groups via group() and groupdict() methods, |
MatchLike | None
|
with the addition of a 'footers' group that may be detected beyond the main regex match. |
Source code in src/codemap/git/commit_linter/parser.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
parse_footers
parse_footers(
footers_str: str | None,
) -> list[dict[str, Any]]
Parses commit footers from a string, handling multi-line values.
Parses footer lines according to Conventional Commits specification, where each footer consists of a token, separator, and value. Handles both strict uppercase tokens and potential invalid footers for error reporting. Preserves multi-line values and blank lines within footer values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
footers_str
|
str | None
|
The string containing footer lines to parse. May be None if no footers exist. |
required |
Returns:
Type | Description |
---|---|
list[dict[str, Any]]
|
A list of dictionaries, where each dictionary represents a parsed footer with keys: |
list[dict[str, Any]]
|
|
list[dict[str, Any]]
|
|
list[dict[str, Any]]
|
|
Note
For invalid footers (those not matching strict regex but looking like footers), the dictionary will still be created but marked as invalid during validation.
Source code in src/codemap/git/commit_linter/parser.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
|
split_body_footers
split_body_footers(
body_and_footers_str: str | None,
) -> tuple[str | None, str | None]
Splits the text after the header into body and footers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
body_and_footers_str
|
str | None
|
The string containing both body and footers text, or None. |
required |
Returns:
Type | Description |
---|---|
tuple[str | None, str | None]
|
A tuple containing: - First element: The body text as a string, or None if empty/not present - Second element: The footers text as a string, or None if empty/not present |
Source code in src/codemap/git/commit_linter/parser.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
|