Skip to content

Commit

Permalink
Minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobranco777 committed Sep 12, 2023
1 parent 73a692b commit f813f5b
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions bugme.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ def _not_found(self, item_id: int, url: str, tag: str) -> Item:
created=now,
updated=now,
url=url,
extra={},
tag=tag,
extra={},
)

def get_item(self, item_id: int = -1, **kwargs) -> Item | None:
Expand Down Expand Up @@ -219,8 +219,8 @@ def _to_item(self, info: Any) -> Item:
created=info.creation_time,
updated=info.last_change_time,
url=f"{self.url}/show_bug.cgi?id={info.id}",
extra=info.__dict__,
tag=f"{self.tag}#{info.id}",
extra=info.__dict__,
)


Expand All @@ -245,7 +245,7 @@ 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:
if getattr(exc, "status", None) == 404:
return self._not_found(
item_id,
"{self.url}/{repo}/issues/{item_id}",
Expand All @@ -263,8 +263,8 @@ def _to_item(self, info: Any, repo: str) -> Item:
created=info.created_at,
updated=info.updated_at,
url=f"{self.url}/{repo}/issues/{info.number}",
extra=info.__dict__["_rawData"],
tag=f"{self.tag}#{repo}#{info.number}",
extra=info.__dict__["_rawData"],
)


Expand Down Expand Up @@ -294,7 +294,7 @@ 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:
if getattr(exc, "response_code", None) == 404:
return self._not_found(
item_id,
f"{self.url}/{repo}/-/issues/{item_id}",
Expand All @@ -314,8 +314,8 @@ def _to_item(self, info: Any, repo: str) -> Item:
created=info.created_at,
updated=info.updated_at,
url=f"{self.url}/{repo}/-/issues/{info.iid}",
extra=info.asdict(),
tag=f"{self.tag}#{repo}#{info.iid}",
extra=info.asdict(),
)


Expand Down Expand Up @@ -351,8 +351,8 @@ def _to_item(self, info: Any) -> Item:
created=info.created_on,
updated=info.updated_on,
url=f"{self.url}/issues/{info.id}",
extra=info.raw(),
tag=f"{self.tag}#{info.id}",
extra=info.raw(),
)


Expand Down Expand Up @@ -448,17 +448,16 @@ def main() -> None: # pylint: disable=too-many-branches
item.created = dateit(item.created, args.time)
item.updated = dateit(item.updated, args.time)
item.status = item.status.upper()
if args.output == "text":
if args.format:
print(Template(args.format).render(item.__dict__))
else:
print(
" ".join(
[f"{item[key]:{align}}" for key, align in keys.items()]
)
)
elif args.output == "json":
if args.output == "json":
all_items.append(item.__dict__)
elif args.format:
print(Template(args.format).render(item.__dict__))
else:
print(
" ".join(
[f"{item[key]:{align}}" for key, align in keys.items()]
)
)

if args.output == "json":
print(json.dumps(all_items, default=str, sort_keys=True))
Expand Down

0 comments on commit f813f5b

Please sign in to comment.