Skip to content

Commit

Permalink
GitStats: Remove LabHub inheritance
Browse files Browse the repository at this point in the history
Inheritence was resulting in labhub commands
being triggered twice when used. This creates
dependency on labhub instead of inheritance.

Fixes #441
  • Loading branch information
nvzard committed Aug 4, 2018
1 parent 7179622 commit 0caa68b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions plugins/git_stats.plug
@@ -1,6 +1,7 @@
[Core]
name = GitStats
module = git_stats
DependsOn = LabHub

[Documentation]
description = GitHub and GitLab statistics
Expand Down
11 changes: 5 additions & 6 deletions plugins/git_stats.py
Expand Up @@ -2,21 +2,20 @@
import re
from shutil import rmtree

from errbot import re_botcmd
from errbot import BotPlugin, re_botcmd

from plugins.labhub import LabHub


class GitStats(LabHub):
class GitStats(BotPlugin):
"""GitHub and GitLab statistics""" # Ignore QuotesBear

PR_LABELS = ('process/approved',
'process/pending review',
'process/pending-review'
)

def __init__(self, bot, name=None):
super().__init__(bot, name)
def activate(self):
super().activate()
self.REPOS = self.get_plugin('LabHub').REPOS

@re_botcmd(pattern=r'mergable\s+([^/]+)', # Ignore PyCodeStyleBear
re_cmd_name_help='pr list <repo>',
Expand Down
3 changes: 2 additions & 1 deletion tests/corobo_test_case.py
Expand Up @@ -32,11 +32,12 @@ def load_plugin(self, plugin_name: str, mock_dict=False):
"""Load plugin manually"""
klass = self.klasses[plugin_name]
plugin = klass(self.bot, plugin_name)
plugin.activate()
self.plugins[plugin_name] = plugin
self.bot.plugin_manager.plugins[plugin_name] = plugin
plug_file = self.plug_files[plugin_name]
plugin.dependencies = plug_file.dependencies
self.bot.plugin_manager.plugin_infos[plug_file.name] = plug_file
plugin.activate()

if mock_dict:
self.inject_mocks(plugin_name=plugin_name, mock_dict=mock_dict)
Expand Down
10 changes: 6 additions & 4 deletions tests/git_stats_test.py
Expand Up @@ -18,17 +18,19 @@
class TestGitStats(CoroboTestCase):

def setUp(self):
super().setUp((plugins.git_stats.GitStats,))
plugins.git_stats.github3 = create_autospec(github3)
super().setUp((plugins.git_stats.GitStats,
plugins.labhub.LabHub,))
plugins.labhub.github3 = create_autospec(github3)
self.mock_org = create_autospec(github3.orgs.Organization)
self.mock_gh = create_autospec(github3.GitHub)
self.mock_repo = create_autospec(IGitt.GitHub.GitHub.GitHubRepository)
plugins.git_stats.github3.login.return_value = self.mock_gh
plugins.labhub.github3.login.return_value = self.mock_gh
self.mock_gh.organization.return_value = self.mock_org
plugins.git_stats.github3.organization.return_value = self.mock_org
plugins.labhub.github3.organization.return_value = self.mock_org

self.plugin = plugins.git_stats.GitStats
self.plugin.__bases__ = (BotPlugin, )
self.labhub = self.load_plugin('LabHub')
self.git_stats = self.load_plugin('GitStats')
self.git_stats.REPOS = {'test': self.mock_repo}

Expand Down

0 comments on commit 0caa68b

Please sign in to comment.