@@ -55,7 +55,7 @@ def main():
5555 generate_stats_cli_command_logic (args , project_name , project_version )
5656
5757
58- def get_commits (args , repo ):
58+ def get_commits_by_branch (args , repo ):
5959 total_commits = 0
6060 commits = []
6161 for commit in repo .iter_commits ():
@@ -79,6 +79,62 @@ def get_commits(args, repo):
7979 return commits , total_commits
8080
8181
82+ def get_commits_by_tags (args , repo ):
83+ commits = []
84+ tags_regexp = args .tags_regexp
85+ if tags_regexp == ".*" :
86+ logging .info (
87+ "Acception all tags that follow semver between the timeframe. If you need further filter specify a regular expression via --tags-regexp"
88+ )
89+ else :
90+ logging .info (
91+ "Filtering all tags via a regular expression: {}" .format (tags_regexp )
92+ )
93+ tags_regex_string = re .compile (tags_regexp )
94+
95+ tags = sorted (repo .tags , key = lambda t : t .commit .committed_datetime )
96+ for tag in tags :
97+ if (
98+ args .from_date
99+ <= datetime .datetime .utcfromtimestamp (
100+ tag .commit .committed_datetime .timestamp ()
101+ )
102+ <= args .to_date
103+ ):
104+ try :
105+ version .Version (tag .name )
106+ match_obj = re .search (tags_regex_string , tag .name )
107+ if match_obj is None :
108+ logging .info (
109+ "Skipping {} given it does not match regex {}" .format (
110+ tag .name , tags_regexp
111+ )
112+ )
113+ else :
114+ git_version = tag .name
115+ commit_datetime = str (tag .commit .committed_datetime )
116+ print (
117+ "Commit summary: {}. Extract semver: {}" .format (
118+ tag .commit .summary , git_version
119+ )
120+ )
121+ commits .append (
122+ {
123+ "git_hash" : tag .commit .hexsha ,
124+ "git_version" : git_version ,
125+ "commit_summary" : tag .commit .summary ,
126+ "commit_datetime" : commit_datetime ,
127+ }
128+ )
129+ except packaging .version .InvalidVersion :
130+ logging .info (
131+ "Ignoring tag {} given we were not able to extract commit or version info from it." .format (
132+ tag .name
133+ )
134+ )
135+ pass
136+ return commits
137+
82138def get_repo (args ):
83139 redisDirPath = args .redis_repo
84140 cleanUp = False
@@ -128,61 +184,10 @@ def trigger_tests_cli_command_logic(args, project_name, project_version):
128184
129185 commits = []
130186 if args .use_branch :
131- commits , total_commits = get_commits (args , repo )
132-
187+ commits , total_commits = get_commits_by_branch (args , repo )
133188 if args .use_tags :
134- tags_regexp = args .tags_regexp
135- if tags_regexp == ".*" :
136- logging .info (
137- "Acception all tags that follow semver between the timeframe. If you need further filter specify a regular expression via --tags-regexp"
138- )
139- else :
140- logging .info (
141- "Filtering all tags via a regular expression: {}" .format (tags_regexp )
142- )
143- tags_regex_string = re .compile (tags_regexp )
189+ commtis = get_commits_by_tags (args , repo )
144190
145- tags = sorted (repo .tags , key = lambda t : t .commit .committed_datetime )
146- for tag in tags :
147- if (
148- args .from_date
149- <= datetime .datetime .utcfromtimestamp (
150- tag .commit .committed_datetime .timestamp ()
151- )
152- <= args .to_date
153- ):
154- try :
155- version .Version (tag .name )
156- match_obj = re .search (tags_regex_string , tag .name )
157- if match_obj is None :
158- logging .info (
159- "Skipping {} given it does not match regex {}" .format (
160- tag .name , tags_regexp
161- )
162- )
163- else :
164- git_version = tag .name
165- commit_datetime = str (tag .commit .committed_datetime )
166- print (
167- "Commit summary: {}. Extract semver: {}" .format (
168- tag .commit .summary , git_version
169- )
170- )
171- commits .append (
172- {
173- "git_hash" : tag .commit .hexsha ,
174- "git_version" : git_version ,
175- "commit_summary" : tag .commit .summary ,
176- "commit_datetime" : commit_datetime ,
177- }
178- )
179- except packaging .version .InvalidVersion :
180- logging .info (
181- "Ignoring tag {} given we were not able to extract commit or version info from it." .format (
182- tag .name
183- )
184- )
185- pass
186191 by_description = "n/a"
187192 if args .use_branch :
188193 by_description = "from branch {}" .format (repo .active_branch .name )
0 commit comments