Skip to content

Commit

Permalink
fix get_repo related issues
Browse files Browse the repository at this point in the history
  • Loading branch information
squi-ddy committed Jan 27, 2024
1 parent 1af2a91 commit a844ea2
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions bot/src/cogs/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging

from config import config
from github import Github
from github import Github, UnknownObjectException
from nextcord import (
CategoryChannel,
File,
Expand Down Expand Up @@ -157,9 +157,12 @@ async def delete(
await project_voice_channel.delete()

if project.github_repo and project.github_webhook_id:
repo = self.org.get_repo(project.github_repo) # type: ignore
hook = repo.get_hook(project.github_webhook_id) # type: ignore
hook.delete()
try:
repo = self.org.get_repo(project.github_repo) # type: ignore
hook = repo.get_hook(project.github_webhook_id) # type: ignore
hook.delete()
except UnknownObjectException:
logging.warn(f"GitHub repo {project.github_repo} not found")

await interaction.send("Project deleted successfully!")

Expand Down Expand Up @@ -243,7 +246,7 @@ async def link(
force: bool = SlashOption(description="Whether to force link even if project already linked", default=False),
) -> None:
await interaction.response.defer()

project_name = project_name.lower().replace(" ", "-")

project = database.get_project(project_name)
Expand All @@ -253,8 +256,9 @@ async def link(
if not force and project.github_repo:
return await send_error(interaction, "Project already linked to GitHub repo")

repo = self.org.get_repo(github_repo)
if not repo:
try:
repo = self.org.get_repo(github_repo)
except UnknownObjectException:
return await send_error(interaction, "GitHub repo does not exist")

project_text_channel = self.cache.guild.get_channel(project.discord_text_channel_id) # type: ignore
Expand All @@ -266,9 +270,13 @@ async def link(

if force and project.github_repo:
# delete old webhooks
repo = self.org.get_repo(project.github_repo) # type: ignore
hook = repo.get_hook(project.github_webhook_id) # type: ignore
hook.delete()
try:
repo = self.org.get_repo(project.github_repo) # type: ignore
hook = repo.get_hook(project.github_webhook_id) # type: ignore
hook.delete()
except UnknownObjectException:
logging.warn(f"Old GitHub repo {project.github_repo} not found")

for webhook in await project_text_channel.webhooks():
if webhook.id == project.webhook_id:
await webhook.delete()
Expand Down Expand Up @@ -317,8 +325,9 @@ async def share(
if not project.github_repo:
return await send_error(interaction, "Project not linked to GitHub repo")

repo = self.org.get_repo(project.github_repo) # type: ignore
if not repo:
try:
repo = self.org.get_repo(project.github_repo) # type: ignore
except UnknownObjectException:
return await send_error(interaction, "GitHub repo link broken; please re-link project")

role = self.cache.guild.get_role(project.discord_role_id) # type: ignore
Expand Down Expand Up @@ -369,13 +378,14 @@ async def export(self, interaction: Interaction) -> None:
# check if member in github
in_github = False
if project.github_repo:
if not (repo := self.org.get_repo(project.github_repo)): # type: ignore
logging.warn(f"GitHub repo {repo} not found, cannot get members in GitHub")
else:
try:
repo = self.org.get_repo(project.github_repo) # type: ignore
contributor_names = [
contributor.login for contributor in repo.get_contributors()
]
in_github = (await self.github_auth.get_github_name(member.id)) in contributor_names
except UnknownObjectException: # type: ignore
logging.warn(f"GitHub repo {project.github_repo} not found, cannot get members in GitHub")

members_writer.writerow([project.name, member.display_name, in_github])
else:
Expand Down

0 comments on commit a844ea2

Please sign in to comment.