Skip to content
Snippets Groups Projects
Commit 58bdca13 authored by Tulir Asokan's avatar Tulir Asokan :cat2:
Browse files

Fix using default repo in commands

parent 305fd2b0
No related branches found
No related tags found
No related merge requests found
Pipeline #4797 passed
......@@ -59,7 +59,7 @@ class CommandIssue(Command):
await evt.reply(f"Commented on issue #{issue.iid}: {issue.title}")
@issue.subcommand("comments", aliases=("read-comments",),
help="Write a comment on an issue.")
help="Read comments on an issue.")
@OptUrlAliasArgument("login", "server URL or alias", arg_num=2)
@OptRepoArgument("repo", "repository")
@command.argument("id", "issue ID", parser=sigil_int)
......
......@@ -43,16 +43,18 @@ class OptUrlAliasArgument(Argument):
class OptRepoArgument(Argument):
def __init__(self, name: str, label: str = None, required: bool = False) -> None:
super().__init__(name, label=label, required=required)
super().__init__(name, label=label, required=required, pass_raw=True)
def match(self, val: str, evt: MessageEvent, instance: 'Command', **kwargs
) -> Tuple[str, Any]:
repo = re.split(r"\s", val, 1)[0]
repo, *rest = re.split(r"\s+", val, 1)
rest = rest[0] if len(rest) > 0 else ""
default_repo = instance.bot.db.get_default_repo(evt.room_id)
if not default_repo or re.fullmatch(r"\w+/[\w/]+", repo):
return val[len(repo):], repo
return val, default_repo
if not default_repo or re.fullmatch(r"\w+/[\w\-./]+", repo):
return rest[0], repo
# TODO use default_repo.server somehow after multi-server stuff is fixed
return val, default_repo.repo
def optional_int(val: str) -> Optional[int]:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment