Skip to content

Commit

Permalink
Add markdown support to koji plugin
Browse files Browse the repository at this point in the history
Adding markdown format output to koji plugin.
In order to provide a link to the build, `weburl` option is required,
pointing to the koji web interface.
  • Loading branch information
sandrobonazzola committed Feb 20, 2024
1 parent 0584a30 commit 300de6f
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions did/plugins/koji.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[koji]
type = koji
url = https://koji.example.org/kojihub
weburl = https://koji.example.org/koji
login = testuser
name = Example koji server
Expand Down Expand Up @@ -38,8 +39,25 @@ def fetch(self):
userID=self.user['id'],
completeAfter=str(self.options.since),
completeBefore=str(self.options.until))
if self.options.format == "markdown":
try:
weburl = f"{self.parent.config['weburl']}/buildinfo?buildID="
self.stats = [
f"[{build['nvr']}]({weburl}{build['build_id']})"
for build in builds
]
except KeyError as ke:
log.warning(
"Missing `%s` option, markdown unavailable for '%s' section",
ke.args[0],
self.name
)
else:
return
# else
self.stats = [build['nvr'] for build in builds]


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Stats Group
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -53,23 +71,23 @@ class KojiStats(StatsGroup):

def __init__(self, option, name=None, parent=None, user=None):
StatsGroup.__init__(self, option, name, parent, user)
config = dict(did.base.Config().section(option))
self.config = dict(did.base.Config().section(option))
try:
url = config['url']
url = self.config['url']
except KeyError:
raise did.base.ReportError(
"No koji url set in the [{0}] section".format(option))
server = koji.ClientSession(url, opts=config)
server = koji.ClientSession(url, opts=self.config)
try:
user = server.getUser(config['login'], strict=True)
user = server.getUser(self.config['login'], strict=True)
except KeyError:
raise did.base.ReportError(
"No koji user set in the [{0}] section".format(option))
except koji.GenericError:
raise did.base.ReportError(
"Non-existent koji user set in the [{0}] section".format(option))

name = config.get('name', url)
name = self.config.get('name', url)

self.stats = [
KojiBuilds(option=option + "-builds",
Expand Down

0 comments on commit 300de6f

Please sign in to comment.