OCA / odoo-pre-commit-hooks

Linters of Odoo addons that complement pylint-odoo
GNU Affero General Public License v3.0
9 stars 11 forks source link

add cli argument: `--exit-zero` #70

Open zwgshr opened 1 year ago

zwgshr commented 1 year ago

Describe the solution you'd like

  - repo: http://gitea.dtdream.vip/z1459/odoo-pre-commit-hooks
    rev: v0.0.23.1
    hooks:
      - id: oca-checks-odoo-module
        args:
          - --exit-zero
        verbose: True
Checks for Odoo modules..................................................Passed
- hook id: oca-checks-odoo-module
- duration: 0.08s

****xml-duplicate-record-id****
myaddons/dtdream_sale_project_state/views/dtdream_finance_bom_config.xml:3 Duplicate xml record id "data/dtdream_finance_bom_config_form_noupdate_0" in myaddons/dtdream_sale_project_state/views/dtdream_finance_bom_config.xml:18 - [xml-duplicate-record-id]

Additional context Add any other context about the feature request here.

diff --git a/src/oca_pre_commit_hooks/global_parser.py b/src/oca_pre_commit_hooks/global_parser.py
index d0247b7..4ec694d 100644
--- a/src/oca_pre_commit_hooks/global_parser.py
+++ b/src/oca_pre_commit_hooks/global_parser.py
@@ -25,6 +25,12 @@ class GlobalParser(argparse.ArgumentParser):
             default=False,
             help="If enabled so disable verbose mode.",
         )
+        self.add_argument(
+            "--exit-zero",
+            action="store_true",
+            default=False,
+            help="If enabled so always exit zero.",
+        )
         self.add_argument(
             "--no-exit",
             action="store_true",

diff --git a/src/oca_pre_commit_hooks/checks_odoo_module.py b/src/oca_pre_commit_hooks/checks_odoo_module.py
index 0f356a8..09a6081 100755
--- a/src/oca_pre_commit_hooks/checks_odoo_module.py
+++ b/src/oca_pre_commit_hooks/checks_odoo_module.py
@@ -169,7 +169,7 @@ def lookup_manifest_paths(filenames_or_modules):
     return odoo_module_files_changed

-def run(files_or_modules, enable=None, disable=None, no_verbose=False, no_exit=False, list_msgs=False):
+def run(files_or_modules, enable=None, disable=None, no_verbose=False, no_exit=False, list_msgs=False, exit_zero=False):
     if list_msgs:
         _, checks_docstring = utils.get_checks_docstring(
             [ChecksOdooModule, checks_odoo_module_csv.ChecksOdooModuleCSV, checks_odoo_module_xml.ChecksOdooModuleXML]
@@ -208,6 +208,8 @@ def run(files_or_modules, enable=None, disable=None, no_verbose=False, no_exit=F
                 checks_obj.print(f"{msg} - [{check_error}]")
     if no_exit:
         return all_check_errors
+    if exit_zero:
+        return sys.exit(0)
     sys.exit(exit_status)
zwgshr commented 1 year ago

Sorry, I don't have enough time and ability to submit a qualified PR, I hope someone can implement this feature.