Skip to content

Commit

Permalink
labhub/assign: Allow multiple issue formats
Browse files Browse the repository at this point in the history
... to be defined inside code easily by using custom parser functions.
  • Loading branch information
Makman2 committed Oct 2, 2017
1 parent 2350587 commit ae2a2b1
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions plugins/labhub.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import github3
from IGitt.GitHub.GitHub import GitHub, GitHubToken
from IGitt.GitLab.GitLab import GitLab, GitLabPrivateToken
from errbot import BotPlugin, re_botcmd
from errbot import BotPlugin, arg_botcmd, re_botcmd

from plugins import constants

Expand Down Expand Up @@ -242,14 +242,34 @@ def mark_cmd(self, msg, match):
bot_prefix=self.bot_config.BOT_PREFIX)
)

@re_botcmd(pattern=r'^assign\s+https://(github|gitlab)\.com/([^/]+)/([^/]+/)+issues/(\d+)', # Ignore LineLengthBear, PyCodeStyleBear
re_cmd_name_help='assign <complete-issue-URL>',
flags=re.IGNORECASE)
def assign_cmd(self, msg, match):
@arg_botcmd('issue_reference', type=str)
def assign(self, msg, issue_reference):
"""Assign to GitLab and GitHub issues.""" # Ignore QuotesBear
org = match.group(2)
repo_name = match.group(3)[:-1]
iss_number = match.group(4)

# Complete URL to issue
def process_full_url(issue_reference):
rgx = r'https://(github|gitlab)\.com/([^/]+)/([^/]+/)+issues/(\d+)'
m = re.fullmatch(rgx, issue_reference, re.IGNORECASE)

if m is None:
return None

return m.group(2), m.group(3)[:-1], m.group(4)

issue_processors = [
process_full_url
]

for issue_processor in issue_processor:
issue_data = issue_processor(issue_reference)

if issue_data is not None:
break
else:
yield 'Invalid issue.'
return

org, repo_name, iss_number = issue_data

user = msg.frm.nick

Expand Down

0 comments on commit ae2a2b1

Please sign in to comment.