66
77import pathspec
88
9- from odoo import fields , models
9+ from odoo import fields , models , tools
1010from odoo .fields import Command
1111
1212_logger = logging .getLogger (__name__ )
@@ -32,19 +32,27 @@ class VcpRule(models.Model):
3232 default = "cloc" ,
3333 )
3434
35- def _process_rule (self , record ):
35+ def _process_rule (self , record , parameters = None ):
3636 """
3737 Process the rule on the given repository and branch.
3838 It will call the corresponding method based on the rule type.
3939 """
40- return getattr (self , f"_process_rule_{ self .rule_type } " )(record )
40+ return getattr (self , f"_process_rule_{ self .rule_type } " )(record , parameters )
4141
42- def _process_rule_cloc (self , record ):
42+ def _process_rule_cloc (self , record , parameters = None ):
4343 """
4444 Process the rule as a cloc analysis.
4545 """
4646 record ._download_code ()
47- cloc_response = self ._call_cloc_command (record .local_path )
47+ if parameters is None :
48+ parameters = {}
49+ if "cloc" in parameters :
50+ cloc_response = parameters ["cloc" ]
51+ else :
52+ cloc_response = self .browse ()._call_cloc_command (
53+ record .id , record .local_path
54+ )
55+ parameters ["cloc" ] = cloc_response
4856 matches = self ._cloc_get_matches (record .local_path )
4957 cloc_data = self ._action_analysis_process_cloc (
5058 record .local_path , matches , cloc_response
@@ -94,7 +102,8 @@ def _action_analysis_process_cloc(self, path, matchs, cloc_response):
94102 res ["empty" ] += res_file ["blank" ]
95103 return res
96104
97- def _call_cloc_command (self , local_path ):
105+ @tools .ormcache ("record_id" , "local_path" )
106+ def _call_cloc_command (self , record_id , local_path ):
98107 res = check_output (["cloc" , "--by-file" , "--json" , local_path ])
99108 return json .loads (res )
100109
0 commit comments