Skip to content

Commit

Permalink
Add support for Redmine
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobranco777 committed Sep 7, 2023
1 parent 431f1e0 commit 0744b63
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 32 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ jobs:
run: |
make flake8
continue-on-error: true
- name: mypy
run: |
make mypy
continue-on-error: true
- name: pylint
run: |
make pylint
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FILES=*.py

.PHONY: all
all: flake8 pylint mypy
all: flake8 pylint

.PHONY: flake8
flake8:
Expand All @@ -10,7 +10,3 @@ flake8:
.PHONY: pylint
pylint:
@pylint $(FILES)

.PHONY: mypy
mypy:
@mypy $(FILES)
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@

# bugme

Show bug and issue statuses
Show bug and issue status

## Example usage

Copy [creds-example.json](creds-example.json) to `~/creds.json` and run.

```
$ bugme.py bsc#1213811 gh#containers/podman#19529
bsc#1213811 NEW Tue Sep 05 16:21:37 CEST 2023 podman network unreachable after starting docker
gh#19529 closed Tue Aug 08 10:56:56 CEST 2023 Unexpected error with --volumes-from
$ ./bugme.py bsc#1213811 gh#containers/podman#19529 poo#133910
bsc#1213811 NEW Tue Sep 05 16:21:37 CEST 2023 podman network unreachable after starting docker
gh#19529 closed Tue Aug 08 10:56:56 CEST 2023 Unexpected error with --volumes-from
poo#133910 Resolved Thu Aug 17 08:50:53 CEST 2023 We need a suite of tests to check volume operations in container runtimes
```

## Requirements

- Tested on Python 3.8+
- [requirements](requirements-dev.txt)

## TODO

- Redmine
39 changes: 27 additions & 12 deletions bugme.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,26 @@
import os
import json
import sys
from typing import List

from dateutil import parser
from pytz import utc

from github import Github, Auth, GithubException
from bugzilla import Bugzilla # type: ignore
from bugzilla.exceptions import BugzillaError # type: ignore
from bugzilla import Bugzilla
from bugzilla.exceptions import BugzillaError
from redminelib import Redmine
from redminelib.exceptions import BaseRedmineError

CREDENTIALS_FILE = os.path.expanduser("./creds.json")
CREDENTIALS_FILE = os.path.expanduser("~/creds.json")


def dateit(date: str = "", time_format: str = "%a %b %d %H:%M:%S %Z %Y") -> str:
def dateit(date, time_format: str = "%a %b %d %H:%M:%S %Z %Y") -> str:
"""
Return date in desired format
"""
return utc.normalize(parser.parse(date)).astimezone().strftime(time_format)
if isinstance(date, str):
date = utc.normalize(parser.parse(date))
return date.astimezone().strftime(time_format)


class GithubIssue: # pylint: disable=too-few-public-methods
Expand All @@ -35,16 +38,19 @@ def __init__(self, repo: str, issue: str):
self.number = int(issue)


def main() -> None:
def main():
"""
Main function
"""
bsc_list: List[int] = []
gh_list: List[GithubIssue] = []
bsc_list = []
poo_list = []
gh_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:]))
else:
Expand All @@ -59,21 +65,30 @@ def main() -> None:
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{dateit(bsc.last_change_time)}\t{bsc.summary}")
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"bsc#{bsc.id}: {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{dateit(info.last_modified)}\t{info.title}")
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)

# 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 __name__ == "__main__":
try:
Expand Down
13 changes: 13 additions & 0 deletions creds-example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"bugzilla.suse.com": {
"user": "[email protected]",
"api_key": "BUGZILLA_API_KEY"
},
"progress.opensuse.org": {
"username": "rbranco",
"key": "REDMINE_API_KEY"
},
"github.com": {
"token": "GITHUB_TOKEN"
}
}
3 changes: 0 additions & 3 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,3 @@

flake8
pylint
mypy
types-python-dateutil
types-pytz

0 comments on commit 0744b63

Please sign in to comment.