Skip to content

Commit

Permalink
Show resources with status ERROR: NOT FOUND
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobranco777 committed Sep 11, 2023
1 parent b902e9f commit 47ba36c
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion bugme.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from gitlab import Gitlab
from gitlab.exceptions import GitlabError
from redminelib import Redmine # type: ignore
from redminelib.exceptions import BaseRedmineError # type: ignore
from redminelib.exceptions import BaseRedmineError, ResourceNotFoundError # type: ignore
from requests.exceptions import RequestException
from jinja2 import Template

Expand Down Expand Up @@ -128,6 +128,19 @@ def __init__(self, url: str):
def __repr__(self) -> str:
return f"{self.__class__.__name__}(url='{self.url}')"

def _not_found(self, item_id: int, url: str, tag: str) -> Item:
now = datetime.now()
return Item(
id=item_id,
status="ERROR",
title="NOT FOUND",
created=now,
updated=now,
url=url,
extra={},
tag=tag,
)

def get_item(self, item_id: int = -1, **kwargs) -> Item | None:
"""
This method must be overriden if get_items() isn't overriden
Expand Down Expand Up @@ -220,6 +233,12 @@ def get_item(self, item_id: int = -1, **kwargs) -> Item | None:
try:
info = self.client.get_repo(repo, lazy=True).get_issue(item_id)
except (GithubException, RequestException) as exc:
if hasattr(exc, "status") and exc.status == 404:
return self._not_found(
item_id,
"{self.url}/{repo}/issues/{item_id}",
"{self.tag}#{repo}#{item_id}",
)
logging.error("Github: get_issue(%s, %s): %s", repo, item_id, exc)
return None
return self._to_item(info, repo)
Expand Down Expand Up @@ -263,6 +282,12 @@ def get_item(self, item_id: int = -1, **kwargs) -> Item | None:
try:
info = self.client.projects.get(repo, lazy=True).issues.get(item_id)
except (GitlabError, RequestException) as exc:
if hasattr(exc, "response_code") and exc.response_code == 404:
return self._not_found(
item_id,
f"{self.url}/{repo}/-/issues/{item_id}",
f"{self.tag}#{repo}#{item_id}",
)
logging.error(
"Gitlab: %s: get_issue(%s, %s): %s", self.url, repo, item_id, exc
)
Expand Down Expand Up @@ -297,6 +322,10 @@ def get_item(self, item_id: int = -1, **kwargs) -> Item | None:
"""
try:
info = self.client.issue.get(item_id)
except ResourceNotFoundError:
return self._not_found(
item_id, f"{self.url}/issues/{item_id}", f"{self.tag}#{item_id}"
)
except (BaseRedmineError, RequestException) as exc:
logging.error("Redmine: %s: get_issue(%d): %s", self.url, item_id, exc)
return None
Expand Down

0 comments on commit 47ba36c

Please sign in to comment.