-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.py
34 lines (24 loc) · 1 KB
/
util.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
import re
def format_branch_name(name):
# If branch has name like "bugfix/issue-1234-bug-title", take only "1234" part
pattern = re.compile("^(bugfix|feature)\/issue-(?P<branch>[0-9]+)-\S+")
match = pattern.search(name)
if match:
return match.group("branch")
# function is called even if branch name is not used in a current template
# just left properly named branches intact
if name in ["master", "dev"]:
return name
# fail in case of wrong branch names like "bugfix/issue-unknown"
raise ValueError(f"Wrong branch name: {name}")
def format_tag_name(name):
# If tag has name like "release/1.2.3", take only "1.2.3" part
pattern = re.compile(r"release\/(?P<tag>[^\d.]+)")
match = pattern.search(name)
if match:
return match.group("tag")
# just left properly named tags intact
if name.startswith("v"):
return name
# fail in case of wrong tag names like "release/unknown"
raise ValueError(f"Wrong tag name: {name}")