Esempio n. 1
0
 def __init__(self):
     self.rules = RuleCollection(self.default_rule_classes)
     self._verbosity = options.IntOption('verbosity', 3, "Verbosity")
     self._ignore_merge_commits = options.BoolOption(
         'ignore-merge-commits', True, "Ignore merge commits")
     self._ignore_fixup_commits = options.BoolOption(
         'ignore-fixup-commits', True, "Ignore fixup commits")
     self._ignore_squash_commits = options.BoolOption(
         'ignore-squash-commits', True, "Ignore squash commits")
     self._ignore_revert_commits = options.BoolOption(
         'ignore-revert-commits', True, "Ignore revert commits")
     self._debug = options.BoolOption('debug', False, "Enable debug mode")
     self._extra_path = None
     target_description = "Path of the target git repository (default=current working directory)"
     self._target = options.PathOption('target',
                                       os.path.realpath(os.getcwd()),
                                       target_description)
     self._ignore = options.ListOption('ignore', [],
                                       'List of rule-ids to ignore')
     self._contrib = options.ListOption('contrib', [],
                                        'List of contrib-rules to enable')
     self._config_path = None
     ignore_stdin_description = "Ignore any stdin data. Useful for running in CI server."
     self._ignore_stdin = options.BoolOption('ignore-stdin', False,
                                             ignore_stdin_description)
     self._staged = options.BoolOption(
         'staged', False,
         "Read staged commit meta-info from the local repository.")
Esempio n. 2
0
 def __init__(self):
     # Use an ordered dict so that the order in which rules are applied is always the same
     self._rules = OrderedDict([(rule_cls.id, rule_cls())
                                for rule_cls in self.default_rule_classes])
     self._verbosity = options.IntOption('verbosity', 3, "Verbosity")
     self._ignore_merge_commits = options.BoolOption(
         'ignore-merge-commits', True, "Ignore merge commits")
     self._ignore_fixup_commits = options.BoolOption(
         'ignore-fixup-commits', True, "Ignore fixup commits")
     self._ignore_squash_commits = options.BoolOption(
         'ignore-squash-commits', True, "Ignore squash commits")
     self._debug = options.BoolOption('debug', False, "Enable debug mode")
     self._extra_path = None
     target_description = "Path of the target git repository (default=current working directory)"
     self._target = options.PathOption('target',
                                       os.path.realpath(os.getcwd()),
                                       target_description)
     self._ignore = options.ListOption('ignore', [],
                                       'List of rule-ids to ignore')
     self._contrib = options.ListOption('contrib', [],
                                        'List of contrib-rules to enable')
     self._config_path = None
     ignore_stdin_description = "Ignore any stdin data. Useful for running in CI server."
     self._ignore_stdin = options.BoolOption('ignore-stdin', False,
                                             ignore_stdin_description)
Esempio n. 3
0
 def __init__(self):
     # Use an ordered dict so that the order in which rules are applied is always the same
     self._rules = OrderedDict([(rule_cls.id, rule_cls()) for rule_cls in self.default_rule_classes])
     self._verbosity = options.IntOption('verbosity', 3, "Verbosity")
     self._ignore_merge_commits = options.BoolOption('ignore-merge-commits', True, "Ignore merge commits")
     self._debug = options.BoolOption('debug', False, "Enable debug mode")
     self._extra_path = None
     target_description = "Path of the target git repository (default=current working directory)"
     self._target = options.PathOption('target', os.path.abspath(os.getcwd()), target_description)
     self._ignore = options.ListOption('ignore', [], 'List of rule-ids to ignore')
     self._config_path = None
Esempio n. 4
0
 def __init__(self, config_path=None, target=None):
     # Use an ordered dict so that the order in which rules are applied is always the same
     self._rules = OrderedDict([(rule_cls.id, rule_cls()) for rule_cls in self.default_rule_classes])
     self._verbosity = options.IntOption('verbosity', 3, "Verbosity")
     self._ignore_merge_commits = options.BoolOption('ignore-merge-commits', True, "Ignore merge commits")
     self._debug = options.BoolOption('debug', False, "Enable debug mode")
     self.config_path = config_path
     if target:
         self.target = target
     else:
         self.target = os.path.abspath(os.getcwd())
Esempio n. 5
0
    def test_extra_path(self):
        config = LintConfig()

        config.set_general_option("extra-path", self.get_user_rules_path())
        self.assertEqual(config.extra_path, self.get_user_rules_path())
        actual_rule = config.rules.find_rule('UC1')
        self.assertTrue(actual_rule.is_user_defined)
        self.assertEqual(ustr(type(actual_rule)), "<class 'my_commit_rules.MyUserCommitRule'>")
        self.assertEqual(actual_rule.id, 'UC1')
        self.assertEqual(actual_rule.name, u'my-üser-commit-rule')
        self.assertEqual(actual_rule.target, None)
        expected_rule_option = options.IntOption('violation-count', 1, u"Number of violåtions to return")
        self.assertListEqual(actual_rule.options_spec, [expected_rule_option])
        self.assertDictEqual(actual_rule.options, {'violation-count': expected_rule_option})

        # reset value (this is a different code path)
        config.set_general_option("extra-path", self.SAMPLES_DIR)
        self.assertEqual(config.extra_path, self.SAMPLES_DIR)
        self.assertIsNone(config.rules.find_rule("UC1"))
Esempio n. 6
0
    def test_find_rule_classes(self):
        # Let's find some user classes!
        user_rule_path = self.get_sample_path("user_rules")
        classes = find_rule_classes(user_rule_path)

        # Compare string representations because we can't import MyUserCommitRule here since samples/user_rules is not
        # a proper python package
        # Note that the following check effectively asserts that:
        # - There is only 1 rule recognized and it is MyUserCommitRule
        # - Other non-python files in the directory are ignored
        # - Other members of the my_commit_rules module are ignored
        #  (such as func_should_be_ignored, global_variable_should_be_ignored)
        # - Rules are loaded non-recursively (user_rules/import_exception directory is ignored)
        self.assertEqual("[<class 'my_commit_rules.MyUserCommitRule'>]",
                         str(classes))

        # Assert that we added the new user_rules directory to the system path and modules
        self.assertIn(user_rule_path, sys.path)
        self.assertIn("my_commit_rules", sys.modules)

        # Do some basic asserts on our user rule
        self.assertEqual(classes[0].id, "UC1")
        self.assertEqual(classes[0].name, "my-üser-commit-rule")
        expected_option = options.IntOption('violation-count', 1,
                                            "Number of violåtions to return")
        self.assertListEqual(classes[0].options_spec, [expected_option])
        self.assertTrue(hasattr(classes[0], "validate"))

        # Test that we can instantiate the class and can execute run the validate method and that it returns the
        # expected result
        rule_class = classes[0]()
        violations = rule_class.validate("false-commit-object (ignored)")
        self.assertListEqual(
            violations,
            [rules.RuleViolation("UC1", "Commit violåtion 1", "Contënt 1", 1)])

        # Have it return more violations
        rule_class.options['violation-count'].value = 2
        violations = rule_class.validate("false-commit-object (ignored)")
        self.assertListEqual(violations, [
            rules.RuleViolation("UC1", "Commit violåtion 1", "Contënt 1", 1),
            rules.RuleViolation("UC1", "Commit violåtion 2", "Contënt 2", 2)
        ])