8
8
from lib .utils .mixin .dcparser import DCToDictMixin
9
9
from lib .utils .utils import Utils
10
10
from pprint import pprint
11
- from time import time
11
+ from time import perf_counter
12
+ from lib .app .app import AppManager
12
13
13
14
# global variables to pass associations to RepoNode dataclass
14
15
associations_commits_tags : Dict [str , str ] = dict () # hexsha - tag's name
@@ -263,6 +264,34 @@ def get_tree(self) -> Optional[RepoNode]:
263
264
264
265
return root_node
265
266
267
+ def get_branches (self ) -> List :
268
+ """
269
+ Return list of branches
270
+
271
+ :return:
272
+ """
273
+
274
+ try :
275
+ self .repo .git .fetch () # try to sync local repo with remote branches
276
+ except Exception as e :
277
+ Logger .log_warning (msg = f"unable to fetch commits from remote branches" , is_verbose = self .verbose )
278
+
279
+ branches : List = []
280
+
281
+ # get references of local and remote branches
282
+ try :
283
+ branches = list (self .repo .branches ) # local
284
+ except Exception as e :
285
+ pass
286
+
287
+ if self .repo .remotes :
288
+ try :
289
+ branches .extend (self .repo .remote ().refs ) # remote
290
+ except Exception as e :
291
+ pass
292
+
293
+ return branches
294
+
266
295
def get_commits (self ) -> List [RepoNode ] | None :
267
296
"""
268
297
Return list of project's repository commits
@@ -282,11 +311,6 @@ def get_commits(self) -> List[RepoNode] | None:
282
311
Logger .log_info (msg = f"start to fetch commits from project repo '{ self .project_path } '..." ,
283
312
is_verbose = self .verbose )
284
313
285
- try :
286
- self .repo .git .fetch () # try to sync local repo with remote branches
287
- except Exception as e :
288
- Logger .log_warning (msg = f"unable to fetch commits from remote branches" , is_verbose = self .verbose )
289
-
290
314
# take tags of repo
291
315
global associations_commits_tags
292
316
associations_commits_tags = dict () # hexsha - tag's name
@@ -295,19 +319,7 @@ def get_commits(self) -> List[RepoNode] | None:
295
319
296
320
Logger .log_info (msg = f"fetched { len (associations_commits_tags .keys ())} tags" , is_verbose = self .verbose )
297
321
298
- branches : List = []
299
-
300
- # get references of local and remote branches
301
- try :
302
- branches = list (self .repo .branches ) # local
303
- except Exception as e :
304
- pass
305
-
306
- if self .repo .remotes :
307
- try :
308
- branches .extend (self .repo .remote ().refs ) # remote
309
- except Exception as e :
310
- pass
322
+ branches : List = self .get_branches ()
311
323
312
324
Logger .log_info (msg = f"fetched { len (branches )} branch(es)" , is_verbose = self .verbose )
313
325
@@ -329,7 +341,7 @@ def get_commits(self) -> List[RepoNode] | None:
329
341
330
342
nodes = list () # use a managed list to share data between processes
331
343
n_of_commits = len (all_repo_commits )
332
- start = time ()
344
+ start = perf_counter ()
333
345
for i in range (n_of_commits ):
334
346
commit = all_repo_commits [i ]
335
347
repo_node : RepoNode = RepoNode .from_commit (commit )
@@ -349,9 +361,25 @@ def get_commits(self) -> List[RepoNode] | None:
349
361
msg = f"elaborating commit { i + 1 } /{ n_of_commits } ({ round ((i + 1 ) * 100 / n_of_commits , 2 )} %)" ,
350
362
is_verbose = self .verbose )
351
363
352
- Logger .log_success (msg = f"commits fetched successfully in { round (time () - start , 4 )} s" ,
364
+ Logger .log_success (msg = f"commits fetched successfully in { round (perf_counter () - start , 4 )} s" ,
353
365
is_verbose = self .verbose )
354
366
return list (nodes )
355
367
356
368
except Exception as e :
357
369
Logger .log_error (msg = f"an error occurs during commits elaborating" , is_verbose = self .verbose )
370
+
371
+ def create_app_branch (self ) -> bool :
372
+ """
373
+ Create app branch in the project
374
+
375
+ :return:
376
+ """
377
+
378
+ return NotImplementedError
379
+
380
+ # if not self.valid_opened_repo():
381
+ # Logger.log_error(msg="impossible to create branch: repo not found", is_verbose=self.verbose)
382
+ # return False
383
+ #
384
+ # APP_BRANCH_NAME = AppManager.APP_NAME
385
+
0 commit comments