Skip to content

Commit c118a1b

Browse files
committed
implemet refactoring suggestions
1 parent abfef99 commit c118a1b

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

bot/exts/utilities/githubinfo.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
}
2424

2525
REPOSITORY_ENDPOINT = "https://api.github.com/orgs/{org}/repos?per_page=100&type=public"
26-
FETCH_MOST_STARRED_ENDPOINT = "https://api.github.com/search/repositories?q={name}&sort=stars&order=desc&per_page=1"
26+
MOST_STARRED_ENDPOINT = "https://api.github.com/search/repositories?q={name}&sort=stars&order=desc&per_page=1"
2727
ISSUE_ENDPOINT = "https://api.github.com/repos/{user}/{repository}/issues/{number}"
2828
PR_ENDPOINT = "https://api.github.com/repos/{user}/{repository}/pulls/{number}"
2929

@@ -79,7 +79,7 @@ class GithubInfo(commands.Cog):
7979

8080
def __init__(self, bot: Bot):
8181
self.bot = bot
82-
self.repos = []
82+
self.pydis_repos: dict = {}
8383

8484
async def cog_load(self) -> None:
8585
"""Function to be run at cog load."""
@@ -313,9 +313,11 @@ async def github_user_info(self, ctx: commands.Context, username: str) -> None:
313313

314314
@tasks.loop(hours=24)
315315
async def refresh_repos(self) -> None:
316-
"""Refresh self.repos with latest PyDis repos."""
317-
self.repos, _ = await self.fetch_data(REPOSITORY_ENDPOINT.format(org="python-discord"))
318-
log.info(f"Loaded {len(self.repos)} repos from Python Discord org into memory.")
316+
"""Refresh self.pydis_repos with latest PyDis repos."""
317+
fetched_repos, _ = await self.fetch_data(REPOSITORY_ENDPOINT.format(org="python-discord"))
318+
for each in fetched_repos:
319+
self.pydis_repos.update({each['name']: each})
320+
log.info(f"Loaded {len(self.pydis_repos)} repos from Python Discord org into memory.")
319321

320322
def build_embed(self, repo_data: dict) -> discord.Embed:
321323
"""Create a clean discord embed to show repo data."""
@@ -375,11 +377,9 @@ async def github_repo_info(self, ctx: commands.Context, *repo: str) -> None:
375377
if repo_query in self.stored_repos:
376378
repo_query = self.stored_repos[repo_query]
377379
else:
378-
for each in self.repos:
379-
if repo_query == each["name"]:
380-
repo_query = each
381-
is_pydis = True
382-
break
380+
if repo_query in self.pydis_repos:
381+
repo_query = self.pydis_repos[repo_query]
382+
is_pydis = True
383383
else:
384384
fetch_most_starred = True
385385

@@ -390,7 +390,7 @@ async def github_repo_info(self, ctx: commands.Context, *repo: str) -> None:
390390

391391
# Case 2: Not stored or PyDis, fetch most-starred matching repo
392392
elif fetch_most_starred:
393-
repos, _ = await self.fetch_data(FETCH_MOST_STARRED_ENDPOINT.format(name=quote(repo_query)))
393+
repos, _ = await self.fetch_data(MOST_STARRED_ENDPOINT.format(name=quote(repo_query)))
394394

395395
if not repos["items"]:
396396
embed = discord.Embed(

0 commit comments

Comments
 (0)