diff options
author | Jan200101 <sentrycraft123@gmail.com> | 2022-05-04 22:16:07 +0200 |
---|---|---|
committer | Jan200101 <sentrycraft123@gmail.com> | 2022-05-04 22:16:07 +0200 |
commit | 30f1ba104559d2b733d98346e8f772fbf20dfc3f (patch) | |
tree | e9e0dd10b49d0f3c37e05b71a9d578bb1334c58e /labbot | |
parent | 087db8ae09f69dfe70e8b0c75b7ce0a5b2dca1c7 (diff) | |
download | lab-bot-30f1ba104559d2b733d98346e8f772fbf20dfc3f.tar.gz lab-bot-30f1ba104559d2b733d98346e8f772fbf20dfc3f.zip |
only list addons on load, add more hook abstractions
Diffstat (limited to 'labbot')
-rw-r--r-- | labbot/bot.py | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/labbot/bot.py b/labbot/bot.py index 49ea71e..3b41ed6 100644 --- a/labbot/bot.py +++ b/labbot/bot.py @@ -16,8 +16,9 @@ class Bot: self.access_token = kwargs.get("access_token") self.secret = kwargs.get("secret", "") self.config = kwargs.pop("config", labbot.config.read_instance_config(self.name)) + self.config_addons = self.config.get("addons", []) - self.addons = self.config.get("addons", []) + self.addons = [] self.addon_paths = [] self.core_addon_path = os.path.join(os.path.dirname(labbot.__file__), "addons") @@ -30,7 +31,7 @@ class Bot: for path in self.addon_paths: sys.path.insert(0, path) - for addon in self.addons: + for addon in self.config_addons: self.load_addon(addon) for path in self.addon_paths: @@ -41,14 +42,40 @@ class Bot: try: import_module(f"{addon}").setup(self) log.info(f"Loaded {addon}") + self.addons.append(addon) except ModuleNotFoundError: log.error(f"No addon named `{addon}`") def register(self, func, *args, **kwargs) -> None: - return self.instance.router.register(*args, **kwargs)(func) + self.instance.router.register(*args, **kwargs)(func) + + def register_push_hook(self, func, *args, **kwargs) -> None: + self.register(func, "Push Hook", *args, **kwargs) + + def register_tag_hook(self, func, *args, **kwargs) -> None: + self.register(func, "Tag Push Hook", *args, **kwargs) + + def register_issue_hook(self, func, *args, **kwargs) -> None: + self.register(func, "Issue Hook", *args, **kwargs) + + def register_note_hook(self, func, *args, **kwargs) -> None: + self.register(func, "Note Hook", *args, **kwargs) def register_merge_hook(self, func, *args, **kwargs) -> None: - return self.instance.router.register("Merge Request Hook", *args, **kwargs)(func) + self.register(func, "Merge Request Hook", *args, **kwargs) + + def register_wiki_hook(self, func, *args, **kwargs) -> None: + self.register(func, "Wiki Page Hook", *args, **kwargs) + + def register_pipeline_hook(self, func, *args, **kwargs) -> None: + self.register(func, "Pipeline Hook", *args, **kwargs) + + def register_job_hook(self, func, *args, **kwargs) -> None: + self.register(func, "Job Hook", *args, **kwargs) + + def register_deployment_hook(self, func, *args, **kwargs) -> None: + self.register(func, "Deployment Hook", *args, **kwargs) + def run(self, *args, **kwargs) -> None: log.info(f"Started {self.name}") |