zendev-commit 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- zendev/commit/__init__.py +572 -0
- zendev/commit/py.typed +0 -0
- zendev/conventional/__init__.py +145 -0
- zendev/conventional/py.typed +0 -0
- zendev/data/LICENSE.gitmoji +21 -0
- zendev/data/emoji-conventions.toml +80 -0
- zendev/data/gitmojis.json +605 -0
- zendev/gitmoji/__init__.py +182 -0
- zendev/gitmoji/py.typed +0 -0
- zendev_commit-0.2.0.dist-info/METADATA +119 -0
- zendev_commit-0.2.0.dist-info/RECORD +13 -0
- zendev_commit-0.2.0.dist-info/WHEEL +4 -0
- zendev_commit-0.2.0.dist-info/entry_points.txt +3 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"""Conventional Commits 1.0.0 parsing primitives."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"ConventionalCommit",
|
|
10
|
+
"ConventionalFooter",
|
|
11
|
+
"ConventionalHeader",
|
|
12
|
+
"ParseIssue",
|
|
13
|
+
"parse_conventional_commit",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
_HEADER_PATTERN = re.compile(
|
|
17
|
+
r"^(?P<type>[^\s():]+)"
|
|
18
|
+
r"(?:\((?P<scope>[^()\r\n]+)\))?"
|
|
19
|
+
r"(?P<breaking>!)?"
|
|
20
|
+
r": "
|
|
21
|
+
r"(?P<description>[^\r\n]+)$"
|
|
22
|
+
)
|
|
23
|
+
_FOOTER_PATTERN = re.compile(
|
|
24
|
+
r"^(?P<token>BREAKING CHANGE|[^\s:#]+)"
|
|
25
|
+
r"(?P<separator>: | #)"
|
|
26
|
+
r"(?P<value>.+)$"
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass(frozen=True, slots=True)
|
|
31
|
+
class ParseIssue:
|
|
32
|
+
"""A stable, user-facing parse failure."""
|
|
33
|
+
|
|
34
|
+
code: str
|
|
35
|
+
message: str
|
|
36
|
+
line: int = 1
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@dataclass(frozen=True, slots=True)
|
|
40
|
+
class ConventionalHeader:
|
|
41
|
+
type: str
|
|
42
|
+
scope: str | None
|
|
43
|
+
description: str
|
|
44
|
+
breaking: bool
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@dataclass(frozen=True, slots=True)
|
|
48
|
+
class ConventionalFooter:
|
|
49
|
+
token: str
|
|
50
|
+
value: str
|
|
51
|
+
|
|
52
|
+
@property
|
|
53
|
+
def is_breaking(self) -> bool:
|
|
54
|
+
return self.token in {"BREAKING CHANGE", "BREAKING-CHANGE"}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@dataclass(frozen=True, slots=True)
|
|
58
|
+
class ConventionalCommit:
|
|
59
|
+
header: ConventionalHeader
|
|
60
|
+
body: str | None
|
|
61
|
+
footers: tuple[ConventionalFooter, ...]
|
|
62
|
+
|
|
63
|
+
@property
|
|
64
|
+
def is_breaking(self) -> bool:
|
|
65
|
+
return self.header.breaking or any(footer.is_breaking for footer in self.footers)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _parse_footer_block(lines: list[str]) -> tuple[ConventionalFooter, ...] | None:
|
|
69
|
+
if not lines or not _FOOTER_PATTERN.fullmatch(lines[0]):
|
|
70
|
+
return None
|
|
71
|
+
|
|
72
|
+
footers: list[ConventionalFooter] = []
|
|
73
|
+
token: str | None = None
|
|
74
|
+
value_lines: list[str] = []
|
|
75
|
+
for line in lines:
|
|
76
|
+
match = _FOOTER_PATTERN.fullmatch(line)
|
|
77
|
+
if match:
|
|
78
|
+
if token is not None:
|
|
79
|
+
footers.append(ConventionalFooter(token=token, value="\n".join(value_lines)))
|
|
80
|
+
token = match.group("token")
|
|
81
|
+
value_lines = [match.group("value")]
|
|
82
|
+
elif token is not None and line:
|
|
83
|
+
value_lines.append(line)
|
|
84
|
+
else:
|
|
85
|
+
return None
|
|
86
|
+
|
|
87
|
+
assert token is not None
|
|
88
|
+
footers.append(ConventionalFooter(token=token, value="\n".join(value_lines)))
|
|
89
|
+
return tuple(footers)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _split_body_and_footers(lines: list[str]) -> tuple[str | None, tuple[ConventionalFooter, ...]]:
|
|
93
|
+
while lines and not lines[-1]:
|
|
94
|
+
lines.pop()
|
|
95
|
+
if not lines:
|
|
96
|
+
return None, ()
|
|
97
|
+
|
|
98
|
+
paragraph_starts = [0]
|
|
99
|
+
for index in range(1, len(lines)):
|
|
100
|
+
if lines[index - 1] == "" and lines[index] != "":
|
|
101
|
+
paragraph_starts.append(index)
|
|
102
|
+
|
|
103
|
+
for start in reversed(paragraph_starts):
|
|
104
|
+
footers = _parse_footer_block(lines[start:])
|
|
105
|
+
if footers is None:
|
|
106
|
+
continue
|
|
107
|
+
body_lines = lines[:start]
|
|
108
|
+
while body_lines and not body_lines[-1]:
|
|
109
|
+
body_lines.pop()
|
|
110
|
+
return ("\n".join(body_lines) or None), footers
|
|
111
|
+
|
|
112
|
+
return "\n".join(lines), ()
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def parse_conventional_commit(text: str) -> tuple[ConventionalCommit | None, ParseIssue | None]:
|
|
116
|
+
"""Parse a Conventional Commits 1.0.0 message without imposing project policy."""
|
|
117
|
+
|
|
118
|
+
lines = text.splitlines()
|
|
119
|
+
if not lines or not lines[0]:
|
|
120
|
+
return None, ParseIssue("empty-message", "The commit message is empty.")
|
|
121
|
+
|
|
122
|
+
match = _HEADER_PATTERN.fullmatch(lines[0])
|
|
123
|
+
if match is None:
|
|
124
|
+
return None, ParseIssue(
|
|
125
|
+
"invalid-conventional-header",
|
|
126
|
+
"Expected <type>(<scope>)!: <description>.",
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
header = ConventionalHeader(
|
|
130
|
+
type=match.group("type"),
|
|
131
|
+
scope=match.group("scope"),
|
|
132
|
+
description=match.group("description"),
|
|
133
|
+
breaking=match.group("breaking") is not None,
|
|
134
|
+
)
|
|
135
|
+
if len(lines) == 1:
|
|
136
|
+
return ConventionalCommit(header=header, body=None, footers=()), None
|
|
137
|
+
if lines[1] != "":
|
|
138
|
+
return None, ParseIssue(
|
|
139
|
+
"missing-header-separator",
|
|
140
|
+
"The body or footers must begin one blank line after the description.",
|
|
141
|
+
line=2,
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
body, footers = _split_body_and_footers(lines[2:])
|
|
145
|
+
return ConventionalCommit(header=header, body=body, footers=footers), None
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016-2022 Carlos Cuesta
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Canonical zendev type for every intention in the vendored Gitmoji catalog.
|
|
2
|
+
#
|
|
3
|
+
# Keys are upstream Gitmoji names. Values are the unique types accepted by the
|
|
4
|
+
# strict default form: <emoji-or-shortcode> <type>(<scope>)!: <description>.
|
|
5
|
+
[types]
|
|
6
|
+
art = "style"
|
|
7
|
+
zap = "perf"
|
|
8
|
+
fire = "remove"
|
|
9
|
+
bug = "fix"
|
|
10
|
+
ambulance = "hotfix"
|
|
11
|
+
sparkles = "feat"
|
|
12
|
+
memo = "docs"
|
|
13
|
+
rocket = "deploy"
|
|
14
|
+
lipstick = "ui"
|
|
15
|
+
tada = "init"
|
|
16
|
+
white-check-mark = "test"
|
|
17
|
+
lock = "security"
|
|
18
|
+
closed-lock-with-key = "secrets"
|
|
19
|
+
bookmark = "release"
|
|
20
|
+
rotating-light = "lint"
|
|
21
|
+
construction = "wip"
|
|
22
|
+
green-heart = "ci-fix"
|
|
23
|
+
arrow-down = "deps-down"
|
|
24
|
+
arrow-up = "deps-up"
|
|
25
|
+
pushpin = "deps-pin"
|
|
26
|
+
construction-worker = "ci"
|
|
27
|
+
chart-with-upwards-trend = "analytics"
|
|
28
|
+
recycle = "refactor"
|
|
29
|
+
heavy-plus-sign = "deps-add"
|
|
30
|
+
heavy-minus-sign = "deps-remove"
|
|
31
|
+
wrench = "chore"
|
|
32
|
+
hammer = "scripts"
|
|
33
|
+
globe-with-meridians = "i18n"
|
|
34
|
+
pencil2 = "typo"
|
|
35
|
+
poop = "bad-code"
|
|
36
|
+
rewind = "revert"
|
|
37
|
+
twisted-rightwards-arrows = "merge"
|
|
38
|
+
package = "build"
|
|
39
|
+
alien = "api"
|
|
40
|
+
truck = "move"
|
|
41
|
+
page-facing-up = "license"
|
|
42
|
+
boom = "breaking"
|
|
43
|
+
bento = "assets"
|
|
44
|
+
wheelchair = "a11y"
|
|
45
|
+
bulb = "comments"
|
|
46
|
+
beers = "drunk"
|
|
47
|
+
speech-balloon = "copy"
|
|
48
|
+
card-file-box = "db"
|
|
49
|
+
loud-sound = "logs"
|
|
50
|
+
mute = "logs-remove"
|
|
51
|
+
busts-in-silhouette = "contributors"
|
|
52
|
+
children-crossing = "ux"
|
|
53
|
+
building-construction = "arch"
|
|
54
|
+
iphone = "responsive"
|
|
55
|
+
clown-face = "mock"
|
|
56
|
+
egg = "easter-egg"
|
|
57
|
+
see-no-evil = "ignore"
|
|
58
|
+
camera-flash = "snapshot"
|
|
59
|
+
alembic = "experiment"
|
|
60
|
+
mag = "seo"
|
|
61
|
+
label = "types"
|
|
62
|
+
seedling = "seed"
|
|
63
|
+
triangular-flag-on-post = "flag"
|
|
64
|
+
goal-net = "error"
|
|
65
|
+
dizzy = "animation"
|
|
66
|
+
wastebasket = "deprecate"
|
|
67
|
+
passport-control = "auth"
|
|
68
|
+
adhesive-bandage = "patch"
|
|
69
|
+
monocle-face = "data"
|
|
70
|
+
coffin = "dead-code"
|
|
71
|
+
test-tube = "test-fail"
|
|
72
|
+
necktie = "business"
|
|
73
|
+
stethoscope = "health"
|
|
74
|
+
bricks = "infra"
|
|
75
|
+
technologist = "dx"
|
|
76
|
+
money-with-wings = "sponsor"
|
|
77
|
+
thread = "concurrency"
|
|
78
|
+
safety-vest = "validation"
|
|
79
|
+
airplane = "offline"
|
|
80
|
+
t-rex = "compat"
|