Skip to content

Commit

Permalink
Add support for Gitlab
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobranco777 committed Sep 7, 2023
1 parent cad5a05 commit 91c0358
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 24 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

Show bug and issue status

Supported:
- bsc#: SUSE's Bugzilla
- gh#: Github
- gl#: Gitlab
- gsd#: SUSE's Gitlab
- poo#: openSUSE's Redmine

## Example usage

Copy [creds-example.json](creds-example.json) to `~/creds.json` and run.
Expand Down
79 changes: 55 additions & 24 deletions bugme.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from pytz import utc

from github import Github, Auth, GithubException
from gitlab import Gitlab
from gitlab.exceptions import GitlabError
from bugzilla import Bugzilla
from bugzilla.exceptions import BugzillaError
from redminelib import Redmine
Expand All @@ -28,7 +30,7 @@ def dateit(date, time_format: str = "%a %b %d %H:%M:%S %Z %Y") -> str:
return date.astimezone().strftime(time_format)


class GithubIssue: # pylint: disable=too-few-public-methods
class RepoIssue: # pylint: disable=too-few-public-methods
"""
Simple class to hold GitHub issue
"""
Expand All @@ -45,14 +47,20 @@ def main():
bsc_list = []
poo_list = []
gh_list = []
gl_list = []
gsd_list = []

for arg in sys.argv[1:]:
if arg.startswith(("bnc#", "boo#", "bsc#")):
bsc_list.append(int(arg.split("#", 1)[1]))
elif arg.startswith("poo#"):
poo_list.append(int(arg.split("#", 1)[1]))
elif arg.startswith("gh#"):
gh_list.append(GithubIssue(*arg.split("#", 2)[1:]))
gh_list.append(RepoIssue(*arg.split("#", 2)[1:]))
elif arg.startswith("gl#"):
gl_list.append(RepoIssue(*arg.split("#", 2)[1:]))
elif arg.startswith("gsd#"):
gsd_list.append(RepoIssue(*arg.split("#", 2)[1:]))
else:
print(f"Unsupported {arg}", file=sys.stderr)

Expand All @@ -62,32 +70,55 @@ def main():
creds = json.load(file)

# Bugzilla
try:
mybsc = Bugzilla("https://bugzilla.suse.com", force_rest=True, **creds["bugzilla.suse.com"])
for bsc in mybsc.getbugs(bsc_list):
print(f"bsc#{bsc.id}\t{bsc.status}\t\t{dateit(bsc.last_change_time)}\t{bsc.summary}")
mybsc.disconnect()
except BugzillaError as exc:
print(f"Bugzilla: {exc}")
if len(bsc_list) > 0:
try:
mybsc = Bugzilla("https://bugzilla.suse.com", force_rest=True, **creds["bugzilla.suse.com"])
for bsc in mybsc.getbugs(bsc_list):
print(f"bsc#{bsc.id}\t{bsc.status}\t\t{dateit(bsc.last_change_time)}\t{bsc.summary}")
mybsc.disconnect()
except BugzillaError as exc:
print(f"Bugzilla: {exc}")

# Github
auth = Auth.Token(**creds["github.com"])
mygh = Github(auth=auth)
for issue in gh_list:
try:
info = mygh.get_repo(issue.repo).get_issue(issue.number)
print(f"gh#{info.number}\t{info.state}\t\t{dateit(info.last_modified)}\t{info.title}")
except GithubException as exc:
print(f"gh#{issue.repo}#{issue.number}: {exc}", file=sys.stderr)
if len(gh_list) > 0:
auth = Auth.Token(**creds["github.com"])
mygh = Github(auth=auth)
for issue in gh_list:
try:
info = mygh.get_repo(issue.repo).get_issue(issue.number)
print(f"gh#{info.number}\t{info.state}\t\t{dateit(info.last_modified)}\t{info.title}")
except GithubException as exc:
print(f"gh#{issue.repo}#{issue.number}: {exc}", file=sys.stderr)

# Gitlab
if len(gl_list) > 0:
mygl = Gitlab(**creds["gitlab.com"])
for issue in gl_list:
try:
info = mygl.projects.get(issue.repo).issues.get(issue.number)
print(f"gl#{info.iid}\t{info.state}\t\t{dateit(info.updated_at)}\t{info.title}")
except GitlabError as exc:
print(f"gl#{issue.repo}#{issue.number}: {exc}", file=sys.stderr)

# SUSE's Gitlab
if len(gsd_list) > 0:
mygl = Gitlab(url="https://gitlab.suse.de", **creds["gitlab.suse.de"])
for issue in gsd_list:
try:
info = mygl.projects.get(issue.repo).issues.get(issue.number)
print(f"gl#{info.iid}\t{info.state}\t\t{dateit(info.updated_at)}\t{info.title}")
except GitlabError as exc:
print(f"gl#{issue.repo}#{issue.number}: {exc}", file=sys.stderr)

# Redmine
redmine = Redmine(url="https://progress.opensuse.org", **creds["progress.opensuse.org"])
for poo in poo_list:
try:
info = redmine.issue.get(poo)
print(f"poo#{info.id}\t{info.status}\t{dateit(info.updated_on)}\t{info.subject}")
except BaseRedmineError as exc:
print(f"poo#{poo}: {exc}", file=sys.stderr)
if len(poo_list) > 0:
redmine = Redmine(url="https://progress.opensuse.org", **creds["progress.opensuse.org"])
for poo in poo_list:
try:
info = redmine.issue.get(poo)
print(f"poo#{info.id}\t{info.status}\t{dateit(info.updated_on)}\t{info.subject}")
except BaseRedmineError as exc:
print(f"poo#{poo}: {exc}", file=sys.stderr)


if __name__ == "__main__":
Expand Down
6 changes: 6 additions & 0 deletions creds-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
"username": "rbranco",
"key": "REDMINE_API_KEY"
},
"gitlab.suse.de": {
"private_token": "GITLAB_API_KEY"
},
"gitlab.com": {
"private_token": "GITLAB_API_KEY"
},
"github.com": {
"token": "GITHUB_TOKEN"
}
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ python-bugzilla
python-redmine
python-dateutil
pytz
python-gitlab
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ PyJWT==2.8.0
PyNaCl==1.5.0
python-bugzilla==3.2.0
python-dateutil==2.8.2
python-gitlab==3.15.0
python-redmine==2.4.0
pytz==2023.3.post1
requests==2.31.0
requests-toolbelt==1.0.0
six==1.16.0
urllib3==2.0.4
wrapt==1.15.0

0 comments on commit 91c0358

Please sign in to comment.