-
-
Notifications
You must be signed in to change notification settings - Fork 278
/
Copy pathjira.py
89 lines (79 loc) · 2.89 KB
/
jira.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
import os
from commitizen.config.base_config import BaseConfig
from commitizen.cz.base import BaseCommitizen
from commitizen.defaults import Questions
__all__ = ["JiraSmartCz"]
class JiraSmartCz(BaseCommitizen):
def __init__(self, config: BaseConfig):
super().__init__(config)
self.bump_map = None
self.bump_pattern = None
self.commit_parser = r"(?P<message>.*)"
self.changelog_pattern = r".*"
def questions(self) -> Questions:
questions = [
{
"type": "input",
"name": "message",
"message": "Git commit message (required):\n",
# 'validate': RequiredValidator,
"filter": lambda x: x.strip(),
},
{
"type": "input",
"name": "issues",
"message": "Jira Issue ID(s) separated by spaces (required):\n",
# 'validate': RequiredValidator,
"filter": lambda x: x.strip(),
},
{
"type": "input",
"name": "workflow",
"message": "Workflow command (testing, closed, etc.) (optional):\n",
"filter": lambda x: "#" + x.strip().replace(" ", "-") if x else "",
},
{
"type": "input",
"name": "time",
"message": "Time spent (i.e. 3h 15m) (optional):\n",
"filter": lambda x: "#time " + x if x else "",
},
{
"type": "input",
"name": "comment",
"message": "Jira comment (optional):\n",
"filter": lambda x: "#comment " + x if x else "",
},
]
return questions
def message(self, answers) -> str:
return " ".join(
filter(
bool,
[
answers["message"],
answers["issues"],
answers["workflow"],
answers["time"],
answers["comment"],
],
)
)
def example(self) -> str:
return (
"JRA-34 #comment corrected indent issue\n"
"JRA-35 #time 1w 2d 4h 30m Total work logged\n"
"JRA-123 JRA-234 JRA-345 #resolve\n"
"JRA-123 JRA-234 JRA-345 #resolve #time 2d 5h #comment Task completed "
"ahead of schedule"
)
def schema(self) -> str:
return "<ignored text> <ISSUE_KEY> <ignored text> #<COMMAND> <optional COMMAND_ARGUMENTS>" # noqa
def schema_pattern(self) -> str:
return r".*[A-Z]{2,}\-[0-9]+( #| .* #).+( #.+)*"
def info(self) -> str:
dir_path = os.path.dirname(os.path.realpath(__file__))
filepath = os.path.join(dir_path, "jira_info.txt")
with open(filepath, "r") as f:
content = f.read()
return content