You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.4KB

  1. # Copyright 2020 Tecnativa - Víctor Martínez
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. import pathspec
  4. from pygount import SourceAnalysis
  5. from odoo import fields, models
  6. class GithubAnalysisRule(models.Model):
  7. _name = "github.analysis.rule"
  8. _description = "Github Analysis Rule"
  9. name = fields.Char(string="Name", required=True)
  10. group_id = fields.Many2one(
  11. string="Group", comodel_name="github.analysis.rule.group", required=True
  12. )
  13. """
  14. Example paths: https://git-scm.com/docs/gitignore#_pattern_format
  15. """
  16. paths = fields.Text(
  17. string="Paths",
  18. help="Define with pathspec especification",
  19. default="*",
  20. required=True,
  21. )
  22. def _set_spec(self, lines):
  23. return pathspec.PathSpec.from_lines("gitwildmatch", lines)
  24. def _get_matches(self, path):
  25. """
  26. Get all matches from rule paths (multiple per line allow in rule)
  27. in a local path
  28. """
  29. return self._set_spec(self.paths.splitlines()).match_tree(path)
  30. def _analysis_file(self, path):
  31. file_res = SourceAnalysis.from_file(path, "")
  32. return {
  33. "path": file_res._path,
  34. "language": file_res._language,
  35. "code": file_res._code,
  36. "documentation": file_res._documentation,
  37. "empty": file_res._empty,
  38. "string": file_res._string,
  39. }
上海开阖软件有限公司 沪ICP备12045867号-1