-
Notifications
You must be signed in to change notification settings - Fork 5
/
conventional_commits.py
145 lines (90 loc) · 3.95 KB
/
conventional_commits.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
137
138
139
140
141
142
143
144
145
# Conventional Commits 1.0.0
# https://www.conventionalcommits.org/en/v1.0.0/#specification
import re
from os.path import join
import pandas as pd
from configuration import DATA_PATH
from language_utils import regex_to_big_query, generate_bq_function, match, SCHEMA_NAME, print_logic_to_bq
from model_evaluation import classifiy_commits_df, evaluate_performance
cc_adaptive_terms = ['feat' # Feature
, 'build'
, 'chore'
, 'ci' # continuous integration
, 'test'
, 'perf' # performance
]
cc_corrective_terms = ['fix']
cc_perfective_terms = ['docs', 'style']
cc_refactor_terms = ['refactor']
cc_actions = cc_adaptive_terms + cc_corrective_terms + cc_perfective_terms + cc_perfective_terms
cc_etc = ['breaking\s+change(!)?:']
def cc_title(astions):
return '^(' + "|".join(astions) +")(\(.*\))?(!)?:"
# Adaptive
def build_cc_adaptive_regex():
return cc_title(cc_adaptive_terms)
def is_cc_adaptive(commit_text):
return len(re.findall(build_cc_adaptive_regex(), commit_text)) > 0
# Corrective
def build_cc_corrective_regex():
return cc_title(cc_corrective_terms)
def is_cc_corrective(commit_text):
return len(re.findall(build_cc_corrective_regex(), commit_text)) > 0
# Refactor
def build_cc_refactor_regex():
return cc_title(cc_refactor_terms)
def is_cc_refactor(commit_text):
return len(re.findall(build_cc_refactor_regex(), commit_text)) > 0
# Just Perfective
def build_cc_just_perfective_regex():
return cc_title(cc_perfective_terms)
def is_cc_just_perfective(commit_text):
return len(re.findall(build_cc_just_perfective_regex(), commit_text)) > 0
# Perfective
def build_cc_perfective_regex():
return "(" + "|".join([build_cc_refactor_regex()
, build_cc_just_perfective_regex()]) + ")"
def is_cc_perfective(commit_text):
return len(re.findall(build_cc_perfective_regex(), commit_text)) > 0
# CC message
def build_cc_message_regex():
return "(" + "|".join([cc_title(cc_actions)] + cc_etc) + ")"
def is_cc_message(commit_text):
return len(re.findall(build_cc_message_regex(), commit_text)) > 0
def print_cc_functions_for_bq(commit: str = 'XXX'):
concepts = {'cc_adaptive' : build_cc_adaptive_regex
, 'cc_corrective' : build_cc_corrective_regex
, 'cc_refactor' : build_cc_refactor_regex
, 'cc_just_perfective' : build_cc_just_perfective_regex
, 'cc_perfective' : build_cc_perfective_regex
, 'cc_message' : build_cc_message_regex
}
for i in concepts.keys():
print()
print_func = lambda : print_logic_to_bq(regex_func=concepts[i]
, concept=i)
generate_bq_function('{schema}.bq_{concept}'.format(schema=SCHEMA_NAME
, concept=i)
, print_func
, commit=commit)
print()
def evaluate_cc_fix_classifier():
text_name = 'message'
classification_function = is_cc_corrective
classification_column = 'corrective_pred'
concept_column = 'Is_Corrective'
df = pd.read_csv(join(DATA_PATH, 'conventional_commits.csv'))
df = classifiy_commits_df(df
, classification_function=classification_function
, classification_column=classification_column
, text_name=text_name
)
cm = evaluate_performance(df
, classification_column
, concept_column
, text_name=text_name)
print("corrective_labels CM")
print(cm)
if __name__ == '__main__':
print_cc_functions_for_bq(commit='60af4655d2baeb3aa15768a02cacf0bff5612e2b')
evaluate_cc_fix_classifier()