From b61f0113584937c7033f748908b233b1998b7333 Mon Sep 17 00:00:00 2001 From: squiddy Date: Sun, 28 Jan 2024 00:40:50 +0800 Subject: [PATCH] fix export --- bot/src/cogs/projects.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/bot/src/cogs/projects.py b/bot/src/cogs/projects.py index 6595b91..ba2abf6 100644 --- a/bot/src/cogs/projects.py +++ b/bot/src/cogs/projects.py @@ -1,6 +1,7 @@ import csv from io import StringIO from typing import Optional +import logging from config import config from github import Github @@ -24,6 +25,7 @@ from .github_auth import GithubAuth from .ui_helper import UIHelper +logger = logging.getLogger(__name__) class Projects(Cog): __slots__ = "bot", "cache", "ui_helper", "ci", "org", "github_auth" @@ -360,19 +362,22 @@ async def export(self, interaction: Interaction) -> None: for project in projects: project_role = guild.get_role(project.discord_role_id) # type: ignore - if not project_role: - raise ValueError(f"Project role {project.discord_role_id} not found") - - for member in project_role.members: - # check if member in github - in_github = False - if project.github_repo: - contributor_names = [ - contributor.login for contributor in self.ci.get_repo(project.github_repo).get_contributors() # type: ignore - ] - in_github = (await self.github_auth.get_github_name(member.id)) in contributor_names - - members_writer.writerow([project.name, member.display_name, in_github]) + if project_role: + for member in project_role.members: + # 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: + contributor_names = [ + contributor.login for contributor in repo.get_contributors() + ] + in_github = (await self.github_auth.get_github_name(member.id)) in contributor_names + + members_writer.writerow([project.name, member.display_name, in_github]) + else: + logging.warn(f"Project role {project.discord_role_id} not found, cannot list members") projects_writer.writerow([project.name, project.github_repo])