-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcz_emoji.py
136 lines (119 loc) · 4.47 KB
/
cz_emoji.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
from collections import OrderedDict
from typing import Any, Dict, List
import emoji
from commitizen.cz.base import BaseCommitizen
from commitizen.cz.utils import multiple_line_breaker, required_validator
from commitizen.defaults import MAJOR, MINOR, PATCH, Questions
__all__ = ["CommitizenEmojiCz"]
def parse_scope(text):
if not text:
return ""
scope = text.strip().split()
if len(scope) == 1:
return scope[0]
return emoji.emojize(" ".join(scope))
def parse_subject(text):
if isinstance(text, str):
text = text.strip(".").strip()
return required_validator(text, msg="Subject is required.")
class ConventionalEmojiCz(BaseCommitizen):
bump_pattern = r"^(BREAKING CHANGE|🎉? ?feat|🔨? ?fix|➗? ?refactor|🧼? ?correction)(\(.+\))?(!)?"
bump_map = OrderedDict(
(
(r"^.+!$", MAJOR),
(r"^BREAKING CHANGE", MAJOR),
(r"^🎉? ?feat", MINOR),
(r"^🔨? ?fix", PATCH),
)
)
change_type_map = {
"feat": "Feat",
"fix": "Fix",
"refactor": "Refactor",
"correction": "Correction",
}
def questions(self) -> Questions:
questions: Questions = [
{
"name": "prefix",
"type": "list",
"message": "Select the type of change you are committing",
"choices": [
{
"value": "🎉 feat",
"name": "🎉 feat: (Bumps MINOR) Add a feature (captures new items; in particular, anything the end user can see)",
},
{
"value": "🔨 fix",
"name": "🔨 fix: (Bumps PATCH) Fix an item (captures modifications; item must exist and the change affect its behavior).",
},
{
"value": "➗ refactor",
"name": "➗ refactor: (Bumps nothing) A change that does not add features or modify behavior.",
},
{
"value": "🧼 correction",
"name": "🧼 correction: (Bumps nothing) A fix that does not add features or modify behavior (e.g. typos, formatting, white-space, etc.)",
},
],
},
{
"name": "scope",
"type": "input",
"message": (
"Scope. Enter the scope of the change (e.g. docs/test/ci/perf, a file name, or a category).\n"
"Enter MarkDown emojis with ':emoji:' style syntax (e.g. :tada:):\n"
),
"filter": parse_scope,
},
{
"name": "subject",
"type": "input",
"message": (
"Subject. Concise description of the changes. Imperative, lower case and no final dot:\n"
),
"filter": parse_subject,
},
{
"name": "body",
"type": "input",
"message": (
"Body. Motivation for the change and contrast this "
"with previous behavior:\n"
),
"filter": multiple_line_breaker,
},
{
"name": "is_breaking_change",
"type": "confirm",
"message": "Is this a BREAKING CHANGE? (Bumps MAJOR)",
"default": False,
},
{
"type": "input",
"name": "footer",
"message": (
"Footer. Information about Breaking Changes and "
"reference issues that this commit closes: (press [enter] to skip)\n"
),
},
]
return questions
def message(self, answers: dict) -> str:
prefix = answers["prefix"]
scope = answers["scope"]
subject = answers["subject"]
body = answers["body"]
is_breaking_change = answers["is_breaking_change"]
footer = answers["footer"]
if scope:
scope = f"({scope})"
if body:
body = f"\n\n{body}"
if is_breaking_change:
body = f"BREAKING CHANGE 🚨: {footer}"
if footer:
footer = f"\n\n{footer}"
message = f"{prefix}{scope}: {subject}{body}{footer}"
return message
discover_this = ConventionalEmojiCz