From c5785a2d1484a98616b0fb8b5a7cb728eb094435 Mon Sep 17 00:00:00 2001 From: jesopo Date: Wed, 26 Jun 2019 14:37:26 +0100 Subject: implement @utils.kwarg() magic, use it for command.regex hooks --- modules/github.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'modules/github.py') diff --git a/modules/github.py b/modules/github.py index 9b245cc5..102f3ab2 100644 --- a/modules/github.py +++ b/modules/github.py @@ -15,6 +15,10 @@ COLOR_NEUTRAL = utils.consts.LIGHTGREY COLOR_NEGATIVE = utils.consts.RED COLOR_ID = utils.consts.PINK +REGEX_PR_OR_ISSUE = re.compile( + r"https?://github.com/([^/]+)/([^/]+)/(pull|issues)/(\d+)", re.I) +REGEX_REF = re.compile(r"(?:\S+(?:\/\S+)?)?#\d+") + API_ISSUE_URL = "https://api.github.com/repos/%s/%s/issues/%s" API_PULL_URL = "https://api.github.com/repos/%s/%s/pulls/%s" @@ -182,12 +186,11 @@ class Module(ModuleManager.BaseModule): else: return True - @utils.hook("command.regex", ignore_action=False) + @utils.hook("command.regex") + @utils.kwarg("ignore_action", False) + @utils.kwarg("command", "github") + @utils.kwarg("pattern", REGEX_PR_OR_ISSUE) def url_regex(self, event): - """ - :command: github - :pattern: https?://github.com/([^/]+)/([^/]+)/(pull|issues)/(\d+) - """ if event["target"].get_setting("auto-github", False): event.eat() ref = "%s/%s#%s" % (event["match"].group(1), @@ -202,12 +205,11 @@ class Module(ModuleManager.BaseModule): event["stdout"].hide_prefix() event["stdout"].write(result) - @utils.hook("command.regex", ignore_action=False) + @utils.hook("command.regex") + @utils.kwarg("ignore_action", False) + @utils.kwarg("command", "github") + @utils.kwarg("pattern", REGEX_REF) def ref_regex(self, event): - """ - :command: github - :pattern: (?:\S+(?:\/\S+)?)?#\d+ - """ if event["target"].get_setting("auto-github", False): event.eat() ref = event["match"].group(0) -- cgit v1.3.1-10-gc9f91