Move regex-based github info to command.regex hooks
This commit is contained in:
parent
281e14d1fb
commit
2fcaf68f0e
1 changed files with 27 additions and 22 deletions
|
@ -8,11 +8,6 @@ COLOR_NEUTRAL = utils.consts.LIGHTGREY
|
||||||
COLOR_NEGATIVE = utils.consts.RED
|
COLOR_NEGATIVE = utils.consts.RED
|
||||||
COLOR_ID = utils.consts.PINK
|
COLOR_ID = utils.consts.PINK
|
||||||
|
|
||||||
REGEX_ISSUE = re.compile("(?:\S+(?:\/\S+)?)?#\d+")
|
|
||||||
REGEX_ISSUE_URL = re.compile(
|
|
||||||
"https?://github.com/([^/]+)/([^/]+)/(pull|issues)/(\d+)", re.I)
|
|
||||||
#https://github.com/ircv3/ircv3-specifications/pull/347
|
|
||||||
|
|
||||||
FORM_ENCODED = "application/x-www-form-urlencoded"
|
FORM_ENCODED = "application/x-www-form-urlencoded"
|
||||||
|
|
||||||
COMMIT_URL = "https://github.com/%s/commit/%s"
|
COMMIT_URL = "https://github.com/%s/commit/%s"
|
||||||
|
@ -232,30 +227,40 @@ class Module(ModuleManager.BaseModule):
|
||||||
else:
|
else:
|
||||||
event["stderr"].write("Issue/PR not found")
|
event["stderr"].write("Issue/PR not found")
|
||||||
|
|
||||||
@utils.hook("received.message.channel", priority=EventManager.PRIORITY_LOW)
|
@utils.hook("command.regex")
|
||||||
def channel_message(self, event):
|
def url_regex(self, event):
|
||||||
url_match = REGEX_ISSUE_URL.search(event["message"])
|
"""
|
||||||
ref = None
|
:command: github
|
||||||
if url_match:
|
:pattern: https?://github.com/([^/]+)/([^/]+)/(pull|issues)/(\d+)
|
||||||
|
"""
|
||||||
|
if event["channel"].get_setting("auto-github", False):
|
||||||
ref = "%s/%s#%s" % (
|
ref = "%s/%s#%s" % (
|
||||||
url_match.group(1), url_match.group(2), url_match.group(4))
|
url_match.group(1), url_match.group(2), url_match.group(4))
|
||||||
event.eat()
|
|
||||||
else:
|
|
||||||
match = REGEX_ISSUE.search(event["message"])
|
|
||||||
if match:
|
|
||||||
ref = match.group(0)
|
|
||||||
|
|
||||||
if ref and event["channel"].get_setting("auto-github", False):
|
|
||||||
try:
|
try:
|
||||||
result = self._get_info(event["channel"], ref)
|
result = self._get_info(event["channel"], ref)
|
||||||
except utils.EventError:
|
except utils.EventError:
|
||||||
return
|
return
|
||||||
if result:
|
if result:
|
||||||
hide_prefix = event["channel"].get_setting(
|
if event["channel"].get_setting("github-hide-prefix", False):
|
||||||
"github-hide-prefix", False)
|
event["stdout"].hide_preix()
|
||||||
self.events.on("send.stdout").call(target=event["channel"],
|
event["stdout"].write(result)
|
||||||
module_name="Github", server=event["server"],
|
|
||||||
message=result, hide_prefix=hide_prefix)
|
@utils.hook("command.regex")
|
||||||
|
def ref_regex(self, event):
|
||||||
|
"""
|
||||||
|
:command: github
|
||||||
|
:pattern: (?:\S+(?:\/\S+)?)?#\d+
|
||||||
|
"""
|
||||||
|
if event["channel"].get_setting("auto-github", False):
|
||||||
|
try:
|
||||||
|
result = self._get_info(event["channel"],
|
||||||
|
event["match"].group(0))
|
||||||
|
except utils.EventError:
|
||||||
|
return
|
||||||
|
if result:
|
||||||
|
if event["channel"].get_setting("github-hide-prefix", False):
|
||||||
|
event["stdout"].hide_preix()
|
||||||
|
event["stdout"].write(result)
|
||||||
|
|
||||||
@utils.hook("received.command.ghwebhook", min_args=1, channel_only=True)
|
@utils.hook("received.command.ghwebhook", min_args=1, channel_only=True)
|
||||||
def github_webhook(self, event):
|
def github_webhook(self, event):
|
||||||
|
|
Loading…
Reference in a new issue