Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobranco777 committed Sep 8, 2023
1 parent 7d7ba6b commit d85977f
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions bugme.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def get_item(string: str) -> Union[Item, None]:
try:
return Item(host=code_to_host[code], repo=repo, id=int(issue))
except KeyError:
logging.error("Unsupported %s", string)
logging.warning("Unsupported %s", string)
return None


Expand Down Expand Up @@ -167,7 +167,10 @@ def get_items(self, items: List[Item]) -> List[Union[Item, None]]:
Get Bugzilla items
"""
try:
return [self._to_item(info) for info in self.client.getbugs([_.id for _ in items])]
return [
self._to_item(info)
for info in self.client.getbugs([_.id for _ in items])
]
except BugzillaError as exc:
logging.error("Bugzilla: %s: get_items(): %s", self.url, exc)
return []
Expand All @@ -188,8 +191,8 @@ class MyGithub(Service):
Github
"""

def __init__(self, creds: dict):
super().__init__("https://github.com")
def __init__(self, url: str, creds: dict):
super().__init__(url)
auth = Auth.Token(**creds)
self.client = Github(auth=auth)

Expand Down Expand Up @@ -237,9 +240,7 @@ def get_item(self, item: Item) -> Union[Item, None]:
Get Gitlab issue
"""
try:
info = self.client.projects.get(item.repo, lazy=True).issues.get(
item.id
)
info = self.client.projects.get(item.repo, lazy=True).issues.get(item.id)
except (GitlabError, RequestException) as exc:
logging.error("Gitlab: %s: get_issue(%s): %s", self.url, item.id, exc)
return None
Expand Down Expand Up @@ -306,24 +307,25 @@ def main() -> None:
else:
items[item["host"]].append(item)

host_to_cls = {
"bugzilla.suse.com": MyBugzilla,
"progress.opensuse.org": MyRedmine,
"gitlab.suse.de": MyGitlab,
"gitlab.com": MyGitlab,
"github.com": MyGithub,
}

clients: Dict[str, Any] = {}
for host in items:
if host == "bugzilla.suse.com":
clients[host] = MyBugzilla(f"https://{host}", creds[host])
elif host == "progress.opensuse.org":
clients[host] = MyRedmine(f"https://{host}", creds[host])
elif host.startswith("gitlab"):
clients[host] = MyGitlab(f"https://{host}", creds[host])
elif host == "github.com":
clients[host] = MyGithub(creds[host])
else:
logging.warning("Skipping %s", host)
clients[host] = host_to_cls[host](f"https://{host}", creds[host])

if len(clients) == 0:
sys.exit(0)

with ThreadPoolExecutor(max_workers=len(clients)) as executor:
for item in executor.map(lambda host: clients[host].get_items(items[host]), clients.keys()):
for item in executor.map(
lambda host: clients[host].get_items(items[host]), clients.keys()
):
print(item)


Expand Down

0 comments on commit d85977f

Please sign in to comment.