Skip to content

Commit 61df875

Browse files
fix: properly parse github repository even with additional words
1 parent 68911e5 commit 61df875

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

monty/exts/info/github/cog.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -492,15 +492,21 @@ async def github_repo(self, ctx: commands.Context, user_and_repo: str, repo: str
492492
# validate the repo
493493
await ctx.trigger_typing()
494494
obj: githubkit.rest.FullRepository | githubkit.rest.RepoSearchResultItem | None = None
495-
if user_and_repo.count("/") == 1 and not repo:
495+
if user_and_repo.count("/") == 1:
496496
user, repo = user_and_repo.split("/", 1)
497-
elif user_and_repo.count("/") > 1:
498-
msg = "Invalid repository format. Please use `user/repo`."
497+
elif (user_and_repo + repo).count("/") > 1:
498+
msg = (
499+
"Invalid repository format. Please use `user/repo`. \n"
500+
"If you're feeling lucky, you can also provide a bare repository"
501+
" name such as 'rust' to get the most popular repository matching that name."
502+
)
499503
raise commands.BadArgument(msg)
504+
elif user_and_repo and repo:
505+
user = user_and_repo
506+
repo = repo
500507
else:
501-
repo = user_and_repo
502-
# Resolve the user from the repo name when possible
503-
repo_shorthand = await self.resolve_repo(ghretos.Repo(owner="", name=repo))
508+
# Treat the first argument as the repo name only
509+
repo_shorthand = await self.resolve_repo(ghretos.Repo(owner="", name=user_and_repo))
504510
user = repo_shorthand.owner
505511
repo = repo_shorthand.name
506512

0 commit comments

Comments
 (0)