コード例 #1
0
    def test_get_channels_based_on_labels(self):
        default_config = mention_bot.BotConfig.from_dict(
            config.get_default_config())
        channels = gitlab_client.get_channels_based_on_labels(
            default_config, ['ccgh', 'risk'])
        self.assertListEqual(channels, [u'#gitlab-merge-requests'])

        channels = gitlab_client.get_channels_based_on_labels(
            default_config, [])
        self.assertListEqual(channels, ['#gitlab-merge-requests'])
コード例 #2
0
class BotConfig(object):
    default_config = config.get_default_config()

    @classmethod
    def from_dict(cls, d):
        cfg = cls()
        attrs = dict(cls.default_config, **d)
        for k, v in attrs.items():
            setattr(cfg, k, v)
        return cfg
コード例 #3
0
 def test_labels(self):
     files = [
         ('pyapp/riskweb/a.py', [1, 2]),
         ('pyapp/riskweb/a.py', [1, 2]),
         ('pylib/b.py', [1, 2, 3, 5, 6]),
         ('c.json', [1, 2, 3]),
         ('readme.md', [2]),
         ('xx.py', [234, 456, 789]),
     ]
     default_config = mention_bot.BotConfig.from_dict(
         config.get_default_config())
     labels = gitlab_client.get_labels(default_config, files)
     self.assertListEqual(labels, sorted(['risk', 'pylib']))
コード例 #4
0
 def test_webhook_valid(self, guess_owners_for_merge_reqeust, add_comment,
                        get_diff_files, manage_labels, is_valid,
                        get_repo_config):
     guess_owners_for_merge_reqeust.return_value = ['lfyzjck']
     get_diff_files.return_value = []
     manage_labels.return_value = True
     get_repo_config.return_value = BotConfig.from_dict(
         get_default_config())
     is_valid.return_value = True
     headers = {'X-Gitlab-Event': 'Merge Request Hook'}
     with open('tests/data/merge_request_event.json') as f:
         data = f.read()
         response = self.client.post('/', data=data, headers=headers)
         self.assertEqual(response.status_code, 200)
     add_comment.assert_called()
コード例 #5
0
def get_repo_config(project_id, target_branch, config_path):
    filecontent = gitlab_client.get_project_file(project_id, target_branch,
                                                 config_path)
    if not filecontent:
        logger.warning(
            "Unable to find config file, use default config instead.")
        return BotConfig.from_dict(config.get_default_config())
    try:
        cfg = json.loads(filecontent)
        return BotConfig.from_dict(cfg)
    except Exception:
        logger.exception("Failed to parse config: %s" % filecontent)
        raise gitlab_client.ConfigSyntaxError(
            "Unable to parse mention-bot custom configuration file due to a syntax error."
        )