[Downloader] Add Repo.clean_url and use it in [p]findcog (#3129)

* enhance(downloader): add `Repo.clean_url` and use it in `[p]findcog`

* chore(changelog): add towncrier entries
This commit is contained in:
jack1142 2019-11-17 16:25:15 +01:00 committed by Michael H
parent 548a50b984
commit 8a90996b36
4 changed files with 11 additions and 1 deletions

View File

@ -0,0 +1 @@
Use sanitized url (without HTTP Basic Auth fragments) in `[p]findcog` command.

View File

@ -0,0 +1 @@
Add `clean_url` property to :class:`redbot.cogs.downloader.repo_manager.Repo` which contains sanitized repo URL (without HTTP Basic Auth).

View File

@ -1150,7 +1150,7 @@ class Downloader(commands.Cog):
repo_url = ( repo_url = (
_("Missing from installed repos") _("Missing from installed repos")
if cog_installable.repo is None if cog_installable.repo is None
else cog_installable.repo.url else cog_installable.repo.clean_url
) )
cog_name = cog_installable.name cog_name = cog_installable.name
else: else:

View File

@ -7,6 +7,7 @@ import pkgutil
import shlex import shlex
import shutil import shutil
import re import re
import yarl
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from pathlib import Path from pathlib import Path
from subprocess import run as sp_run, PIPE, CompletedProcess from subprocess import run as sp_run, PIPE, CompletedProcess
@ -147,6 +148,13 @@ class Repo(RepoJSONMixin):
self._loop = loop if loop is not None else asyncio.get_event_loop() self._loop = loop if loop is not None else asyncio.get_event_loop()
@property
def clean_url(self):
"""Sanitized repo URL (with removed HTTP Basic Auth)"""
url = yarl.URL(self.url)
clean_url = url.with_user(None)
return clean_url
@classmethod @classmethod
async def convert(cls, ctx: commands.Context, argument: str) -> Repo: async def convert(cls, ctx: commands.Context, argument: str) -> Repo:
downloader_cog = ctx.bot.get_cog("Downloader") downloader_cog = ctx.bot.get_cog("Downloader")