Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobranco777 committed Sep 8, 2023
1 parent ef09ff5 commit 2d3d48a
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions bugme.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class RepoIssue: # pylint: disable=too-few-public-methods
"""
Simple class to hold GitHub issue
"""

def __init__(self, repo: str, issue: str):
self.repo = repo
self.number = int(issue)
Expand All @@ -46,6 +47,7 @@ class Item: # pylint: disable=too-few-public-methods
"""
Item class
"""

def __init__(self, **kwargs):
for attr, value in kwargs.items():
setattr(self, attr, value)
Expand All @@ -55,16 +57,23 @@ class Service:
"""
Service class to abstract methods
"""

def __init__(self, url):
url = url.rstrip('/')
url = url.rstrip("/")
self.url = url if urlparse(url).scheme else f"https://{url}"

def __enter__(self):
return self

def __exit__(self, exc_type, exc_value, traceback):
if exc_type is not None:
logging.error("%s: %s: %s: %s", self.__class__.__name__, exc_type, exc_value, traceback)
logging.error(
"%s: %s: %s: %s",
self.__class__.__name__,
exc_type,
exc_value,
traceback,
)

def get_item(self, item: int) -> Item:
"""
Expand All @@ -84,6 +93,7 @@ class MyBugzilla(Service):
"""
Bugzilla
"""

def __init__(self, url: str, creds: dict):
super().__init__(url)
sslverify = os.environ.get("REQUESTS_CA_BUNDLE", True)
Expand Down Expand Up @@ -131,6 +141,7 @@ class MyGithub(Service):
"""
Github
"""

def __init__(self, creds: dict):
super().__init__("https://github.com")
auth = Auth.Token(**creds)
Expand Down Expand Up @@ -162,10 +173,13 @@ class MyGitlab(Service):
"""
Gitlab
"""

def __init__(self, url: str, creds: dict):
super().__init__(url)
ssl_verify = os.getenv("REQUESTS_CA_BUNDLE") if self.url else True
self.client = Gitlab(url=self.url, ssl_verify=ssl_verify, retry_transient_errors=False, **creds)
self.client = Gitlab(
url=self.url, ssl_verify=ssl_verify, retry_transient_errors=False, **creds
)

def __exit__(self, exc_type, exc_value, traceback):
try:
Expand All @@ -179,7 +193,9 @@ def get_item(self, issue: RepoIssue) -> Item:
Get Gitlab issue
"""
try:
info = self.client.projects.get(issue.repo, lazy=True).issues.get(issue.number)
info = self.client.projects.get(issue.repo, lazy=True).issues.get(
issue.number
)
except GitlabError as exc:
logging.error("Gitlab: %s: get_issue(%d): %s", self.url, issue, exc)
return None
Expand All @@ -200,6 +216,7 @@ class MyRedmine(Service):
"""
Redmine
"""

def __init__(self, url: str, creds: dict):
super().__init__(url)
self.client = Redmine(url=self.url, raise_attr_exception=False, **creds)
Expand All @@ -210,7 +227,6 @@ def get_item(self, item: int) -> Item:
"""
try:
info = self.client.issue.get(item)
print(f"poo#{info.id}\t{info.status}\t{dateit(info.updated_on)}\t{info.subject}")
except BaseRedmineError as exc:
logging.error("Redmine: %s: get_issue(%d): %s", self.url, item, exc)
return None
Expand Down Expand Up @@ -256,6 +272,7 @@ def main():
sys.exit(f"ERROR: {CREDENTIALS_FILE} has insecure permissions")
creds = json.load(file)


# do_bugzilla("https://bugzilla.suse.com", bsc_list, creds["bugzilla.suse.com"])
# do_github(gh_list, creds["github.com"])
# do_gitlab(None, gl_list, creds["gitlab.com"])
Expand Down

0 comments on commit 2d3d48a

Please sign in to comment.